support o1 models not allowing system prompts

This commit is contained in:
Steve Dudenhoeffer 2024-10-31 11:21:03 -04:00
parent c4f4f6abe6
commit f603010dee

View File

@ -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
}