1
2
3
4
5
6
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
use openai_safe::OpenAI;
use openai_safe::OpenAIModels;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;

#[derive(Deserialize, Serialize, JsonSchema, Debug, Clone)]
struct TranslationResponse {
    pub spanish: String,
    pub french: String,
    pub german: String,
    pub polish: String,
}

#[tokio::main]
async fn main() {
    env_logger::init();
    let api_key: String = std::env::var("OPENAI_API_KEY").expect("OPENAI_API_KEY not set");
    let model = OpenAIModels::Gpt3_5Turbo; // Choose the model

    let open_ai = OpenAI::new(&api_key, model, None, None);

    // Example context and instructions
    let instructions =
        "Translate the following English text to all the languages in the response type";

    match open_ai
        .get_answer::<TranslationResponse>(instructions)
        .await
    {
        Ok(response) => println!("Response: {:?}", response),
        Err(e) => eprintln!("Error: {:?}", e),
    }
}