在订阅智谱的 Coding 套餐后,抱着一种多用一点多赚一点的心态,在自己用的 Chatbox,Cli 工具上都用上了智谱的模型,最近还添加了 4.6 的模型,那更得多用用了。打算把 copilot 也配上,但是 VSCode 这玩意添加 OAIModels 的功能还在实验阶段,添加模型还是遇到了不少坑。
要使用上自定义模型,我一共找到有两种方法,一个是社区插件,一个是 CustomOAIModels 配置参数。但是我只有社区的方法成功了,CostomOAIModels 参数无法显示添加的模型和配置 apikey。
方法 1: 安装插件#
这个插件是我在仓库的 issue 中,有人自行推荐的插件。
issue 地址
Add custom OpenAI endpoint configuration (Base URL & Model Parameter) of copilot chat settings #7518
插件地址
OAI Compatible Provider for Copilot
在 vscode 插件商场下载这个插件后,点击插件配置,跳转到 json 配置页面,添加以下内容。
"oaicopilot.baseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
"oaicopilot.models": [
{
"id": "glm-4.6",
"owned_by": "zhipuai",
"context_length": 200000,
"max_tokens": 132000,
},
{
"id": "glm-4.5",
"owned_by": "zhipuai",
"context_length": 128000,
"max_tokens": 96000,
},
{
"id": "glm-4.5-air",
"owned_by": "zhipuai",
"context_length": 128000,
"max_tokens": 96000,
},
]
更多配置请查看仓库。
在完成配置设定后,使用 ctrl+shift+p,打开管理模型配置页面。
选择 OAI Compatible,填入 apikey,勾选需要使用的模型即可。
最后在对话框中就能看见添加的模型,使用其他模型供应商逻辑也相同。
方法 2: CustomOAIModels 配置#
这个配置方法是在 copilot 仓库中的一个 pr 提出的,但是我配置后,始终无法在对话框中找到新添加的模型,也无法配置我的 apikey,CustomOAIModels 在配置中显示是实验性功能,所以能不能用确实随缘吧。
Add support for generic OAI endpoints #621
配置方式是在 vscode 的 setting.json 中添加上述配置,例如
"github.copilot.chat.customOAIModels": {
"gpt-4.1": {
"name": "GPT-4.1 Custom",
"maxInputTokens": 64768,
"maxOutputTokens": 16192,
"toolCalling": true,
"url": "https://api.openai.com/v1/chat/completions",
"vision": true,
"requiresAPIKey": true
},
"openai/gpt-oss-20b": {
"name": "GPT-OSS-20B",
"maxInputTokens": 32768,
"maxOutputTokens": 8192,
"toolCalling": false,
"url": "http://127.0.0.1:1234/v1/chat/completions",
"vision": false,
"requiresAPIKey": false
}
}
也有一个老哥的 copilot 仓库提到了这个方法,所以说不定也能行得通。
加入 github.copilot.chat.customOAIModels 組態說明 #43
同样,官方文档也提到了这个方法。
AI language models in VS Code
所以这个方法也可供大家使用参考。反正我是没能成功配置。
参考连接#
- https://docs.bigmodel.cn/cn/coding-plan/tool/others
- https://code.visualstudio.com/docs/copilot/customization/language-models
- https://github.com/doggy8088/github-copilot-configs/issues/43
- https://github.com/microsoft/vscode-copilot-chat/pull/621
- https://github.com/microsoft/vscode-copilot-release/issues/7518#issuecomment-3294489890
- https://code.visualstudio.com/api/extension-guides/ai/language-model-chat-provider#overview