diff --git a/internal/translator/gemini-cli/openai/cli_openai_request.go b/internal/translator/gemini-cli/openai/cli_openai_request.go index fd7fe136..c7c2ecee 100644 --- a/internal/translator/gemini-cli/openai/cli_openai_request.go +++ b/internal/translator/gemini-cli/openai/cli_openai_request.go @@ -94,9 +94,10 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c continue } - switch roleResult.String() { - // System messages are converted to a user message followed by a model's acknowledgment. - case "system": + role := roleResult.String() + + if role == "system" && len(messagesResults) > 1 { + // System messages are converted to a user message followed by a model's acknowledgment. if contentResult.Type == gjson.String { systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}} } else if contentResult.IsObject() { @@ -105,8 +106,8 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c systemInstruction = &client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.Get("text").String()}}} } } - // User messages can contain simple text or a multi-part body. - case "user": + } else if role == "user" || (role == "system" && len(messagesResults) == 1) { // If there's only a system message, treat it as a user message. + // User messages can contain simple text or a multi-part body. if contentResult.Type == gjson.String { contents = append(contents, client.Content{Role: "user", Parts: []client.Part{{Text: contentResult.String()}}}) } else if contentResult.IsArray() { @@ -151,9 +152,10 @@ func ConvertOpenAIChatRequestToCli(rawJSON []byte) (string, *client.Content, []c } contents = append(contents, client.Content{Role: "user", Parts: parts}) } - // Assistant messages can contain text responses or tool calls - // In the internal format, assistant messages are converted to "model" role - case "assistant": + } else if role == "assistant" { + // Assistant messages can contain text responses or tool calls + // In the internal format, assistant messages are converted to "model" role + if contentResult.Type == gjson.String { // Simple text response from the assistant contents = append(contents, client.Content{Role: "model", Parts: []client.Part{{Text: contentResult.String()}}})