@@ -37,13 +37,40 @@ async fn main() -> Result<(), Box<dyn Error>> {
3737
3838 let response = client. chat ( ) . create ( request) . await ?;
3939
40- println ! ( "\n Response:\n " ) ;
41- for choice in response. choices {
42- println ! (
43- "{}: Role: {} Content: {:?}" ,
44- choice. index, choice. message. role, choice. message. content
45- ) ;
46- }
40+ println ! ( "Chat Completion Response:\n " ) ;
41+ println ! ( "{:#?}" , response) ;
42+
43+ // api doesnt return the chat completion immediately, so retrieval doesnt work immediately, sleep
44+ tokio:: time:: sleep ( std:: time:: Duration :: from_secs ( 5 ) ) . await ;
45+
46+ // get chat completion object
47+ let chat_completion = client. chat ( ) . retrieve ( & response. id ) . await ?;
48+
49+ println ! ( "--------------------------------" ) ;
50+ println ! ( "Retrieved chat completion:\n " ) ;
51+ println ! ( "{:#?}" , chat_completion) ;
52+
53+ let chat_completion_messages = client
54+ . chat ( )
55+ . messages ( & response. id , & [ ( "limit" , 10 ) ] )
56+ . await ?;
57+
58+ println ! ( "--------------------------------" ) ;
59+ println ! ( "Retrieved chat completion messages:\n " ) ;
60+ println ! ( "{:#?}" , chat_completion_messages) ;
61+
62+ // list all chat completions
63+ let chat_completions = client. chat ( ) . list ( & [ ( "limit" , 10 ) ] ) . await ?;
64+
65+ println ! ( "--------------------------------" ) ;
66+ println ! ( "Retrieved chat completions:\n " ) ;
67+ println ! ( "{:#?}" , chat_completions) ;
68+
69+ let deleted = client. chat ( ) . delete ( & response. id ) . await ?;
70+
71+ println ! ( "--------------------------------" ) ;
72+ println ! ( "Deleted chat completion:\n " ) ;
73+ println ! ( "{:#?}" , deleted) ;
4774
4875 Ok ( ( ) )
4976}
0 commit comments