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