From f603010dee49b4d423dbaca152ae37b05f7c4090 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Thu, 31 Oct 2024 11:21:03 -0400 Subject: [PATCH] support o1 models not allowing system prompts --- openai.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 }