Skip to content

chore: remove messages hacks for external providers #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func toMessages(request types.CompletionRequest, compat bool) (result []openai.C
msgs []types.CompletionMessage
)

if request.InternalSystemPrompt == nil || *request.InternalSystemPrompt {
if !compat && (request.InternalSystemPrompt == nil || *request.InternalSystemPrompt) {
systemPrompts = append(systemPrompts, system.InternalSystemPrompt)
}

Expand All @@ -236,25 +236,6 @@ func toMessages(request types.CompletionRequest, compat bool) (result []openai.C
})
}

if compat {
// This is terrible hack to deal with APIs that strictly want: (system, user | user) (assistant, user)* assistant?
// Two scenarios where this breaks with GPTScript is just sending system, or sending system, assistant

// Don't send just a system message
if len(msgs) == 1 && msgs[0].Role == types.CompletionMessageRoleTypeSystem {
msgs[0].Role = types.CompletionMessageRoleTypeUser
}

// Don't send system, assistant. If so, insert a user message that just has "."
if len(msgs) > 1 && msgs[0].Role == types.CompletionMessageRoleTypeSystem &&
msgs[1].Role == types.CompletionMessageRoleTypeAssistant {
msgs = slices.Insert(msgs, 1, types.CompletionMessage{
Role: types.CompletionMessageRoleTypeUser,
Content: types.Text("."),
})
}
}

for _, message := range msgs {
chatMessage := openai.ChatCompletionMessage{
Role: string(message.Role),
Expand Down