-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add support for the latest OpenAI chat models (e.g., o1, gpt-4o) for completions. #3628
base: main
Are you sure you want to change the base?
Conversation
…4o-mini while doing completion
struct CompletionRequest { | ||
model: String, | ||
prompt: String, | ||
|
||
#[serde(skip_serializing_if = "Option::is_none")] |
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.
prompt
and messages
fields are not allowed at the same time even with the empty value.
max_tokens: i32, | ||
temperature: f32, | ||
stream: bool, | ||
presence_penalty: f32, | ||
|
||
#[serde(skip_serializing_if = "Vec::is_empty")] | ||
messages: Vec<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.
ditto
struct CompletionResponseChoice { | ||
text: String, | ||
text: Option<String>, | ||
delta: Option<CompletionResponseDelta>, |
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.
FYI: offical api docs:
https://platform.openai.com/docs/api-reference/chat/streaming
} else { | ||
(prompt, None) | ||
}; | ||
const LEGACY_MODEL_NAME: &str = "gpt-3.5-turbo-instruct"; |
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.
At the moment, this is the only one I knew.
stream: true, | ||
presence_penalty: options.presence_penalty, | ||
..Default::default() |
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.
other fields will be filled later according to the self.model_name
(prompt, None) | ||
}; | ||
request.prompt = Some(prompt.into()); | ||
request.suffix = suffix.map(Into::into); |
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.
For other fields marked as #[serde(skip_serializing_if = "Option::is_none")]
, will be ignored while serializing to json otherwise openai server would complain about the extra fields.
|
||
request.messages = vec![Message { | ||
role: "user".to_string(), | ||
content: format!("{SYS_PMT}\n{prompt}"), |
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.
ditto
Add Support for Latest OpenAI Chat Models (e.g., o1, gpt-4o) for Completions
Overview
The current implementation in
crates/http-api-bindings/src/completion/openai.rs
exclusively supports the legacy completion modelgpt-3.5-turbo-instruct
. This model has been marked as legacy in OpenAI's API documentation, as illustrated below:This pull request introduces support for the latest OpenAI chat models (e.g.,
o1
,gpt-4o
) for completions while retaining compatibility with the legacygpt-3.5-turbo-instruct
model.Changes
o1
andgpt-4o
.gpt-3.5-turbo-instruct
completion model.Configuration
Below is an example of the
config.toml
used during testing: