使用 OpenCode 调用 V2EX AI API 的配置文件例子

8 月 30 日
 Livid

之前的 OpenCode 配置例子帖子中的配置文件非常 bare bone:

https://edge.v2ex.com/t/1227634

所以其实很多 OpenCode 的额外功能会因此没有打开。

这里是一个我目前测试过的更完整的配置文件例子:

文件位置 ~/.config/opencode/opencode.jsonc

内容是目前 V2EX 上能够提供的 3 个 GLM 模型及其能力,其中 GLM 5.3 Flash 能支持图片。

{
  "$schema": "https://opencode.ai/config.json",
  "disabled_providers": [],
  "provider": {
    "v2ex": {
      "name": "v2ex",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://edge.v2ex.com/chat/v1"
      },
      "models": {
        "coder": {
          "name": "GLM-5.2",
          "reasoning": true,
          "temperature": true,
          "interleaved": { "field": "reasoning_content" },
          "limit": { "context": 1000000, "output": 131072 },
          "modalities": { "input": ["text"], "output": ["text"] },
          "cost": { "input": 1.4, "output": 4.4, "cache_read": 0.26, "cache_write": 0 },
          "variants": {
            "high": { "reasoningEffort": "high" },
            "max": { "reasoningEffort": "max" }
          }
        },
        "glm-5.3": {
          "name": "GLM-5.3",
          "reasoning": true,
          "temperature": true,
          "interleaved": { "field": "reasoning_content" },
          "limit": { "context": 1048576, "output": 131072 },
          "modalities": { "input": ["text"], "output": ["text"] },
          "cost": { "input": 1.4, "output": 4.4, "cache_read": 0.26, "cache_write": 0 },
          "variants": {
            "low": { "reasoningEffort": "low" },
            "high": { "reasoningEffort": "high" },
            "max": { "reasoningEffort": "max" }
          }
        },
        "glm-5.3-flash": {
          "name": "GLM-5.3-Flash",
          "attachment": true,
          "reasoning": true,
          "temperature": true,
          "interleaved": { "field": "reasoning_content" },
          "limit": { "context": 1048576, "output": 131072 },
          "modalities": { "input": ["text", "image"], "output": ["text"] },
          "cost": { "input": 0.075, "output": 0.25, "cache_read": 0.015, "cache_write": 0 },
          "variants": {
            "low": { "reasoningEffort": "low" },
            "high": { "reasoningEffort": "high" },
            "max": { "reasoningEffort": "max" }
          }
        }
      }
    }
  }
}

这样配置之后,除了可以看到思考过程,还可以看到 context 占用和费用预估(如果是使用类似官方 API 的话)。

2265 次点击
所在节点    Wunder
2 条回复
chanssl
8 月 30 日
感谢 Livid
waytin
8 月 30 日
普通账号现在能有多少额度呀

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1238187

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX