mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-17 11:07:11 +08:00
Adds first-class support for configuring more than one custom OpenAI-compatible provider (e.g. SiliconFlow, DeepSeek, local vLLM) and switching the active one from the web console, addressing #2838. Backend: - config: new `custom_providers` (list) and `custom_active_provider` fields, fully backward compatible with the legacy single `open_ai_api_base`/`model` fields (used as fallback). - models/custom_provider.py: centralized resolver `resolve_custom_credentials()` returning (api_key, api_base, model), with active-provider selection and graceful fallback. - chat_gpt_bot.py wired to use the resolver. - web_channel.py: `_provider_overview` expands `custom_providers` into one card per provider (id `custom:<name>`, active flag, masked key); new POST actions `set_custom_provider`, `delete_custom_provider`, `set_active_custom_provider` with hermetic persistence + bridge reset. Frontend: - console.js: dedicated "Custom providers" section with add / edit / delete / set-active actions, masked-key keep-existing handling, and ~20 new zh/en i18n strings. - chat.html: custom provider modal. Tests: - tests/test_custom_provider.py (11) - resolver/config behavior. - tests/test_custom_provider_handlers.py (18) - write-side handlers and overview expansion, including duplicate-name rejection. All 29 unit tests pass.
97 lines
2.8 KiB
Plaintext
97 lines
2.8 KiB
Plaintext
---
|
||
title: 自定义
|
||
description: 自定义厂商配置,适用于第三方 API 代理和本地模型
|
||
---
|
||
|
||
适用于通过 OpenAI 兼容协议接入的第三方模型服务或本地部署的模型,例如:
|
||
|
||
- **第三方 API 代理**:使用统一的 API Base 调用多种模型
|
||
- **本地模型**:通过 Ollama、vLLM、LocalAI 等工具在本地部署的模型
|
||
- **私有化部署**:企业内部部署的模型服务
|
||
|
||
<Note>
|
||
与 `openai` 厂商的区别:选择自定义厂商后,通过 `/config model` 切换模型时,不会自动切换厂商类型,始终使用自定义的 API 地址。
|
||
</Note>
|
||
|
||
## 文本对话
|
||
|
||
### 第三方 API 代理
|
||
|
||
```json
|
||
{
|
||
"bot_type": "custom",
|
||
"model": "",
|
||
"custom_api_key": "YOUR_API_KEY",
|
||
"custom_api_base": "https://{your-proxy.com}/v1"
|
||
}
|
||
```
|
||
|
||
| 参数 | 说明 |
|
||
| --- | --- |
|
||
| `bot_type` | 必须设为 `custom` |
|
||
| `model` | 模型名称,填写代理服务支持的任意模型名 |
|
||
| `custom_api_key` | API 密钥,由代理服务提供 |
|
||
| `custom_api_base` | API 地址,由代理服务提供,需兼容 OpenAI 协议 |
|
||
|
||
### 本地模型
|
||
|
||
本地模型通常不需要 API Key,只需填写 API Base:
|
||
|
||
```json
|
||
{
|
||
"bot_type": "custom",
|
||
"model": "qwen3.5:27b",
|
||
"custom_api_base": "http://localhost:11434/v1"
|
||
}
|
||
```
|
||
|
||
常见的本地部署工具及默认地址:
|
||
|
||
| 工具 | 默认 API Base |
|
||
| --- | --- |
|
||
| [Ollama](https://ollama.com) | `http://localhost:11434/v1` |
|
||
| [vLLM](https://docs.vllm.ai) | `http://localhost:8000/v1` |
|
||
| [LocalAI](https://localai.io) | `http://localhost:8080/v1` |
|
||
|
||
### 切换模型
|
||
|
||
自定义厂商下切换模型时,只会修改 `model`,不会改变 `bot_type` 和 API 地址:
|
||
|
||
```
|
||
/config model qwen3.5:27b
|
||
```
|
||
|
||
## 配置多个自定义厂商
|
||
|
||
如果需要同时配置多个第三方 OpenAI 兼容服务(例如硅基流动、七牛云等),可以使用 `custom_providers` 列表,并通过 `custom_active_provider` 指定当前生效的厂商:
|
||
|
||
```json
|
||
{
|
||
"bot_type": "custom",
|
||
"custom_active_provider": "siliconflow",
|
||
"custom_providers": [
|
||
{
|
||
"name": "siliconflow",
|
||
"api_key": "YOUR_SILICONFLOW_KEY",
|
||
"api_base": "https://api.siliconflow.cn/v1",
|
||
"model": "deepseek-ai/DeepSeek-V3"
|
||
},
|
||
{
|
||
"name": "qiniu",
|
||
"api_key": "YOUR_QINIU_KEY",
|
||
"api_base": "https://api.qnaigc.com/v1",
|
||
"model": "deepseek-v3"
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
| 参数 | 说明 |
|
||
| --- | --- |
|
||
| `custom_providers` | 自定义厂商列表,每项包含 `name`、`api_key`、`api_base`、可选的 `model` |
|
||
| `custom_active_provider` | 当前生效厂商的 `name`;留空时默认使用列表中的第一个厂商 |
|
||
|
||
<Note>
|
||
当 `custom_providers` 为空时,将自动回退到上文的 `custom_api_key` / `custom_api_base` 单厂商配置,已有配置无需改动即可正常工作。
|
||
</Note>
|