Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ func ConvertOpenAIRequestToClaude(modelName string, inputRawJSON []byte, stream
} else if contentResult.Exists() && contentResult.IsArray() {
contentResult.ForEach(func(_, part gjson.Result) bool {
if part.Get("type").String() == "text" {
textContent := part.Get("text").String()
if textContent == "" {
return true
}
textPart := `{"type":"text","text":""}`
textPart, _ = sjson.Set(textPart, "text", part.Get("text").String())
textPart, _ = sjson.Set(textPart, "text", textContent)
out, _ = sjson.SetRaw(out, fmt.Sprintf("messages.%d.content.-1", systemMessageIndex), textPart)
Comment on lines +159 to 165
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to handle empty text parts is duplicated for system messages here, and for user/assistant messages later in this file (lines 185-191). To improve maintainability, consider refactoring this into a helper function in a future change.

}
return true
Expand All @@ -178,8 +182,12 @@ func ConvertOpenAIRequestToClaude(modelName string, inputRawJSON []byte, stream

switch partType {
case "text":
textContent := part.Get("text").String()
if textContent == "" {
return true
}
textPart := `{"type":"text","text":""}`
textPart, _ = sjson.Set(textPart, "text", part.Get("text").String())
textPart, _ = sjson.Set(textPart, "text", textContent)
msg, _ = sjson.SetRaw(msg, "content.-1", textPart)

case "image_url":
Expand Down
Loading