-
Notifications
You must be signed in to change notification settings - Fork 140
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
Fix Perplexity API Role Compatibility (Issue #448) #454
Fix Perplexity API Role Compatibility (Issue #448) #454
Conversation
stream.go
Outdated
messages := m.messages | ||
if mod.Name == "o1-preview" || mod.Name == "o1-mini" { | ||
messages = []openai.ChatCompletionMessage{} | ||
for _, message := range m.messages { | ||
if message.Role == openai.ChatMessageRoleSystem { | ||
messages = append(messages, openai.ChatCompletionMessage{ | ||
Role: openai.ChatMessageRoleUser, | ||
Content: message.Content, | ||
}) | ||
} else { | ||
messages = append(messages, message) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could probably simplify this to something like:
if mod.Name == "o1-preview" || mod.Name == "o1-mini" {
for i := range m.messages {
if message.Role != openai.ChatMessageRoleSystem {
continue
}
m.messages[i].Role = openai.ChatMessageRoleUser
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah you're right, simplified it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR!
made one one small suggestion
thanks! |
Fix Perplexity API Role Compatibility (Issue #448)
This fix maintains compatibility with legacy o1 models while solving the Perplexity error.
The Problem
A previous update (commit e5e4bdd) added support for o1-preview and o1-mini models by converting system messages to user messages. However, this breaks Perplexity models because their API doesn't allow multiple consecutive messages with the same role.
How to See the Issue
Try this command and you'll see an error:
Solution
createOpenAIStream (stream.go)
Note
The system message remapping is not needed for these models, which handle system messages correctly without modification: