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

source

pub fn model(&mut self, model: ChatModels) -> &mut Self

Set the model to use

source

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);
}
source

pub fn n(&mut self, n: i32) -> &mut Self

Set the number of messages to return

source

pub fn temperature(&mut self, temperature: f64) -> &mut Self

Set the temperature to use

source

pub fn top_p(&mut self, top_p: f64) -> &mut Self

Set the top_p to use

source

pub fn max_tokens(&mut self, max_tokens: u32) -> &mut Self

Set the max_tokens to use

source

pub fn presence_penalty(&mut self, presence_penalty: f64) -> &mut Self

Set the presence_penalty to use

source

pub fn frequency_penalty(&mut self, frequency_penalty: f64) -> &mut Self

Set the frequency_penalty to use

Trait Implementations§

source§

impl Debug for ChatArgs

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ChatArgs

source§

fn default() -> Self

Default chat arguments

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more