Skip to content

Commit 2cf3f89

Browse files
authored
[bugfix] providers: fetch the live text model list (#462)
* [bugfix] providers: fetch the live text model list Signed-off-by: Weiming Liao <liaowm5@gmail.com> * [test] providers: split new model discovery gate Signed-off-by: Weiming Liao <liaowm5@gmail.com> --------- Signed-off-by: Weiming Liao <liaowm5@gmail.com>
1 parent 6a41c57 commit 2cf3f89

15 files changed

Lines changed: 407 additions & 62 deletions

File tree

‎apps/api/src/opendirector_api/localization.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
chooses an English message from the stable error code when the caller asks for
55
English, so a missing translation never leaks Chinese into an English UI.
66
"""
7+
import re
8+
79
from fastapi import Request
810

911

@@ -98,6 +100,7 @@
98100
"role_restricted": "This item does not allow that operation.",
99101
"storage_unavailable": "A stored file is missing or has changed. Restore the file and try again.",
100102
"capability_unsupported": "This capability is not supported yet.",
103+
"model_list_http_error": "Could not load the model list from the service.",
101104
"operation_rejected": "The operation was rejected. Reload the item and try again.",
102105
"storage_busy": "Project storage is busy. Try again shortly.",
103106
"project_open_elsewhere": "This project is open in another window. Close it there and try again.",
@@ -150,6 +153,10 @@ def localized_error_for_language(
150153
return chinese
151154
if code == 'tool_model_missing':
152155
return missing_tool_model_message(required_capability, english=True)
156+
if code == 'model_list_http_error':
157+
upstream_status = re.search(r'HTTP ([0-9]{3})', chinese)
158+
if upstream_status:
159+
return f'Could not load the model list (HTTP {upstream_status[1]}).'
153160
if code.startswith(('capability_', 'image_input_', 'tool_source_')):
154161
translated = english_capability_message(chinese)
155162
if translated:

‎docs/development/validation.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,13 @@ Zhipu BigModel chat access uses the following checks. Browser commands connect t
607607
```sh
608608
.venv/bin/python -m pytest tests/test_zhipu.py tests/test_model_configs.py -q
609609
node --test tests/providerPresets.test.ts
610+
CREATION_API_URL=http://127.0.0.1:8019 CREATION_WEB_URL=http://127.0.0.1:5179 node tests/browser/new_model_discovery.mjs
610611
CREATION_API_URL=http://127.0.0.1:8019 CREATION_WEB_URL=http://127.0.0.1:5179 node tests/browser/zhipu_provider.mjs
611612
```
612613

613614
The Python cases check how the shared thinking levels map to GLM reasoning_effort. GLM accepts only low, high and max for reasoning_effort. The auto level omits the parameter so the provider default applies, and an unknown level falls back to high as in the DeepSeek branch. Other hosts and the DeepSeek behavior stay unchanged.
614615

615-
The browser case checks both display languages for the provider list and names, canonical URL prefill, GLM model preselection without remote discovery, manual addition of other model IDs, the saved connection reuse hint, save and reopen, key privacy in public model responses, and the assistant agent picker listing and keeping the selected Zhipu model. The browser never contacts open.bigmodel.cn and the API key is always a fixture value. Real streaming conversations, tool call execution and thinking level effects additionally require valid Zhipu credentials. Keep the conversation transcript, tool receipts and screenshots as evidence.
616+
The **New model discovery** case runs on its own with the isolated API and Vite. It verifies that a model absent from the preset appears after an authenticated `GET /models`, can be selected and saved, and remains selectable in the assistant. The **Zhipu model settings feedback** case checks both display languages for missing credentials, request progress, upstream failure, retry, empty responses, manual entry, and audio preset isolation. Both cases use local HTTP fixtures and synthetic keys. Real streaming conversations, tool calls, and thinking levels require a separate run with valid Zhipu credentials.
616617

617618
智谱 BigModel GLM-TTS 接入使用以下检查:
618619

‎packages/core/src/opendirector/integrations/model_capabilities.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Read an optional, explicit videoCapabilities extension on GET /models."""
1+
"""Read service model lists and resolve video capabilities."""
22
import json
33
import logging
44

@@ -23,18 +23,20 @@ async def read_service_models(config, transport=None):
2323
return [{'id': name, 'videoCapabilities': kling_capabilities(name)} for name in KLING_MODELS]
2424
if config.get('protocol') == 'minimax_video_v2':
2525
return [{'id': name} for name in MINIMAX_MODELS]
26+
is_text_model = config.get('kind') == 'agent'
2627
try:
2728
async with httpx.AsyncClient(event_hooks=MODEL_HTTP_HOOKS, transport=transport, trust_env=trust_environment(config['url'], config=config),
2829
timeout=15, follow_redirects=False) as client:
2930
async with client.stream('GET', endpoint(config['url'], '/models'), headers=auth_headers(config)) as response:
3031
if response.status_code != 200:
31-
raise ProjectError(f'读取模型声明失败(HTTP {response.status_code}),未修改配置。')
32+
raise ProjectError(f'读取模型声明失败(HTTP {response.status_code}),未修改配置。',
33+
code='model_list_http_error' if is_text_model else None)
3234
data = bytearray()
3335
async for chunk in response.aiter_bytes():
3436
data.extend(chunk)
3537
if len(data) > 1024 * 1024:
3638
raise ProjectError('模型声明超过 1 MB,未修改配置。')
37-
models = json.loads(data).get('data', [])
39+
models = json.loads(data).get('data', None if is_text_model else [])
3840
if not isinstance(models, list) or any(not isinstance(item, dict) or not isinstance(item.get('id'), str)
3941
or not item['id'].strip() or len(item['id']) > 200 for item in models):
4042
raise ProjectError('服务返回的模型列表格式无效。')

‎scripts/run-browser-suite.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const workflows = [
3232
},
3333
{ name: "minimax h3", script: "tests/browser/minimax_h3.mjs" },
3434
{ name: "provider settings", script: "tests/browser/provider_settings.mjs" },
35+
{ name: "new model discovery", script: "tests/browser/new_model_discovery.mjs" },
36+
{ name: "Zhipu model settings feedback", script: "tests/browser/zhipu_provider.mjs" },
3537
{ name: "capability discovery", script: "tests/browser/capability_discovery.mjs" },
3638
{ name: "created node focus", script: "tests/browser/created_node_focus.mjs" },
3739
{ name: "cross canvas paste", script: "tests/browser/cross_canvas_paste.mjs" },

‎src/canvas/ModelPicker.tsx‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function ModelPicker({
1414
selected,
1515
loaded,
1616
loading,
17+
loadsPreset,
1718
error,
1819
disabled,
1920
canFetch,
@@ -22,13 +23,13 @@ export function ModelPicker({
2223
onTest,
2324
results,
2425
renderDetails,
25-
fetchLabel,
2626
}: {
2727
modelPlaceholder: string;
2828
available: string[];
2929
selected: string[];
3030
loaded: boolean;
3131
loading: boolean;
32+
loadsPreset: boolean;
3233
error: string;
3334
disabled: boolean;
3435
canFetch: boolean;
@@ -37,7 +38,6 @@ export function ModelPicker({
3738
onTest?: (id: string) => void;
3839
results: Record<string, ModelTestResult>;
3940
renderDetails?: (id: string) => ReactNode;
40-
fetchLabel?: string;
4141
}) {
4242
const t = useT();
4343
const manualFieldId = useId();
@@ -55,6 +55,17 @@ export function ModelPicker({
5555
);
5656
const allSelected =
5757
visible.length > 0 && visible.every((id) => selected.includes(id));
58+
const fetchLabel = loadsPreset
59+
? "models.service.loadSupportedModels"
60+
: loaded ? "generation.picker.refresh" : "generation.picker.fetch";
61+
let status = "";
62+
if (loading) {
63+
status = t("generation.picker.fetching");
64+
} else if (loaded && !error) {
65+
status = available.length
66+
? t(loadsPreset ? "generation.picker.loadedPreset" : "generation.picker.fetched", { count: available.length })
67+
: t("generation.picker.noReturned");
68+
}
5869
const addManual = () => {
5970
const id = manualId.trim();
6071
if (!id || id.length > 200 || /[\x00-\x1f]/.test(id)) {
@@ -101,18 +112,21 @@ export function ModelPicker({
101112
<button
102113
type="button"
103114
className="cw-settings-button"
104-
disabled={disabled || !canFetch}
115+
disabled={disabled}
105116
onClick={onFetch}
106117
>
107-
{loading
108-
? t("generation.picker.loading")
109-
: (fetchLabel ??
110-
(loaded
111-
? t("generation.picker.refresh")
112-
: t("generation.picker.fetch")))}
118+
{t(loading ? "generation.picker.loading" : fetchLabel)}
113119
</button>
114120
</div>
115121
</div>
122+
<div role="status">
123+
{status && <p className="cw-model-note">{status}</p>}
124+
</div>
125+
{error && (
126+
<p className="cw-model-feedback" role="alert">
127+
{error}
128+
</p>
129+
)}
116130
{manualOpen && (
117131
<div className="cw-model-manual">
118132
<label htmlFor={manualFieldId}>
@@ -160,11 +174,6 @@ export function ModelPicker({
160174
)}
161175
</div>
162176
)}
163-
{error && (
164-
<p className="cw-model-feedback" role="alert">
165-
{t("generation.picker.retry", { error })}
166-
</p>
167-
)}
168177
{ids.length > 4 && (
169178
<>
170179
<div className="cw-model-filterbar">
@@ -209,15 +218,14 @@ export function ModelPicker({
209218
)}
210219
<div className="cw-model-options" aria-busy={loading}>
211220
{loading && !ids.length ? (
212-
<div className="cw-model-empty-state" role="status">
221+
<div className="cw-model-empty-state">
213222
<span className="cw-model-spinner" />
214-
<strong>{t("generation.picker.fetching")}</strong>
215223
<p>{t("generation.picker.connecting")}</p>
216224
</div>
217225
) : !ids.length ? (
218226
<div className="cw-model-empty-state">
219227
<CanvasIcon name="model" size={26} />
220-
<strong>{loaded ? t("generation.picker.noReturned") : t("generation.picker.noneAdded")}</strong>
228+
{!loaded && <strong>{t("generation.picker.noneAdded")}</strong>}
221229
<p>
222230
{loaded
223231
? t("generation.picker.manualHint")

‎src/canvas/ModelServiceForm.tsx‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,19 @@ export function ModelServiceForm({
145145
const segmentation = value.protocol === "vllm_omni_segmentation";
146146
const depth = value.protocol === "vllm_omni_depth";
147147
const score = value.protocol === "vllm_omni_score";
148+
const preset = PROVIDER_PRESETS.find((item) => item.id === presetId);
149+
const mediaPresetModels = kind === "agent" ? undefined : preset?.modelsByKind?.[kind];
148150
const hasSavedKey = Boolean(
149151
connection &&
150152
connection.authMode === "bearer" &&
151153
connection.url === value.url.trim(),
152154
);
153-
const canFetch = Boolean(
154-
value.url.trim() &&
155-
(value.authMode === "none" || value.apiKey.trim() || hasSavedKey),
156-
);
155+
const fetchPrerequisite = !value.url.trim()
156+
? "generation.picker.addressRequired"
157+
: value.authMode === "bearer" && !value.apiKey.trim() && !hasSavedKey
158+
? "generation.picker.keyRequired"
159+
: null;
160+
const canFetch = fetchPrerequisite === null;
157161
const canSave = canFetch && selectedModels.length > 0 && selectedModels.length <= 200 &&
158162
!selectedTestFailed && !selectedModels.some((id) => modelErrors[id]);
159163
const update = (patch: Partial<ModelConfigInput>) => {
@@ -174,7 +178,7 @@ export function ModelServiceForm({
174178
patch.protocol !== undefined ||
175179
patch.connectionType !== undefined ||
176180
patch.authMode !== undefined;
177-
if (connectionChanged) {
181+
if (connectionChanged || patch.proxyMode !== undefined) {
178182
setModelIds(selectedModels);
179183
setLoaded(false);
180184
setDiscoveryError("");
@@ -198,20 +202,23 @@ export function ModelServiceForm({
198202
setError("");
199203
};
200204
const loadModels = async () => {
205+
if (fetchPrerequisite) {
206+
setDiscoveryError(t(fetchPrerequisite));
207+
if (fetchPrerequisite === "generation.picker.addressRequired") setConnectionOpen(true);
208+
return;
209+
}
201210
setDiscovering(true);
202211
setDiscoveryError("");
203212
try {
204-
const preset = PROVIDER_PRESETS.find((item) => item.id === presetId);
205-
const presetModels = preset?.modelsByKind?.[kind];
206-
const models = presetModels
207-
? [...presetModels]
213+
const models = mediaPresetModels
214+
? [...mediaPresetModels]
208215
: (await discoverModels(value, connection?.id)).models;
209216
setModelIds(models);
210-
if (presetModels && !connection) setSelectedModels(models);
217+
if (mediaPresetModels && !connection) setSelectedModels(models);
211218
setLoaded(true);
212219
setConnectionOpen(false);
213220
} catch (failure) {
214-
setDiscoveryError(errorMessage(failure));
221+
setDiscoveryError(t("generation.picker.retry", { error: errorMessage(failure) }));
215222
} finally {
216223
setDiscovering(false);
217224
}
@@ -320,6 +327,8 @@ export function ModelServiceForm({
320327
);
321328
setSelectedModels(peers.map((item) => item.modelId));
322329
setModelIds(peers.map((item) => item.modelId));
330+
setLoaded(false);
331+
setDiscoveryError("");
323332
setModelOptions({});
324333
setModelErrors({});
325334
setResults({});
@@ -524,6 +533,7 @@ export function ModelServiceForm({
524533
selected={selectedModels}
525534
loaded={loaded}
526535
loading={discovering}
536+
loadsPreset={Boolean(mediaPresetModels)}
527537
error={discoveryError}
528538
disabled={locked}
529539
canFetch={canFetch}
@@ -534,11 +544,6 @@ export function ModelServiceForm({
534544
}}
535545
onTest={kind === "agent" ? (id) => void test(id) : undefined}
536546
results={results}
537-
fetchLabel={
538-
PROVIDER_PRESETS.find((item) => item.id === presetId)?.modelsByKind?.[kind]
539-
? t("models.service.loadSupportedModels")
540-
: undefined
541-
}
542547
renderDetails={(id) => (
543548
<>
544549
<DraftAvailabilityCheck connection={{ ...value, ...optionsFor(id) }} configId={connection?.id} modelId={id} />

‎src/i18n/messages/en-US/generation.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ export const generation = {
216216
"generation.picker.modelId": "Model ID (the service's served-model-name)",
217217
"generation.picker.add": "Add",
218218
"generation.picker.cancel": "Cancel",
219+
"generation.picker.addressRequired": "Enter the service address first.",
220+
"generation.picker.keyRequired": "Enter an API Key first.",
219221
"generation.picker.retry": "{error} You can retry or add a model manually.",
220222
"generation.picker.search": "Search models",
221223
"generation.picker.searchPlaceholder": "Search model names…",
@@ -227,6 +229,14 @@ export const generation = {
227229
"generation.picker.selectAll": "Select all current results",
228230
"generation.picker.deselectAll": "Deselect all",
229231
"generation.picker.fetching": "Fetching the model list",
232+
"generation.picker.fetched": {
233+
one: "{count} model fetched",
234+
other: "{count} models fetched",
235+
},
236+
"generation.picker.loadedPreset": {
237+
one: "{count} preset model loaded",
238+
other: "{count} preset models loaded",
239+
},
230240
"generation.picker.connecting": "Connecting to the service…",
231241
"generation.picker.noReturned": "The service returned no models",
232242
"generation.picker.noneAdded": "No models added yet",

‎src/i18n/messages/zh-CN/generation.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ export const generation = {
201201
"generation.picker.modelId": "Model ID(服务的 served-model-name)",
202202
"generation.picker.add": "添加",
203203
"generation.picker.cancel": "取消",
204+
"generation.picker.addressRequired": "请先填写服务地址。",
205+
"generation.picker.keyRequired": "请先填写 API Key。",
204206
"generation.picker.retry": "{error} 可重试或手动添加模型。",
205207
"generation.picker.search": "搜索模型",
206208
"generation.picker.searchPlaceholder": "搜索模型名称…",
@@ -209,6 +211,8 @@ export const generation = {
209211
"generation.picker.selectAll": "全选当前结果",
210212
"generation.picker.deselectAll": "取消当前全选",
211213
"generation.picker.fetching": "正在获取模型列表",
214+
"generation.picker.fetched": "已获取 {count} 个模型",
215+
"generation.picker.loadedPreset": "已载入 {count} 个预设模型",
212216
"generation.picker.connecting": "正在连接服务,请稍候…",
213217
"generation.picker.noReturned": "服务未返回模型",
214218
"generation.picker.noneAdded": "尚未添加模型",

‎tests/browser/manifest.json‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,26 @@
552552
],
553553
"note": "Runs with voice_library_server.py in the Release checks voice library phase."
554554
},
555+
{
556+
"file": "new_model_discovery.mjs",
557+
"previewSafe": true,
558+
"lanes": [
559+
"gate"
560+
],
561+
"note": "Discovers a new text model from a loopback GET /models service, saves it, and selects it in the assistant."
562+
},
563+
{
564+
"file": "zhipu_catalog_fixture.mjs",
565+
"helper": true,
566+
"note": "Shared loopback catalog fixture for the new-model and Zhipu feedback tests."
567+
},
555568
{
556569
"file": "zhipu_provider.mjs",
557570
"previewSafe": true,
558571
"lanes": [
559-
"extended"
560-
]
572+
"gate"
573+
],
574+
"note": "Bilingual catalog feedback, retry and empty responses, and Zhipu audio preset isolation."
561575
},
562576
{
563577
"file": "kimi_real.mjs",

0 commit comments

Comments
 (0)