mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 22:27:29 +08:00
fix(ai-proxy): fix gemini provider missing finishReason (#2408)
Signed-off-by: Xijun Dai <daixijun1990@gmail.com> Co-authored-by: Se7en <chengzw258@163.com>
This commit is contained in:
@@ -524,7 +524,7 @@ func (g *geminiProvider) buildChatCompletionResponse(ctx wrapper.HttpContext, re
|
|||||||
choice.Message.Content = part.Text
|
choice.Message.Content = part.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
choice.FinishReason = util.Ptr(candidate.FinishReason)
|
choice.FinishReason = util.Ptr(strings.ToLower(candidate.FinishReason))
|
||||||
fullTextResponse.Choices = append(fullTextResponse.Choices, choice)
|
fullTextResponse.Choices = append(fullTextResponse.Choices, choice)
|
||||||
choiceIndex += 1
|
choiceIndex += 1
|
||||||
}
|
}
|
||||||
@@ -560,6 +560,9 @@ func (g *geminiProvider) buildChatCompletionStreamResponse(ctx wrapper.HttpConte
|
|||||||
var choice chatCompletionChoice
|
var choice chatCompletionChoice
|
||||||
if len(geminiResp.Candidates) > 0 && len(geminiResp.Candidates[0].Content.Parts) > 0 {
|
if len(geminiResp.Candidates) > 0 && len(geminiResp.Candidates[0].Content.Parts) > 0 {
|
||||||
choice.Delta = &chatMessage{Content: geminiResp.Candidates[0].Content.Parts[0].Text}
|
choice.Delta = &chatMessage{Content: geminiResp.Candidates[0].Content.Parts[0].Text}
|
||||||
|
if geminiResp.Candidates[0].FinishReason != "" {
|
||||||
|
choice.FinishReason = util.Ptr(strings.ToLower(geminiResp.Candidates[0].FinishReason))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
streamResponse := chatCompletionResponse{
|
streamResponse := chatCompletionResponse{
|
||||||
Id: fmt.Sprintf("chatcmpl-%s", uuid.New().String()),
|
Id: fmt.Sprintf("chatcmpl-%s", uuid.New().String()),
|
||||||
|
|||||||
Reference in New Issue
Block a user