mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 22:27:29 +08:00
Fix/claude thinking tool call conversion (#3756)
Signed-off-by: wydream <yaodiwu618@gmail.com>
This commit is contained in:
@@ -174,7 +174,15 @@ func mergeConsecutiveMessages(body []byte) ([]byte, error) {
|
||||
result[len(result)-1].Role == msg.Role &&
|
||||
(msg.Role == roleUser || msg.Role == roleAssistant) {
|
||||
last := &result[len(result)-1]
|
||||
if msg.Role == roleAssistant &&
|
||||
(len(last.ToolCalls) > 0 || len(msg.ToolCalls) > 0 || last.FunctionCall != nil || msg.FunctionCall != nil) {
|
||||
// Assistant tool-calling turns are structurally sensitive. Keep them split
|
||||
// rather than trying to merge content/reasoning and risking dropped calls.
|
||||
result = append(result, msg)
|
||||
continue
|
||||
}
|
||||
last.Content = mergeMessageContent(last.Content, msg.Content)
|
||||
last.ReasoningContent = mergeReasoningContent(last.ReasoningContent, msg.ReasoningContent)
|
||||
merged = true
|
||||
continue
|
||||
}
|
||||
@@ -202,6 +210,17 @@ func mergeMessageContent(prev, curr any) any {
|
||||
return append(prevParts, currParts...)
|
||||
}
|
||||
|
||||
func mergeReasoningContent(prev, curr string) string {
|
||||
switch {
|
||||
case prev == "":
|
||||
return curr
|
||||
case curr == "":
|
||||
return prev
|
||||
default:
|
||||
return prev + "\n\n" + curr
|
||||
}
|
||||
}
|
||||
|
||||
func ReplaceResponseBody(body []byte) error {
|
||||
log.Debugf("response body: %s", string(body))
|
||||
err := proxywasm.ReplaceHttpResponseBody(body)
|
||||
|
||||
Reference in New Issue
Block a user