Struct openai_rust::chat::ChatArguments
source · pub struct ChatArguments {
pub model: String,
pub messages: Vec<Message>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub n: Option<u32>,
pub stream: Option<bool>,
pub stop: Option<String>,
pub max_tokens: Option<u32>,
pub presence_penalty: Option<f32>,
pub frequency_penalty: Option<f32>,
pub user: Option<String>,
}
Expand description
Request arguments for chat completion.
See https://platform.openai.com/docs/api-reference/chat/create.
let args = openai_rust::chat::ChatArguments::new("gpt-3.5-turbo", vec![
openai_rust::chat::Message {
role: "user".to_owned(),
content: "Hello GPT!".to_owned(),
}
]);
Fields§
§model: String
§messages: Vec<Message>
§temperature: Option<f32>
§top_p: Option<f32>
§n: Option<u32>
§stream: Option<bool>
§stop: Option<String>
§max_tokens: Option<u32>
§presence_penalty: Option<f32>
§frequency_penalty: Option<f32>
§user: Option<String>
Implementations§
source§impl ChatArguments
impl ChatArguments
sourcepub fn new(model: impl AsRef<str>, messages: Vec<Message>) -> ChatArguments
pub fn new(model: impl AsRef<str>, messages: Vec<Message>) -> ChatArguments
Examples found in repository?
More examples
examples/chat_stream_example.rs (lines 9-14)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
async fn main() {
let client = openai_rust::Client::new(&std::env::var("OPENAI_API_KEY").unwrap());
let args = openai_rust::chat::ChatArguments::new("gpt-3.5-turbo", vec![
openai_rust::chat::Message {
role: "user".to_owned(),
content: "Hello GPT!".to_owned(),
}
]);
let mut res = client.create_chat_stream(args).await.unwrap();
while let Some(events) = res.next().await {
for event in events.unwrap() {
print!("{}", event.choices[0].delta.content.as_ref().unwrap_or(&"".to_owned()));
std::io::stdout().flush().unwrap();
}
}
}
Trait Implementations§
source§impl Clone for ChatArguments
impl Clone for ChatArguments
source§fn clone(&self) -> ChatArguments
fn clone(&self) -> ChatArguments
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more