Skip to content

Commit 04d27bc

Browse files
committed
fix(anthropic): 增强聊天适配器的输出逻辑,添加推理结果处理
- 在 Chat 方法中添加对 ThinkingDelta 的处理,确保推理过程中的输出能够正确发送。 - 优化错误处理逻辑,仅在有实际内容时发送输出块,提升代码的健壮性和可读性。
1 parent ba6982f commit 04d27bc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pkg/llminterface/anthropic/anthropic.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ func (a *AnthropicAdapter) Chat(ctx context.Context, input llminterface.ChatInpu
142142
},
143143
}
144144
outputChan <- chunk
145-
145+
case anthropic.ThinkingDelta:
146+
chunk := llminterface.ChatOutputChunk{
147+
Reasoning: Some(deltaVariant.JSON.Thinking.Raw()),
148+
}
149+
outputChan <- chunk
146150
case anthropic.InputJSONDelta:
147151
// 工具调用参数增量
148152
currentToolArgs.WriteString(deltaVariant.PartialJSON)
@@ -190,7 +194,11 @@ func (a *AnthropicAdapter) Chat(ctx context.Context, input llminterface.ChatInpu
190194
chunk := llminterface.ChatOutputChunk{
191195
Error: stream.Err(),
192196
}
193-
outputChan <- chunk
197+
198+
// 只有当有实际内容时才发送 chunk
199+
if len(chunk.ContentParts) > 0 || chunk.Reasoning.IsSome() {
200+
outputChan <- chunk
201+
}
194202
}
195203
}()
196204

0 commit comments

Comments
 (0)