fix(translator): handle stop_reason and MAX_TOKENS for Claude responses

This commit is contained in:
Luis Pater
2026-01-31 04:03:01 +08:00
parent f887f9985d
commit f99cddf97f
3 changed files with 8 additions and 1 deletions

View File

@@ -251,6 +251,8 @@ func ConvertGeminiResponseToClaude(_ context.Context, _ string, originalRequestR
template := `{"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
if usedTool {
template = `{"type":"message_delta","delta":{"stop_reason":"tool_use","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
} else if finish := gjson.GetBytes(rawJSON, "candidates.0.finishReason"); finish.Exists() && finish.String() == "MAX_TOKENS" {
template = `{"type":"message_delta","delta":{"stop_reason":"max_tokens","stop_sequence":null},"usage":{"input_tokens":0,"output_tokens":0}}`
}
thoughtsTokenCount := usageResult.Get("thoughtsTokenCount").Int()