1use openai_api_rs::v1::api::OpenAIClient;
2use openai_api_rs::v1::chat_completion::chat_completion::ChatCompletionRequest;
3use openai_api_rs::v1::chat_completion::{self};
4use openai_api_rs::v1::common::GPT4_O;
5use std::env;
6
7#[tokio::main]
8async fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let api_key = env::var("OPENAI_API_KEY").unwrap().to_string();
10 let mut client = OpenAIClient::builder().with_api_key(api_key).build()?;
11
12 let req = ChatCompletionRequest::new(
13 GPT4_O.to_string(),
14 vec![chat_completion::ChatCompletionMessage {
15 role: chat_completion::MessageRole::user,
16 content: chat_completion::Content::ImageUrl(vec![
17 chat_completion::ImageUrl {
18 r#type: chat_completion::ContentType::text,
19 text: Some(String::from("What's in this image?")),
20 image_url: None,
21 },
22 chat_completion::ImageUrl {
23 r#type: chat_completion::ContentType::image_url,
24 text: None,
25 image_url: Some(chat_completion::ImageUrlType {
26 url: String::from(
27 "https://upload.wikimedia.org/wikipedia/commons/5/50/Bitcoin.png",
28 ),
29 }),
30 },
31 ]),
32 name: None,
33 tool_calls: None,
34 tool_call_id: None,
35 }],
36 );
37
38 let result = client.chat_completion(req).await?;
39 println!("{:?}", result.choices[0].message.content);
40
41 Ok(())
42}
43
44