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:
Henry Heng
2024-05-30 11:59:19 +01:00
committed by GitHub
parent d734747ec0
commit 059eae4268
2 changed files with 46 additions and 15 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ Flowise support different environment variables to configure your instance. You
| DEBUG | Print logs from components | Boolean | |
| 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_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` |
| 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 | |
+45 -14
View File
@@ -21,27 +21,58 @@ const getModelsJSONPath = (): string => {
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 modelFile = process.env.MODEL_LIST_CONFIG_JSON || MASTER_MODEL_LIST
if (!modelFile) {
throw new Error('MODEL_LIST_CONFIG_JSON not set')
}
try {
const resp = await axios.get(modelFile)
if (resp.status === 200 && resp.data) {
const models = resp.data
const categoryModels = models[category]
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
} else {
throw new Error('Error fetching model list')
if (isValidUrl(modelFile)) {
try {
const resp = await axios.get(modelFile)
if (resp.status === 200 && resp.data) {
const models = resp.data
const categoryModels = models[category]
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
} 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) {
const models = await fs.promises.readFile(getModelsJSONPath(), 'utf8')
if (models) {
const categoryModels = JSON.parse(models)[category]
return categoryModels.find((model: INodeOptionsValue) => model.name === name)
} else {
try {
if (fs.existsSync(modelFile)) {
const models = await fs.promises.readFile(modelFile, 'utf8')
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 {}
}
}