edit/
edit.rs

1use openai_gpt_rs::models::EditModels;
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    let mut instruction = String::new();
10
11    print!("Enter a prompt: ");
12    let _ = stdout().flush();
13
14    stdin().read_line(&mut prompt).unwrap();
15
16    print!("Enter the instruction: ");
17    let _ = stdout().flush();
18
19    stdin().read_line(&mut instruction).unwrap();
20
21    let client = Client::new(env::var("OPENAI_API_KEY").unwrap().as_str());
22
23    let resp = client
24        .create_edit(|args| {
25            args.input(prompt)
26                .instruction(instruction)
27                .model(EditModels::TextDavinciEdit1)
28                .n(1)
29                .temperature(1.0)
30        })
31        .await
32        .unwrap();
33
34    let text = resp.get_content(0).unwrap();
35
36    println!("{}", text);
37}