Opencode簡(jiǎn)介
OpenCode 是一個(gè)開(kāi)源的 AI 編程代理(AI coding agent),旨在幫助開(kāi)發(fā)者在終端、桌面或 IDE 中更高效地編寫(xiě)、調試和重構代碼。支持對接主流的大模型廠(chǎng)商,比如智谷API、DeepSeek等。
但是在某些場(chǎng)景下我們可能需要在內網(wǎng)搭建自己的模型,所以需要使用Opencode對接屬于自己的大模型。
步驟
1、安裝LM Studio
在LM Studio官網(wǎng)中下載屬于自己平臺的LM Studio,并且安裝,當前不做詳細描述。
安裝好之后在點(diǎn)擊Server,選擇Local Server,打開(kāi)Local Server

可以在Server Settings中看到當前server監聽(tīng)的端口:http://127.0.0.1:1234
本地模型可以從https://huggingface.co/models?num_parameters=min:0,max:9B&apps=lmstudio&sort=trending&search=GPT-5中下載。
2、OpenCode對接LM Studio
在當前用戶(hù)的.config\opencode下面新建opencode.json中新增下面配置:
{
"$schema": "https://opencode.ai/config.json",
"disabled_providers": [
"lm_studio_local"
],
"provider": {
"lm_studio": {
"name": "lm studio",
"npm": "@ai-sdk/openai-compatible",
"models": {
"lfm2.5-1.2b-glm-4.7-flash-thinking@q6_k": {
"name": "lfm2.5-1.2b-glm-4.7-flash-thinking"
},
"glm4.7-distill-lfm2.5-1.2b-i1": {
"name": "glm4.7-distill-lfm2.5-1.2b-i1"
}
},
"options": {
"baseURL": "http://localhost:1234/v1"
}
}
}
}
重啟opencode可以看到自定義的模型了。