fix: normalize input_text content blocks in Claude-to-OpenAI conversion
Clients like OpenClaw send input_text content blocks (a Responses API type) through /v1/messages. The Claude-to-OpenAI converter silently drops unknown types, so the message arrives empty at the upstream, causing "Invalid value: 'input_text'" errors. Map input_text to text since they share the same structure.
This commit is contained in:
@@ -127,7 +127,7 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
|
|||||||
|
|
||||||
for _, mediaMsg := range contents {
|
for _, mediaMsg := range contents {
|
||||||
switch mediaMsg.Type {
|
switch mediaMsg.Type {
|
||||||
case "text":
|
case "text", "input_text":
|
||||||
message := dto.MediaContent{
|
message := dto.MediaContent{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: mediaMsg.GetText(),
|
Text: mediaMsg.GetText(),
|
||||||
|
|||||||
@@ -214,8 +214,12 @@ func ChatCompletionsRequestToResponsesRequest(req *dto.GeneralOpenAIRequest) (*d
|
|||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
switch part.Type {
|
switch part.Type {
|
||||||
case dto.ContentTypeText:
|
case dto.ContentTypeText:
|
||||||
|
textType := "input_text"
|
||||||
|
if role == "assistant" {
|
||||||
|
textType = "output_text"
|
||||||
|
}
|
||||||
contentParts = append(contentParts, map[string]any{
|
contentParts = append(contentParts, map[string]any{
|
||||||
"type": "input_text",
|
"type": textType,
|
||||||
"text": part.Text,
|
"text": part.Text,
|
||||||
})
|
})
|
||||||
case dto.ContentTypeImageURL:
|
case dto.ContentTypeImageURL:
|
||||||
|
|||||||
Reference in New Issue
Block a user