fix: distill LLM 模型切换 gemma-4-31b-it + JSON 解析增强

根因链:
1. gpt-oss-120b 是 reasoning 模型,content=null 答案全在 reasoning 字段,
   代码只读 content/reasoning_content(OpenAI 用 reasoning 字段名)→ parse 失败
   → 永远降级 keyword 提取 (facts=1 entities=0)
2. skill 记载的 m3/m2.7/mistral-large 均已 EOL 或渠道失效 (2026-07-27 后)
3. gemma-4-31b-it 对 '0.X' 占位符输出 0.0 → prompt 改为明确 0-1 浮点说明

修复:
- engine.go: 支持 reasoning 字段 + 剥离 markdown code fence + prompt 评分说明明确化
- zhiyid.service: LLM_MODEL=google/gemma-4-31b-it

验证: LLM entities=2, overall=1.000, facts=3 entities=2, recall 命中 0.765
This commit is contained in:
xiaowei 2026-08-02 23:59:29 +08:00
parent 21bc777430
commit 98e541b985
1 changed files with 13 additions and 1 deletions

View File

@ -280,7 +280,8 @@ func (e *Engine) callLLM5D(content string) (LLMResponse, error) {
内容:
%s
只返回JSON: {"decisions": ["决定1", "决定2"], "conclusions": ["结论1"], "actions_taken": ["行动1"], "open_questions": ["问题1"], "entities": ["entity1", "entity2"], "is": 0.X, "su": 0.X, "pa": 0.X, "vd": 0.X, "ru": 0.X}`, truncate(content, 1000))
只返回JSON: {"decisions": ["决定1", "决定2"], "conclusions": ["结论1"], "actions_taken": ["行动1"], "open_questions": ["问题1"], "entities": ["entity1", "entity2"], "is": 0.8, "su": 0.7, "pa": 0.6, "vd": 0.9, "ru": 0.7}
评分说明is/su/pa/vd/ru 0.0 1.0 之间的浮点数越高越好不要用 0-10 整数`, truncate(content, 1000))
body := map[string]interface{}{
"model": e.LLMModel,
@ -318,6 +319,8 @@ func (e *Engine) callLLM5D(content string) (LLMResponse, error) {
Message struct {
Content string `json:"content"`
ReasoningContent string `json:"reasoning_content"`
// OpenAI 系 reasoning 模型gpt-oss 等)用 "reasoning" 字段,不是 "reasoning_content"
Reasoning string `json:"reasoning"`
} `json:"message"`
} `json:"choices"`
}
@ -335,6 +338,15 @@ func (e *Engine) callLLM5D(content string) (LLMResponse, error) {
if llmContent == "" {
llmContent = result.Choices[0].Message.ReasoningContent
}
if llmContent == "" {
llmContent = result.Choices[0].Message.Reasoning
}
// 剥离 markdown code fenceminimax 等模型习惯用 ```json 包裹)
llmContent = strings.TrimSpace(llmContent)
llmContent = strings.TrimPrefix(llmContent, "```json")
llmContent = strings.TrimPrefix(llmContent, "```")
llmContent = strings.TrimSuffix(llmContent, "```")
llmContent = strings.TrimSpace(llmContent)
if err := json.Unmarshal([]byte(llmContent), &llmResp); err != nil {
log.Printf("[distill] LLM JSON parse error: %v | content=%q", err, truncate(llmContent, 200))
return LLMResponse{}, fmt.Errorf("parse score: %w", err)