mirror of
https://github.com/alibaba/higress.git
synced 2026-03-01 15:10:56 +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)
|
||||
|
||||
qwenChoice := qwenResponse.Output.Choices[0]
|
||||
// Yes, Qwen uses a string "null" as null.
|
||||
finished := qwenChoice.FinishReason != "" && qwenChoice.FinishReason != "null"
|
||||
message := qwenChoice.Message
|
||||
|
||||
deltaContentMessage := &chatMessage{Role: message.Role, Content: message.Content}
|
||||
deltaToolCallsMessage := &chatMessage{Role: message.Role, ToolCalls: append([]toolCall{}, message.ToolCalls...)}
|
||||
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 message.Content == "" {
|
||||
message.Content = pushedMessage.Content
|
||||
@@ -386,8 +394,7 @@ func (m *qwenProvider) buildChatCompletionStreamingResponse(ctx wrapper.HttpCont
|
||||
responses = append(responses, &response)
|
||||
}
|
||||
|
||||
// Yes, Qwen uses a string "null" as null.
|
||||
if qwenChoice.FinishReason != "" && qwenChoice.FinishReason != "null" {
|
||||
if finished {
|
||||
finishResponse := *&baseMessage
|
||||
finishResponse.Choices = append(finishResponse.Choices, chatCompletionChoice{FinishReason: qwenChoice.FinishReason})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user