pub struct CompletionArgs {
    pub prompt: String,
    pub model: String,
    pub suffix: String,
    pub max_tokens: u32,
    pub n: usize,
    pub temperature: f64,
}

Fields§

§prompt: String§model: String§suffix: String§max_tokens: u32§n: usize§temperature: f64

Implementations§

source§

impl CompletionArgs

source

pub fn prompt<T>(&mut self, prompt: T) -> &mut Selfwhere T: ToString,

Set the prompt for the completion

Examples found in repository?
examples/completion.rs (line 19)
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
async fn main() {
    let mut prompt = String::new();

    print!("Enter a prompt: ");
    let _ = stdout().flush();

    stdin().read_line(&mut prompt).unwrap();

    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());

    let resp = client
        .create_completion(|args| {
            args.prompt(prompt)
                .model(CompletionModels::TextDavinci3)
                .max_tokens(32)
                .n(1)
                .temperature(1.0)
        })
        .await
        .unwrap();

    let completion = resp.get_content(0).unwrap();

    println!("{}", completion);
}
source

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

Set the model to use for the completion

Examples found in repository?
examples/completion.rs (line 20)
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
async fn main() {
    let mut prompt = String::new();

    print!("Enter a prompt: ");
    let _ = stdout().flush();

    stdin().read_line(&mut prompt).unwrap();

    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());

    let resp = client
        .create_completion(|args| {
            args.prompt(prompt)
                .model(CompletionModels::TextDavinci3)
                .max_tokens(32)
                .n(1)
                .temperature(1.0)
        })
        .await
        .unwrap();

    let completion = resp.get_content(0).unwrap();

    println!("{}", completion);
}
source

pub fn suffix<T>(&mut self, suffix: T) -> &mut Selfwhere T: ToString,

Set the suffix for the completion

source

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

Set the maximum number of tokens for the completion

Examples found in repository?
examples/completion.rs (line 21)
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
async fn main() {
    let mut prompt = String::new();

    print!("Enter a prompt: ");
    let _ = stdout().flush();

    stdin().read_line(&mut prompt).unwrap();

    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());

    let resp = client
        .create_completion(|args| {
            args.prompt(prompt)
                .model(CompletionModels::TextDavinci3)
                .max_tokens(32)
                .n(1)
                .temperature(1.0)
        })
        .await
        .unwrap();

    let completion = resp.get_content(0).unwrap();

    println!("{}", completion);
}
source

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

Set the number of completions to return

Examples found in repository?
examples/completion.rs (line 22)
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
async fn main() {
    let mut prompt = String::new();

    print!("Enter a prompt: ");
    let _ = stdout().flush();

    stdin().read_line(&mut prompt).unwrap();

    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());

    let resp = client
        .create_completion(|args| {
            args.prompt(prompt)
                .model(CompletionModels::TextDavinci3)
                .max_tokens(32)
                .n(1)
                .temperature(1.0)
        })
        .await
        .unwrap();

    let completion = resp.get_content(0).unwrap();

    println!("{}", completion);
}
source

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

Set the temperature for the completion

Examples found in repository?
examples/completion.rs (line 23)
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
async fn main() {
    let mut prompt = String::new();

    print!("Enter a prompt: ");
    let _ = stdout().flush();

    stdin().read_line(&mut prompt).unwrap();

    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());

    let resp = client
        .create_completion(|args| {
            args.prompt(prompt)
                .model(CompletionModels::TextDavinci3)
                .max_tokens(32)
                .n(1)
                .temperature(1.0)
        })
        .await
        .unwrap();

    let completion = resp.get_content(0).unwrap();

    println!("{}", completion);
}

Trait Implementations§

source§

impl Debug for CompletionArgs

source§

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

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

impl Default for CompletionArgs

source§

fn default() -> Self

Create a new CompletionArgs struct with default values

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