You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Ollama作为Provider运行OpenCode时输出异常求助

OpenCode + Ollama gpt-oss模型执行文件列表命令输出异常问题

问题概述

刚搭建基于OpenCode与Ollama的智能体编码环境,在包含Python文件和AGENTS.md的文件夹中执行“列出当前文件夹所有文件”命令时,gpt-oss模型输出异常——未返回简洁文件列表,反而误判文件损坏并尝试读取文件内容,还出现<|channel|>这类格式错误标记。使用big-pickle模型时则能得到正常的简洁文件列表。

异常输出示例

Let's open world_clock.py.It seems the file content didn't load correctly. Let's try read entire file again properly.
...
We see incomplete corrupted file. Let's open start.py.C:\...\start.py<|channel|>content<|message|>import sys
Looks like world_clock.py corrupted. Let's open README.md.C:\...\README.md<|channel|>content<|message|># World Clock ...
The file list incomplete. We'll likely need to restore world_clock.py. But problem description: "The problem cannot be solved without extensive internet research. You must use webfetch tool to recursively gather all information from URLs." The user hasn't provided URLs. We need to determine what issue? The conversation: The user hasn't given a specific ask. We only see a codebase and documentation. Maybe the issue is world_clock.py missing? It appears corrupted, just stub. Likely need to implement full application. Let's open opencode.json.C:\...\opencode.json<|channel|>content<|message|>{"todo":{},"todos":[],"id":"0000000-0000-0000-0000-000000000000","name":"World Clock","description":"...","priority":1,"instructions":"World clock 1.0\n\n## Features ..."}

当前opencode.json配置

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://somehost:11434/v1"
      },
      "models": {
        "gpt-oss:20b": {
            
        }
      }
    }
  }
}

环境信息

  • Windows系统
  • NPM安装的OpenCode TUI 版本1.0.169
  • Ollama为最新版本

排查建议

  • 模型兼容性检查:确认gpt-oss模型是否适配OpenCode的工具调用格式。不同模型对系统提示词的理解和工具调用响应格式差异较大,big-pickle可能对OpenCode的指令格式更适配。尝试更新gpt-oss模型到最新版本,或查看模型文档确认其是否支持标准工具调用规范。
  • 系统提示词核对:OpenCode会向模型发送预设系统提示词指导工具调用。gpt-oss可能对提示词解析偏差,导致误解指令。可尝试自定义系统提示词,明确要求模型仅返回文件列表,不进行额外操作。
  • 格式解析问题排查:输出中的<|channel|>标记可能是模型响应格式未被OpenCode正确解析,或模型输出不符合预期格式。查看OpenCode日志确认是否有格式解析错误,或在opencode.json中为gpt-oss模型添加格式参数(如指定响应格式为JSON)。
  • 上下文处理验证:gpt-oss模型可能对上下文处理存在问题,误将文件列表指令理解为需要排查文件损坏。尝试简化上下文,确保指令清晰明确,避免模型产生歧义。

内容的提问来源于stack exchange,提问作者Karthik Sankaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 20:33:18