mirror of
https://github.com/alibaba/higress.git
synced 2026-04-21 20:17:29 +08:00
fix: Accommodate the incomplete function name in the initial event from Qwen (#1045)
This commit is contained in:
@@ -349,11 +349,19 @@ func (m *qwenProvider) buildChatCompletionStreamingResponse(ctx wrapper.HttpCont
|
|||||||
responses := make([]*chatCompletionResponse, 0)
|
responses := make([]*chatCompletionResponse, 0)
|
||||||
|
|
||||||
qwenChoice := qwenResponse.Output.Choices[0]
|
qwenChoice := qwenResponse.Output.Choices[0]
|
||||||
|
// Yes, Qwen uses a string "null" as null.
|
||||||
|
finished := qwenChoice.FinishReason != "" && qwenChoice.FinishReason != "null"
|
||||||
message := qwenChoice.Message
|
message := qwenChoice.Message
|
||||||
|
|
||||||
deltaContentMessage := &chatMessage{Role: message.Role, Content: message.Content}
|
deltaContentMessage := &chatMessage{Role: message.Role, Content: message.Content}
|
||||||
deltaToolCallsMessage := &chatMessage{Role: message.Role, ToolCalls: append([]toolCall{}, message.ToolCalls...)}
|
deltaToolCallsMessage := &chatMessage{Role: message.Role, ToolCalls: append([]toolCall{}, message.ToolCalls...)}
|
||||||
if !incrementalStreaming {
|
if !incrementalStreaming {
|
||||||
|
for _, tc := range message.ToolCalls {
|
||||||
|
if tc.Function.Arguments == "" && !finished {
|
||||||
|
// We don't push any tool call until its arguments are available.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
if pushedMessage, ok := ctx.GetContext(ctxKeyPushedMessage).(qwenMessage); ok {
|
if pushedMessage, ok := ctx.GetContext(ctxKeyPushedMessage).(qwenMessage); ok {
|
||||||
if message.Content == "" {
|
if message.Content == "" {
|
||||||
message.Content = pushedMessage.Content
|
message.Content = pushedMessage.Content
|
||||||
@@ -386,8 +394,7 @@ func (m *qwenProvider) buildChatCompletionStreamingResponse(ctx wrapper.HttpCont
|
|||||||
responses = append(responses, &response)
|
responses = append(responses, &response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes, Qwen uses a string "null" as null.
|
if finished {
|
||||||
if qwenChoice.FinishReason != "" && qwenChoice.FinishReason != "null" {
|
|
||||||
finishResponse := *&baseMessage
|
finishResponse := *&baseMessage
|
||||||
finishResponse.Choices = append(finishResponse.Choices, chatCompletionChoice{FinishReason: qwenChoice.FinishReason})
|
finishResponse.Choices = append(finishResponse.Choices, chatCompletionChoice{FinishReason: qwenChoice.FinishReason})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user