LinSoap

LinSoap

Null
github
x

VSCode Copilot 配置自訂模型(GLM為例)

在訂閱智譜的 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

圖片

所以這個方法也可供大家使用參考。反正我是沒能成功配置。

參考連結#

  1. https://docs.bigmodel.cn/cn/coding-plan/tool/others
  2. https://code.visualstudio.com/docs/copilot/customization/language-models
  3. https://github.com/doggy8088/github-copilot-configs/issues/43
  4. https://github.com/microsoft/vscode-copilot-chat/pull/621
  5. https://github.com/microsoft/vscode-copilot-release/issues/7518#issuecomment-3294489890
  6. https://code.visualstudio.com/api/extension-guides/ai/language-model-chat-provider#overview
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。