diff --git a/openai.go b/openai.go index caed728..6f1909d 100644 --- a/openai.go +++ b/openai.go @@ -4,6 +4,7 @@ import ( "context" "fmt" oai "github.com/sashabaranov/go-openai" + "strings" ) type openai struct { @@ -72,6 +73,20 @@ func (o openai) requestToOpenAIRequest(request Request) oai.ChatCompletionReques res.Temperature = *request.Temperature } + // is this an o1-* model? + isO1 := strings.Split(o.model, "-")[0] == "o1" + + if isO1 { + // o1 models do not support system messages, so if any messages are system messages, we need to convert them to + // user messages + + for i, msg := range res.Messages { + if msg.Role == "system" { + res.Messages[i].Role = "user" + } + } + } + return res }