Skip to content

修改前端,"测试场"新增测试模型网关模型#1597

Merged
looplj merged 2 commits into
looplj:unstablefrom
zhai23:unstable
May 5, 2026
Merged

修改前端,"测试场"新增测试模型网关模型#1597
looplj merged 2 commits into
looplj:unstablefrom
zhai23:unstable

Conversation

@zhai23

@zhai23 zhai23 commented May 4, 2026

Copy link
Copy Markdown
Contributor

在测试场的渠道下拉中新增“模型网关”选项,用于通过默认路由流程测试模型页配置的模型。
选择“模型网关”时,模型下拉会加载模型页中已启用的聊天模型并显示模型名;发送请求时不再携带 X-Channel-ID,让后端根据模型关联规则自动解析可用渠道。原有按渠道测试的流程保持不变。
image

在测试场的渠道下拉中新增“模型网关”选项,用于通过默认路由流程测试模型页配置的模型。
选择“模型网关”时,模型下拉会加载模型页中已启用的聊天模型并显示模型名;发送请求时不再携带 X-Channel-ID,让后端根据模型关联规则自动解析可用渠道。原有按渠道测试的流程保持不变。
@greptile-apps

greptile-apps Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds a Model Gateway test mode to the Playground UI via a tab switcher, allowing users to test models through the default routing flow without specifying a channel. useQueryModels gains an enabled option for deferred fetching, and locale strings are cleaned up with a pre-existing bug fix.

Confidence Score: 5/5

This PR is safe to merge — changes are frontend-only, additive, and well-guarded.

No P0 or P1 issues found. The deferred-query pattern with enabled and the useEffect fallback for auto-selecting the first model covers the loading-state race correctly. Header logic change (omitting empty X-Channel-ID) is an improvement. Locale bug fix is correct. Removal of MODEL_ID from the sort union is safe — no other caller of this hook used that field.

No files require special attention.

Important Files Changed

Filename Overview
frontend/src/features/playground/index.tsx Core logic for the new model source tab, conditional header sending, and model auto-selection on source switch. State management via refs and effects is consistent with the existing pattern. No logic errors found.
frontend/src/features/models/data/models.ts Adds optional enabled parameter to useQueryModels and removes unused MODEL_ID sort field from the TypeScript union. No other callers of this specific hook use MODEL_ID, so the removal is safe.
frontend/src/locales/en/playground.json Adds new translation keys for model source tab and gateway model count; fixes pre-existing incorrect 'No models available' text on the channel selector.
frontend/src/locales/zh-CN/playground.json Mirrors the English locale additions and bug-fix. Chinese strings look accurate.

Sequence Diagram

sequenceDiagram
    participant User
    participant Playground UI
    participant React Query
    participant Backend

    User->>Playground UI: Select "Channel" tab (default)
    Playground UI->>React Query: useQueryChannels (always enabled)
    React Query-->>Playground UI: channelsData
    Playground UI->>Playground UI: Auto-select first channel + model

    User->>Playground UI: Send message
    Playground UI->>Backend: POST /admin/playground/chat<br/>Headers: Authorization, X-Project-ID, X-Channel-ID<br/>Body: {model, temperature, max_tokens, system}
    Backend-->>Playground UI: Streaming response

    User->>Playground UI: Switch to "Model Gateway" tab
    Playground UI->>React Query: useQueryModels (now enabled)
    React Query-->>Playground UI: modelsData (enabled chat models)
    Playground UI->>Playground UI: Auto-select first model from list

    User->>Playground UI: Send message
    Playground UI->>Backend: POST /admin/playground/chat<br/>Headers: Authorization, X-Project-ID (no X-Channel-ID)<br/>Body: {model, temperature, max_tokens, system}
    Backend->>Backend: Auto-resolve channel via model routing rules
    Backend-->>Playground UI: Streaming response
Loading

Reviews (2): Last reviewed commit: "改为使用Tab,页面足够,使用更清晰" | Re-trigger Greptile

Comment thread frontend/src/features/playground/index.tsx
Comment thread frontend/src/locales/en/playground.json Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a "Model Gateway" option to the playground, allowing users to select models directly from the model page. It updates the useQueryModels hook to support conditional fetching and modifies the playground's selection logic and UI to integrate this new channel. Feedback includes addressing a UX inconsistency where the default selected channel does not match the first item in the dropdown list and a suggestion to memoize query arguments in the useQueryModels hook to optimize performance.

Comment on lines +288 to +292
useEffect(() => {
if (!selectedChannel && channelOptions.length > 0) {
handleChannelChange(channelOptions[0].value);
if (!selectedChannel && !channelsLoading && channelOptions.length > 0) {
handleChannelChange(realChannelOptions[0]?.value ?? MODEL_PAGE_CHANNEL_VALUE);
}
}, [channelOptions, handleChannelChange, selectedChannel]);
}, [channelOptions, channelsLoading, handleChannelChange, realChannelOptions, selectedChannel]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The initialization logic defaults to the first real channel (realChannelOptions[0]) if available, even though the "Model Gateway" option is prepended to the channelOptions list and appears first in the UI. This creates a UX inconsistency where the first item in the dropdown is not the default selection. Consider either making the "Model Gateway" the default or moving it to the end of the list to match the default selection behavior.

Comment on lines +77 to +87
const { data: modelsData, isLoading: modelsLoading } = useQueryModels(
{
first: 10000,
orderBy: { field: 'NAME', direction: 'ASC' },
where: {
statusIn: ['enabled'],
typeIn: ['chat'],
},
},
{ enabled: isModelPageChannel }
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The args object passed to useQueryModels is created on every render. While TanStack Query performs a deep comparison on the queryKey, it is generally better practice to memoize static arguments to avoid unnecessary object creation and comparison logic in the hook.

Suggested change
const { data: modelsData, isLoading: modelsLoading } = useQueryModels(
{
first: 10000,
orderBy: { field: 'NAME', direction: 'ASC' },
where: {
statusIn: ['enabled'],
typeIn: ['chat'],
},
},
{ enabled: isModelPageChannel }
);
const modelQueryArgs = useMemo(() => ({
first: 10000,
orderBy: { field: 'NAME' as const, direction: 'ASC' as const },
where: {
statusIn: ['enabled'],
typeIn: ['chat'],
},
}), []);
const { data: modelsData, isLoading: modelsLoading } = useQueryModels(
modelQueryArgs,
{ enabled: isModelPageChannel }
);

@looplj

looplj commented May 5, 2026

Copy link
Copy Markdown
Owner

建议改成 tab,而不是使用一个特殊的值。

改为使用Tab,页面足够,使用更清晰
@zhai23

zhai23 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

建议改成 tab,而不是使用一个特殊的值。

确实,这样更清晰,修改为tab提交了

@looplj looplj merged commit fcad222 into looplj:unstable May 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants