Skip to content

Commit

Permalink
chore: remove messages hacks for external providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed May 28, 2024
1 parent 9291758 commit e65513e
Showing 1 changed file with 1 addition and 20 deletions.
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

0 comments on commit e65513e

Please sign in to comment.