Skip to content

feat: Add max_tokens for chat completion requests #50

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
Mar 5, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions async-openai/src/types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ pub struct CreateChatCompletionRequest {
/// The messages to generate chat completions for, in the [chat format](https://platform.openai.com/docs/guides/chat/introduction).
pub messages: Vec<ChatCompletionRequestMessage>, // min: 1

/// The maximum number of [tokens](/tokenizer) to generate in the completion.
///
/// The token count of your prompt plus `max_tokens` cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tokens: Option<u16>,

/// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
///
/// We generally recommend altering this or `top_p` but not both.
Expand Down
1 change: 1 addition & 0 deletions examples/chat-stream/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let request = CreateChatCompletionRequestArgs::default()
.model("gpt-3.5-turbo")
.max_tokens(1024u16)
.messages([ChatCompletionRequestMessageArgs::default()
.content("write a song if Coldplay and AR Rahman collaborated together")
.role(Role::User)
Expand Down
1 change: 1 addition & 0 deletions examples/chat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::new();

let request = CreateChatCompletionRequestArgs::default()
.max_tokens(512u16)
.model("gpt-3.5-turbo")
.messages([
ChatCompletionRequestMessageArgs::default()
Expand Down