先記錄我原先使用的 llama.cpp 版本
C:\> llama-cli --version
version: 9947 (3de7dd4c8)
built with Clang 20.1.8 for Windows x86_64
C:\> llama --version
b9947-3de7dd4c8
這個版本的 llama.cpp,OpenCode 會出現以下錯誤訊息
Error: Unable to generate parser for this template. Automatic parser generation failed: JSON schema conversion failed: Pattern must start with '^' and end with '$'
而我的 %USERPROFILE%\.config\opencode\opencode.json
內容如下
{
"$schema" : "https://opencode.ai/config.json",
"provider": {
"llama": {
"npm" : "@ai-sdk/openai-compatible",
"name" : "llama.cpp (local)",
"options": {"baseURL": "http://127.0.0.1:11030/v1"},
"models" : {
"Qwen/Qwen2.5-Coder-3B-Instruct-GGUF:Q5_K_M": {
"name" : "Qwen2.5-3b-Q5_K_M(local)",
"variant": "low",
"limit" : {"context": 8192, "output": 2048}
}
}
}
}
}
經過查詢, llama.cpp 有相關的 issue 在討論此問題
- #26930 json-schema-to-grammar: valid unanchored pattern is rejected, failing the entire tool-calling request
- #27580 json_schema_to_grammar: regex shorthand classes (\d, \w, \s) in “pattern” are copied verbatim into GBNF, producing an unparseable grammar with no error
這 issue 是在討論 llama 不接受未加錨點的 pattern。例如 "\S" 是合法的 JSON Schema pattern,但 llama.cpp 會要求它以 ^ 開頭、以 $ 結尾。
而這問題在更新的版本就有修正了
我將我的 llama.cpp 更新到新版本(b11774)就解決了
參考資料
- OpenCode 的 Models說明文件
- ChatGPT 的對話
沒有留言:
張貼留言