Skip to content

fix: 「无后缀」设置生效,带 Key 的 Ollama 请求带上 Bearer (#89) - #91

Open
haywolf wants to merge 2 commits into
masterfrom
fix/89-suffix-ollama-bearer
Open

haywolf wants to merge 2 commits into
masterfrom
fix/89-suffix-ollama-bearer

Conversation

@haywolf

@haywolf haywolf commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #89

改动

  • 新增 src/shared/providerSuffix.ts,主进程和渲染进程共用:""/null 表示用默认后缀,"none" 表示无后缀,其他值作为路径追加。旧数据的 "" 含义不变,不需要数据库迁移
  • ModelService 改用共享函数;选了无后缀时,Gemini 不再追加 /{model}:generateContent,请求地址等于 Base URL;无后缀且 Base URL 为空时报错,避免把 Key 发到官方端点
  • Provider.tsx 选择、保存、重新打开都正确显示无后缀,地址预览与实际请求一致
  • OllamaClient 在有 Key 时发送 Authorization: Bearer,没有 Key 时不带这个请求头
  • 自定义名称的 Ollama 服务商,模型列表改为请求 /tags

测试

  • 新增 providerSuffix.test.ts、ProviderEndpoint.test.ts,并补充了 Ollama、Gemini、工厂、provider handler、Provider.tsx 组件的测试
  • npm run test:unit:51 个文件,1075 个用例全部通过
  • npm run test:renderer:18 个文件,300 个用例全部通过
  • npm run typecheck、lint、electron-vite build:通过

需要注意

  • 以前选过“无后缀”的用户,库里存的是 "",和“未设置”区分不开,升级后需要重新选一次
  • 无后缀时,模型列表仍然请求 Base URL + /models

未验证项

  • 没有在真实 Electron 界面上验证,只跑了 jsdom 组件测试
  • 没有连接真实网关或带鉴权的 Ollama 代理,用 mock 和模拟代理代替

"" means "never configured" for new and preset providers, so it could not
also mean "no suffix": the runtime fell back to the default suffix and the
settings page showed the default again on reopen.

Store an explicit "none" marker for "no suffix" and keep "" as "use the
default", so existing providers request the same URLs as before. The meaning
of the stored value now lives in src/shared/providerSuffix.ts, used by both
ModelService and the settings page, so the preview matches the real URL.

Gemini appends the model path itself, so the factory passes exactEndpoint to
keep the request on the base URL. "No suffix" without a base URL now fails
instead of falling back to the official endpoint with a gateway's key.
The model list sent the API key but completions did not, so an Ollama behind
an authenticating proxy listed models and then failed with HTTP 401 on
connection test and conversion. Send the header only when a key is set.

A custom-named Ollama provider matched no preset, so its model list went to
/models, which Ollama does not serve. Fall back to the Ollama preset (/tags
and the default base URL).
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.

服务商「无后缀」选项不生效;带 API Key 的 Ollama 补全请求未带 Bearer

1 participant