-
-
Notifications
You must be signed in to change notification settings - Fork 181
feat: add models-list endpoint support #482
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -25,8 +25,9 @@ import type { Format } from "../converters/types"; | |||||||||
| * - "claude": 检测到 Claude Messages API 格式的请求(通过 `system` 或 Claude 特有字段) | ||||||||||
| * - "gemini": 检测到 Gemini API 直接格式的请求(通过 `contents` 字段) | ||||||||||
| * - "gemini-cli": 检测到 Gemini CLI 格式的请求(通过 `request` envelope) | ||||||||||
| * - "models-list": 模型列表请求(格式无关,不限制供应商类型) | ||||||||||
| */ | ||||||||||
| export type ClientFormat = "response" | "openai" | "claude" | "gemini" | "gemini-cli"; | ||||||||||
| export type ClientFormat = "response" | "openai" | "claude" | "gemini" | "gemini-cli" | "models-list"; | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 根据请求端点检测客户端格式(优先级最高) | ||||||||||
|
|
@@ -67,6 +68,13 @@ export function detectFormatByEndpoint(pathname: string): ClientFormat | null { | |||||||||
| // OpenAI Chat Completions | ||||||||||
| { pattern: /^\/v1\/chat\/completions$/i, format: "openai" }, | ||||||||||
|
|
||||||||||
| // ⭐ 模型列表端点(格式无关,不限制供应商类型,仅按用户分组过滤) | ||||||||||
| // 支持多种客户端:有些请求 /v1/models,有些在 base URL 后加 /models | ||||||||||
| { pattern: /^\/v1\/models$/i, format: "models-list" }, | ||||||||||
| { pattern: /^\/v1\/responses\/models$/i, format: "models-list" }, | ||||||||||
| { pattern: /^\/v1\/chat\/completions\/models$/i, format: "models-list" }, | ||||||||||
|
Comment on lines
+73
to
+75
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. For better maintainability and conciseness, the three regular expressions for the
Suggested change
|
||||||||||
| { pattern: /^\/v1beta\/models$/i, format: "models-list" }, | ||||||||||
|
|
||||||||||
| // Gemini Direct API | ||||||||||
| { | ||||||||||
| pattern: /^\/v1beta\/models\/[^/:]+:(?:generateContent|streamGenerateContent|countTokens)$/i, | ||||||||||
|
|
@@ -107,6 +115,10 @@ export function mapClientFormatToTransformer(clientFormat: ClientFormat): Format | |||||||||
| return "gemini-cli"; // 直接 Gemini 格式内部使用 gemini-cli 转换器 | ||||||||||
| case "gemini-cli": | ||||||||||
| return "gemini-cli"; | ||||||||||
| case "models-list": | ||||||||||
| // 模型列表端点不需要格式转换,默认返回 openai-compatible | ||||||||||
| // 因为大多数客户端期望 OpenAI 格式的模型列表响应 | ||||||||||
| return "openai-compatible"; | ||||||||||
| default: { | ||||||||||
| // 类型守卫:如果有未处理的格式,TypeScript 会报错 | ||||||||||
| const _exhaustiveCheck: never = clientFormat; | ||||||||||
|
|
@@ -156,6 +168,16 @@ export function mapTransformerFormatToClient(transformerFormat: Format): ClientF | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 检查是否为模型列表端点(格式无关) | ||||||||||
| * | ||||||||||
| * @param format - 客户端格式 | ||||||||||
| * @returns 是否为模型列表端点 | ||||||||||
| */ | ||||||||||
| export function isModelsListFormat(format: ClientFormat): boolean { | ||||||||||
| return format === "models-list"; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * 检测请求格式(基于请求体结构) | ||||||||||
| * | ||||||||||
|
|
||||||||||
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
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
Oops, something went wrong.
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.
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.
The changelog entries added in this pull request do not seem to correspond to the feature being introduced (
feat: add models-list endpoint support). The changelog should accurately reflect the changes made in this PR. Please update this section to describe the newmodels-listendpoint support.