()
| 34 | * If any of the loading fails, fallback to the default models.json file on disk |
| 35 | */ |
| 36 | const getRawModelFile = async () => { |
| 37 | const modelFile = |
| 38 | process.env.MODEL_LIST_CONFIG_JSON ?? 'https://raw.githubusercontent.com/FlowiseAI/Flowise/main/packages/components/models.json' |
| 39 | try { |
| 40 | if (isValidUrl(modelFile)) { |
| 41 | const resp = await axios.get(modelFile) |
| 42 | if (resp.status === 200 && resp.data) { |
| 43 | return resp.data |
| 44 | } else { |
| 45 | throw new Error('Error fetching model list') |
| 46 | } |
| 47 | } else if (fs.existsSync(modelFile)) { |
| 48 | const models = await fs.promises.readFile(modelFile, 'utf8') |
| 49 | if (models) { |
| 50 | return JSON.parse(models) |
| 51 | } |
| 52 | } |
| 53 | throw new Error('Model file does not exist or is empty') |
| 54 | } catch (e) { |
| 55 | const models = await fs.promises.readFile(getModelsJSONPath(), 'utf8') |
| 56 | if (models) { |
| 57 | return JSON.parse(models) |
| 58 | } |
| 59 | return {} |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | const getModelConfig = async (category: MODEL_TYPE, name: string) => { |
| 64 | const models = await getRawModelFile() |
no test coverage detected