From 88fbf89a630b08171a40337392b76c2859043d54 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Tue, 18 Mar 2025 01:01:46 -0400 Subject: [PATCH] Fix handling of OpenAI messages with content and multi-content. Previously, OpenAI messages containing both `Content` and `MultiContent` could cause inconsistent behavior. This update ensures `Content` is converted into a `MultiContent` entry to maintain compatibility. --- llm.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/llm.go b/llm.go index a0e4cd1..058a479 100644 --- a/llm.go +++ b/llm.go @@ -106,6 +106,15 @@ func (m Message) toChatCompletionMessages() []openai.ChatCompletionMessage { } } + // openai does not support messages with both content and multi-content + if len(res.MultiContent) > 0 && res.Content != "" { + res.MultiContent = append([]openai.ChatMessagePart{{ + Type: "text", + Text: res.Content, + }}, res.MultiContent...) + res.Content = "" + } + return []openai.ChatCompletionMessage{res} }