mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
Bugfix/model list unreachable (#2522)
* fallback to fetch local models json file * enable user to specify local path to load models.json * Update pnpm-lock.yaml
This commit is contained in:
+1
-1
@@ -131,7 +131,7 @@ Flowise support different environment variables to configure your instance. You
|
|||||||
| DEBUG | Print logs from components | Boolean | |
|
| DEBUG | Print logs from components | Boolean | |
|
||||||
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` |
|
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` |
|
||||||
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
|
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
|
||||||
| LOG_JSON_SPACES | Spaces to beautify JSON logs | | 2
|
| LOG_JSON_SPACES | Spaces to beautify JSON logs | | 2 |
|
||||||
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
|
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
|
||||||
| TOOL_FUNCTION_BUILTIN_DEP | NodeJS built-in modules to be used for Tool Function | String | |
|
| TOOL_FUNCTION_BUILTIN_DEP | NodeJS built-in modules to be used for Tool Function | String | |
|
||||||
| TOOL_FUNCTION_EXTERNAL_DEP | External modules to be used for Tool Function | String | |
|
| TOOL_FUNCTION_EXTERNAL_DEP | External modules to be used for Tool Function | String | |
|
||||||
|
|||||||
@@ -21,27 +21,58 @@ const getModelsJSONPath = (): string => {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isValidUrl = (urlString: string) => {
|
||||||
|
let url
|
||||||
|
try {
|
||||||
|
url = new URL(urlString)
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return url.protocol === 'http:' || url.protocol === 'https:'
|
||||||
|
}
|
||||||
|
|
||||||
const getModelConfig = async (category: MODEL_TYPE, name: string) => {
|
const getModelConfig = async (category: MODEL_TYPE, name: string) => {
|
||||||
const modelFile = process.env.MODEL_LIST_CONFIG_JSON || MASTER_MODEL_LIST
|
const modelFile = process.env.MODEL_LIST_CONFIG_JSON || MASTER_MODEL_LIST
|
||||||
|
|
||||||
if (!modelFile) {
|
if (!modelFile) {
|
||||||
throw new Error('MODEL_LIST_CONFIG_JSON not set')
|
throw new Error('MODEL_LIST_CONFIG_JSON not set')
|
||||||
}
|
}
|
||||||
try {
|
if (isValidUrl(modelFile)) {
|
||||||
const resp = await axios.get(modelFile)
|
try {
|
||||||
if (resp.status === 200 && resp.data) {
|
const resp = await axios.get(modelFile)
|
||||||
const models = resp.data
|
if (resp.status === 200 && resp.data) {
|
||||||
const categoryModels = models[category]
|
const models = resp.data
|
||||||
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
const categoryModels = models[category]
|
||||||
} else {
|
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
||||||
throw new Error('Error fetching model list')
|
} else {
|
||||||
|
throw new Error('Error fetching model list')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
const models = await fs.promises.readFile(getModelsJSONPath(), 'utf8')
|
||||||
|
if (models) {
|
||||||
|
const categoryModels = JSON.parse(models)[category]
|
||||||
|
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
||||||
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} else {
|
||||||
const models = await fs.promises.readFile(getModelsJSONPath(), 'utf8')
|
try {
|
||||||
if (models) {
|
if (fs.existsSync(modelFile)) {
|
||||||
const categoryModels = JSON.parse(models)[category]
|
const models = await fs.promises.readFile(modelFile, 'utf8')
|
||||||
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
if (models) {
|
||||||
|
const categoryModels = JSON.parse(models)[category]
|
||||||
|
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {}
|
||||||
|
} catch (e) {
|
||||||
|
const models = await fs.promises.readFile(getModelsJSONPath(), 'utf8')
|
||||||
|
if (models) {
|
||||||
|
const categoryModels = JSON.parse(models)[category]
|
||||||
|
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
|
||||||
|
}
|
||||||
|
return {}
|
||||||
}
|
}
|
||||||
return {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user