completion/
completion.rs

1use openai_gpt_rs::models::CompletionModels;
2use openai_gpt_rs::{client::Client, response::Content};
3use std::env;
4use std::io::{stdin, stdout, Write};
5
6#[tokio::main]
7async fn main() {
8    let mut prompt = String::new();
9
10    print!("Enter a prompt: ");
11    let _ = stdout().flush();
12
13    stdin().read_line(&mut prompt).unwrap();
14
15    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());
16
17    let resp = client
18        .create_completion(|args| {
19            args.prompt(prompt)
20                .model(CompletionModels::TextDavinci3)
21                .max_tokens(32)
22                .n(1)
23                .temperature(1.0)
24        })
25        .await
26        .unwrap();
27
28    let completion = resp.get_content(0).unwrap();
29
30    println!("{}", completion);
31}