Repository navigation
feat: ListModels 填充 OpenRouter 与 Anthropic 的模型元数据 - #128
Open
sheepbox8646 wants to merge 1 commit into
Open
sheepbox8646 wants to merge 1 commit into
sheepbox8646 wants to merge 1 commit into
Conversation
completions 与 responses 的 ListModels 改用共享的 internal/openaimodels 解析 /models,OpenRouter 的 context_length、top_provider.max_completion_tokens、architecture 模态、supported_parameters 与 reasoning 对象会映射到 sdk.Model 元数据;字段不存在时保持零值,OpenAI 官方结果不变。 Anthropic Messages 的 ListModels 原来不分页,只拿到第一页 20 个模型。现在以 limit=1000 按 has_more/after_id 翻页,首页因 limit 被拒(400/422)时不带 limit 重试一次;并把 max_input_tokens、max_tokens、capabilities 映射为元数据。 Linear: TWI-15 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
概要
sdk.Model已经有Modalities、ContextWindow、MaxOutputTokens、ToolCall、StructuredOutput、Reasoning等元数据字段,但没有任何 provider 填充它们。completions 与 responses 指向 OpenRouter 时,列出的 462 个模型全部没有元数据。Anthropic Messages 指向 OpenRouter 时只列出 20 个模型,原因是它不分页。/models解析:新增internal/openaimodels,completions 与 responses 共用,替换原来两份重复的类型。识别 OpenRouter 的扩展字段:ContextWindow:取context_length,缺失时用top_provider.context_length。MaxOutputTokens:取top_provider.max_completion_tokens。Modalities:取architecture.input_modalities与output_modalities,file映射为pdf。ToolCall:supported_parameters含tools。StructuredOutput:只认structured_outputs。单有response_format不算,因为它可能只是不带 schema 的 JSON mode。Reasoning:结合supported_parameters与模型的reasoning对象(mandatory、default_enabled、supported_efforts、default_effort、supports_max_tokens),填入 Efforts、Budget、Off 和 Default。DisplayName与Description:取name与description。/models的解析结果不变。扩展字段类型对不上时,只丢弃该模型的元数据,不会让整个列表失败。limit=1000请求,has_more为真时用last_id作after_id继续翻页。limit被拒(400 或 422)时,不带limit重试一次,兼容上限更低的兼容服务。原实现不发送limit,所以这里需要回退。/v1/models同样默认每页 20 个,所以这个问题不止影响 OpenRouter。ContextWindow取max_input_tokens。Claude 的输出与输入共用同一个上下文窗口,所以输入上限就是整个窗口。MaxOutputTokens取max_tokens。capabilities中的image_input、pdf_input、structured_outputs、thinking、effort映射到模态、结构化输出与推理。ToolCall保持 false。docs/providers.md补充了映射规则与分页说明,docs/api-reference.md更新了Model的说明。关联
验证
ID与Provider。limit与after_id的序列。last_id。limit被拒后不带limit重试;后续页出错不重试。go build ./...、go vet ./...、go vet -tags integration ./...、go test ./... -short -count=1 -race、internal/sdkdiff的测试、golangci-lint run ./...,全部通过。go mod tidy无变化。OpenRouter 的 Anthropic 兼容端点
capabilities全是 null,所以没有模态与推理信息。anthropic/claude-sonnet-5.5上下文 1000000、输出 128000,输入 text、image、pdf,支持工具与结构化输出,effort 为 low 到 max。openai/gpt-4o上下文 128000、输出 16384,Reasoning为 nil。未验证与已知限制
max_input_tokens不统一。例如openai/gpt-5.5报 922000,即总窗口减去最大输出。这种情况下ContextWindow会偏小,偏保守。代码注释与文档中已说明。🤖 Generated with Claude Code