-
-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Add timeout for remote model list loading #6551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import axios from 'axios' | ||
| import { getModelConfigByModelName, MODEL_TYPE } from './modelLoader' | ||
|
|
||
| jest.mock('axios') | ||
|
|
||
| const mockedAxios = axios as jest.Mocked<typeof axios> | ||
|
|
||
| describe('modelLoader', () => { | ||
| const originalModelListConfigJson = process.env.MODEL_LIST_CONFIG_JSON | ||
|
|
||
| afterEach(() => { | ||
| jest.resetAllMocks() | ||
| if (originalModelListConfigJson === undefined) { | ||
| delete process.env.MODEL_LIST_CONFIG_JSON | ||
| } else { | ||
| process.env.MODEL_LIST_CONFIG_JSON = originalModelListConfigJson | ||
| } | ||
| }) | ||
|
|
||
| it('uses a bounded timeout when loading remote model config before falling back locally', async () => { | ||
| process.env.MODEL_LIST_CONFIG_JSON = 'https://example.com/models.json' | ||
| mockedAxios.get.mockRejectedValueOnce(new Error('timeout')) | ||
|
|
||
| const modelConfig = await getModelConfigByModelName(MODEL_TYPE.CHAT, 'awsChatBedrock', 'ai21.jamba-1-5-large-v1:0') | ||
|
|
||
| expect(mockedAxios.get).toHaveBeenCalledWith('https://example.com/models.json', { timeout: 5000 }) | ||
| expect(modelConfig?.name).toBe('ai21.jamba-1-5-large-v1:0') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ import * as fs from 'fs' | |
| import * as path from 'path' | ||
| import { INodeOptionsValue } from './Interface' | ||
|
|
||
| const MODEL_LIST_FETCH_TIMEOUT_MS = 5000 | ||
|
|
||
| export enum MODEL_TYPE { | ||
| CHAT = 'chat', | ||
| LLM = 'llm', | ||
|
|
@@ -38,7 +40,7 @@ const getRawModelFile = async () => { | |
| process.env.MODEL_LIST_CONFIG_JSON ?? 'https://raw.githubusercontent.com/FlowiseAI/Flowise/main/packages/components/models.json' | ||
| try { | ||
| if (isValidUrl(modelFile)) { | ||
| const resp = await axios.get(modelFile) | ||
| const resp = await axios.get(modelFile, { timeout: MODEL_LIST_FETCH_TIMEOUT_MS }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance & UX Issue: Repeated Network Requests and TimeoutsCurrently, With the new 5-second timeout:
RecommendationImplement an in-memory cache for the loaded models so that the remote file (or local fallback) is only fetched/read once per application lifecycle.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in c992188. The loader now caches the loaded model file per model-list source and supports MODEL_LIST_FETCH_TIMEOUT_MS with a default fallback. Validation: git diff --check and ./node_modules/.bin/jest src/modelLoader.test.ts --runInBand from packages/components. |
||
| if (resp.status === 200 && resp.data) { | ||
| return resp.data | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to make the fetch timeout configurable via an environment variable. This allows users in restricted network environments, slow proxies, or air-gapped systems to adjust the timeout value as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c992188. The loader now caches the loaded model file per model-list source and supports MODEL_LIST_FETCH_TIMEOUT_MS with a default fallback.
Validation: git diff --check and ./node_modules/.bin/jest src/modelLoader.test.ts --runInBand from packages/components.