deduplicate think tag for bedrock and vertex (#2933)

This commit is contained in:
rinfx
2025-09-18 14:35:36 +08:00
committed by GitHub
parent caae3ee068
commit ef12f40c0e
2 changed files with 9 additions and 13 deletions

View File

@@ -35,11 +35,9 @@ const (
// converseStream路径 /model/{modelId}/converse-stream
bedrockStreamChatCompletionPath = "/model/%s/converse-stream"
// invoke_model 路径 /model/{modelId}/invoke
bedrockInvokeModelPath = "/model/%s/invoke"
bedrockSignedHeaders = "host;x-amz-date"
requestIdHeader = "X-Amzn-Requestid"
reasoningContextMarkerStart = "<think>"
reasoningContextMarkerEnd = "</think>"
bedrockInvokeModelPath = "/model/%s/invoke"
bedrockSignedHeaders = "host;x-amz-date"
requestIdHeader = "X-Amzn-Requestid"
)
type bedrockProviderInitializer struct{}
@@ -122,7 +120,7 @@ func (b *bedrockProvider) convertEventFromBedrockToOpenAI(ctx wrapper.HttpContex
if bedrockEvent.Delta.ReasoningContent != nil {
var content string
if ctx.GetContext("thinking_start") == nil {
content += reasoningContextMarkerStart
content += reasoningStartTag
ctx.SetContext("thinking_start", true)
}
content += bedrockEvent.Delta.ReasoningContent.Text
@@ -130,7 +128,7 @@ func (b *bedrockProvider) convertEventFromBedrockToOpenAI(ctx wrapper.HttpContex
} else if bedrockEvent.Delta.Text != nil {
var content string
if ctx.GetContext("thinking_start") != nil && ctx.GetContext("thinking_end") == nil {
content += reasoningContextMarkerEnd
content += reasoningEndTag
ctx.SetContext("thinking_end", true)
}
content += *bedrockEvent.Delta.Text
@@ -844,7 +842,7 @@ func (b *bedrockProvider) buildChatCompletionResponse(ctx wrapper.HttpContext, b
}
}
if reasoningContent != "" {
outputContent = reasoningContextMarkerStart + reasoningContent + reasoningContextMarkerEnd + normalContent
outputContent = reasoningStartTag + reasoningContent + reasoningEndTag + normalContent
} else {
outputContent = normalContent
}

View File

@@ -31,8 +31,6 @@ const (
vertexChatCompletionAction = "generateContent"
vertexChatCompletionStreamAction = "streamGenerateContent?alt=sse"
vertexEmbeddingAction = "predict"
reasoningContextMarkerStart = "<think>"
reasoningContextMarkerEnd = "</think>"
)
type vertexProviderInitializer struct{}
@@ -278,7 +276,7 @@ func (v *vertexProvider) buildChatCompletionResponse(ctx wrapper.HttpContext, re
},
}
} else if part.Thounght != nil && len(candidate.Content.Parts) > 1 {
choice.Message.Content = reasoningContextMarkerStart + part.Text + reasoningContextMarkerEnd + candidate.Content.Parts[1].Text
choice.Message.Content = reasoningStartTag + part.Text + reasoningEndTag + candidate.Content.Parts[1].Text
} else if part.Text != "" {
choice.Message.Content = part.Text
}
@@ -339,14 +337,14 @@ func (v *vertexProvider) buildChatCompletionStreamResponse(ctx wrapper.HttpConte
}
} else if part.Thounght != nil {
if ctx.GetContext("thinking_start") == nil {
choice.Delta = &chatMessage{Content: reasoningContextMarkerStart + part.Text}
choice.Delta = &chatMessage{Content: reasoningStartTag + part.Text}
ctx.SetContext("thinking_start", true)
} else {
choice.Delta = &chatMessage{Content: part.Text}
}
} else if part.Text != "" {
if ctx.GetContext("thinking_start") != nil && ctx.GetContext("thinking_end") == nil {
choice.Delta = &chatMessage{Content: reasoningContextMarkerEnd + part.Text}
choice.Delta = &chatMessage{Content: reasoningEndTag + part.Text}
ctx.SetContext("thinking_end", true)
} else {
choice.Delta = &chatMessage{Content: part.Text}