Repository navigation
Conversation
- 新增 POST /api/models:自动探测 OpenAI/Anthropic 格式,GET {base_url}/v1/models 拉取模型列表,兼容 data/models 数组、id/name 字段与纯字符串数组等响应结构,复用现有 User-Agent 伪装与 WAF 拦截错误提示
- “API 自动测试”与“新建指纹”表单的“接口模型名”旁新增“获取模型”按钮,获取后经 datalist 下拉选择,无需手工输入模型名
- 未填 Base URL/API Key 时提示先填写;成功提示模型数量;列表为空与请求失败分别给出提示
- 输入框与按钮同行排版、底部对齐,窄屏自动退化为单列
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR:测试与采集表单支持从接口获取可选模型列表
当前「模型测试 → API 自动测试」和「指纹库管理 → 新建指纹」两处表单中的接口模型名都需要用户手工输入。多数 OpenAI 兼容网关(以及 Anthropic 官方 API)都提供
GET /v1/models接口用于列出可用模型,但用户往往不知道自己的服务端到底支持哪些模型名,容易拼错或使用了与指纹库不一致的写法,导致测试/采集失败。本 PR 在两处表单的「接口模型名」输入框旁增加获取模型按钮:填好 Base URL 与 API Key 后一键拉取上游模型列表,点击输入框即可从下拉列表中选择,无需手工输入。
改动内容(5 个文件,+142 / -3)
enrollment.pylist_models():向{base_url}/v1/models发 GET 请求拉取模型列表app.pyPOST /api/models路由,成功返回{"models": [...]},失败返回 502 与压缩后的可读错误templates/index.htmltest-model-options/enroll-model-options两个dataliststatic/app.jsfetchModelOptions(),统一处理两个按钮的请求、填充与提示static/styles.css实现细节
request_completion一致,先按 OpenAI 格式请求/v1/models,失败再回退 Anthropic 格式(x-api-key+anthropic-version头)。{"data": [{"id": ...}]}、{"models": [...]}、顶层纯数组,以及条目为id/name字段或纯字符串的情况;结果排序去重后返回。User-Agent伪装(规避 Cloudflare/WAF 对 Python 默认 UA 的 403 拦截),错误提示复用_compact_upstream_error,WAF 拦截页会给出与聊天接口一致的排查建议。model-optionsdatalist)保持不变;本次仅替换两处「接口模型名」的候选来源。测试验证
python -m py_compile app.py enrollment.py通过。{"data": [{"id": "mock-a"}, {"id": "mock-b"}]})+ Flasktest_client冒烟测试:list_models()正确解析为['mock-a', 'mock-b'];POST /api/models返回 200 与解析后的模型列表;datalist。兼容性 / 风险
GET /v1/models或拒绝该路径,此时按钮会返回可读错误,用户仍可像之前一样手工输入模型名,不影响原有流程。截图