fix: 修复 ollama 免 key 无法启动与示例 base_url 缺 /v1#29
Open
525300887039 wants to merge 1 commit into
Open
Conversation
litellm 构造客户端时无条件要求 api_key 非空(OpenAICompatProvider 未重写 Validate,沿用 BaseProvider 校验,无视 ollama 的 SkipAPIKeyValidation), 与本项目 RequiresAPIKey 约定冲突,ollama 等免 key provider 报 "ollama: API key is required" 无法启动。 - createModelFromConfig: 对 RequiresAPIKey==false 的 provider 在 key 为空时 注入占位 api_key 绕过 litellm 构造校验(ollama 忽略该值) - config.example.jsonc / setup.go / README.md: ollama base_url 补全 /v1 (OpenAI 兼容端点在 /v1 下,省略会打到 /chat/completions 失败) Closes voocel#28
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.
问题
复现 #28:使用 ollama 时,按
config.example.jsonc的示例(省略api_key、base_url不带/v1)会启动失败:根因
api_key 被强制要求:
createModelFromConfig→ litellmclient.New()在构造时无条件调用provider.Validate();OpenAICompatProvider未重写导出的Validate(),沿用BaseProvider.Validate()(只校验 key 非空),无视 ollama 的SkipAPIKeyValidation。这与本项目RequiresAPIKey("ollama") == false的约定冲突,导致免 key provider 报API key is required。base_url 缺
/v1:示例里显式写http://localhost:11434,会被原样拼成/chat/completions;而 ollama 的 OpenAI 兼容端点在/v1下,应为http://localhost:11434/v1。改动
internal/bootstrap/models.go:对RequiresAPIKey == false的 provider 在api_key为空时注入占位 key(no-key),绕过 litellm 构造期校验。ollama 忽略该值;免鉴权自定义代理同理。对 bedrock 无行为变化(其将api_key解析为accessKeyID:secretAccessKey,无冒号占位后仍报相同的 AWS 凭证缺失错误)。config.example.jsonc/internal/bootstrap/setup.go(向导预填 + 内嵌模板)/README.md:ollamabase_url统一补全/v1。这样既修好了 issue,也让"ollama / 免鉴权代理可省略 api_key"的文档承诺真正成立。
验证
go build ./...、go vet ./internal/bootstrap:通过gofmt:改动内容合规go test ./...:通过(internal/rules有一处 Windows 平台相关的既有失败,与本 PR 无关,已确认在未改动的 main 上同样失败)Closes #28