Struct openai_gpt_rs::args::ChatArgs
source · pub struct ChatArgs {
pub model: String,
pub messages: Vec<Message>,
pub n: i32,
pub temperature: f64,
pub top_p: f64,
pub max_tokens: u32,
pub presence_penalty: f64,
pub frequency_penalty: f64,
}
Fields§
§model: String
§messages: Vec<Message>
§n: i32
§temperature: f64
§top_p: f64
§max_tokens: u32
§presence_penalty: f64
§frequency_penalty: f64
Implementations§
source§impl ChatArgs
impl ChatArgs
sourcepub fn model(&mut self, model: ChatModels) -> &mut Self
pub fn model(&mut self, model: ChatModels) -> &mut Self
Set the model to use
sourcepub fn messages(&mut self, messages: Vec<Message>) -> &mut Self
pub fn messages(&mut self, messages: Vec<Message>) -> &mut Self
Set the messages to use
Examples found in repository?
examples/chat.rs (line 44)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
async fn main() {
let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());
let mut role: String;
let mut message = String::new();
let mut index = String::new();
print!(" 1: system\n 2: assistant\n 3: user\nSelect a role: ");
let _ = stdout().flush();
stdin().read_line(&mut index).unwrap();
if index.trim() == "1" {
role = "system".to_string();
} else if index.trim() == "2" {
role = "assistant".to_string();
} else if index.trim() == "3" {
role = "user".to_string();
} else {
panic!("Invalid role!");
}
role = role.trim().to_string();
print!("Enter a message: ");
let _ = stdout().flush();
stdin().read_line(&mut message).unwrap();
let content = message.trim().to_string();
let message = Message { role, content };
let message = vec![message];
let resp = client
.create_chat_completion(|args| args.messages(message))
.await
.unwrap();
let content = resp.get_content(0).unwrap();
println!("Response: {}", content);
}
sourcepub fn temperature(&mut self, temperature: f64) -> &mut Self
pub fn temperature(&mut self, temperature: f64) -> &mut Self
Set the temperature to use
sourcepub fn max_tokens(&mut self, max_tokens: u32) -> &mut Self
pub fn max_tokens(&mut self, max_tokens: u32) -> &mut Self
Set the max_tokens to use
sourcepub fn presence_penalty(&mut self, presence_penalty: f64) -> &mut Self
pub fn presence_penalty(&mut self, presence_penalty: f64) -> &mut Self
Set the presence_penalty to use
sourcepub fn frequency_penalty(&mut self, frequency_penalty: f64) -> &mut Self
pub fn frequency_penalty(&mut self, frequency_penalty: f64) -> &mut Self
Set the frequency_penalty to use
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for ChatArgs
impl Send for ChatArgs
impl Sync for ChatArgs
impl Unpin for ChatArgs
impl UnwindSafe for ChatArgs
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more