1- use openai_api_rs:: v1:: api:: Client ;
1+ use openai_api_rs:: v1:: api:: OpenAIClient ;
22use openai_api_rs:: v1:: assistant:: AssistantRequest ;
33use openai_api_rs:: v1:: common:: GPT4_O ;
44use openai_api_rs:: v1:: message:: { CreateMessageRequest , MessageRole } ;
@@ -7,8 +7,9 @@ use openai_api_rs::v1::thread::CreateThreadRequest;
77use std:: collections:: HashMap ;
88use std:: env;
99
10- fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
11- let client = Client :: new ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) ) ;
10+ #[ tokio:: main]
11+ async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
12+ let client = OpenAIClient :: new ( env:: var ( "OPENAI_API_KEY" ) . unwrap ( ) . to_string ( ) ) ;
1213
1314 let mut tools = HashMap :: new ( ) ;
1415 tools. insert ( "type" . to_string ( ) , "code_interpreter" . to_string ( ) ) ;
@@ -21,28 +22,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2122 let req = req. clone ( ) . tools ( vec ! [ tools] ) ;
2223 println ! ( "AssistantRequest: {:?}" , req) ;
2324
24- let result = client. create_assistant ( req) ?;
25+ let result = client. create_assistant ( req) . await ?;
2526 println ! ( "Create Assistant Result ID: {:?}" , result. id) ;
2627
2728 let thread_req = CreateThreadRequest :: new ( ) ;
28- let thread_result = client. create_thread ( thread_req) ?;
29+ let thread_result = client. create_thread ( thread_req) . await ?;
2930 println ! ( "Create Thread Result ID: {:?}" , thread_result. id. clone( ) ) ;
3031
3132 let message_req = CreateMessageRequest :: new (
3233 MessageRole :: user,
3334 "`I need to solve the equation 3x + 11 = 14. Can you help me?" . to_string ( ) ,
3435 ) ;
3536
36- let message_result = client. create_message ( thread_result. id . clone ( ) , message_req) ?;
37+ let message_result = client
38+ . create_message ( thread_result. id . clone ( ) , message_req)
39+ . await ?;
3740 println ! ( "Create Message Result ID: {:?}" , message_result. id. clone( ) ) ;
3841
3942 let run_req = CreateRunRequest :: new ( result. id ) ;
40- let run_result = client. create_run ( thread_result. id . clone ( ) , run_req) ?;
43+ let run_result = client. create_run ( thread_result. id . clone ( ) , run_req) . await ?;
4144 println ! ( "Create Run Result ID: {:?}" , run_result. id. clone( ) ) ;
4245
4346 loop {
4447 let run_result = client
4548 . retrieve_run ( thread_result. id . clone ( ) , run_result. id . clone ( ) )
49+ . await
4650 . unwrap ( ) ;
4751 if run_result. status == "completed" {
4852 break ;
@@ -52,7 +56,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5256 }
5357 }
5458
55- let list_message_result = client. list_messages ( thread_result. id . clone ( ) ) . unwrap ( ) ;
59+ let list_message_result = client
60+ . list_messages ( thread_result. id . clone ( ) )
61+ . await
62+ . unwrap ( ) ;
5663 for data in list_message_result. data {
5764 for content in data. content {
5865 println ! (
0 commit comments