11use crate :: v1:: assistant:: {
2- AssistantFileObject , AssistantFileRequest , AssistantObject , AssistantRequest , DeletionStatus ,
3- ListAssistant , ListAssistantFile ,
2+ AssistantFileObject , AssistantFileRequest , AssistantObject , AssistantRequest , ListAssistant ,
3+ ListAssistantFile ,
44} ;
55use crate :: v1:: audio:: {
66 AudioSpeechRequest , AudioSpeechResponse , AudioTranscriptionRequest , AudioTranscriptionResponse ,
@@ -30,6 +30,7 @@ use crate::v1::message::{
3030 CreateMessageRequest , ListMessage , ListMessageFile , MessageFileObject , MessageObject ,
3131 ModifyMessageRequest ,
3232} ;
33+ use crate :: v1:: model:: { ModelResponse , ModelsResponse } ;
3334use crate :: v1:: moderation:: { CreateModerationRequest , CreateModerationResponse } ;
3435use crate :: v1:: run:: {
3536 CreateRunRequest , CreateThreadAndRunRequest , ListRun , ListRunStep , ModifyRunRequest , RunObject ,
@@ -70,7 +71,8 @@ pub struct OpenAIClient {
7071 organization : Option < String > ,
7172 proxy : Option < String > ,
7273 timeout : Option < u64 > ,
73- pub headers : Option < HeaderMap > ,
74+ headers : Option < HeaderMap > ,
75+ pub response_headers : Option < HeaderMap > ,
7476}
7577
7678impl OpenAIClientBuilder {
@@ -124,6 +126,7 @@ impl OpenAIClientBuilder {
124126 proxy : self . proxy ,
125127 timeout : self . timeout ,
126128 headers : self . headers ,
129+ response_headers : None ,
127130 } )
128131 }
129132}
@@ -237,7 +240,7 @@ impl OpenAIClient {
237240 let text = response. text ( ) . await . unwrap_or_else ( |_| "" . to_string ( ) ) ;
238241 match serde_json:: from_str :: < T > ( & text) {
239242 Ok ( parsed) => {
240- self . headers = Some ( headers) ;
243+ self . response_headers = Some ( headers) ;
241244 Ok ( parsed)
242245 }
243246 Err ( e) => Err ( APIError :: CustomError {
@@ -507,7 +510,7 @@ impl OpenAIClient {
507510 pub async fn delete_assistant (
508511 & mut self ,
509512 assistant_id : String ,
510- ) -> Result < DeletionStatus , APIError > {
513+ ) -> Result < common :: DeletionStatus , APIError > {
511514 self . delete ( & format ! ( "assistants/{}" , assistant_id) ) . await
512515 }
513516
@@ -544,7 +547,7 @@ impl OpenAIClient {
544547 & mut self ,
545548 assistant_id : String ,
546549 file_id : String ,
547- ) -> Result < DeletionStatus , APIError > {
550+ ) -> Result < common :: DeletionStatus , APIError > {
548551 self . delete ( & format ! ( "assistants/{}/files/{}" , assistant_id, file_id) )
549552 . await
550553 }
@@ -586,7 +589,10 @@ impl OpenAIClient {
586589 self . post ( & format ! ( "threads/{}" , thread_id) , & req) . await
587590 }
588591
589- pub async fn delete_thread ( & mut self , thread_id : String ) -> Result < DeletionStatus , APIError > {
592+ pub async fn delete_thread (
593+ & mut self ,
594+ thread_id : String ,
595+ ) -> Result < common:: DeletionStatus , APIError > {
590596 self . delete ( & format ! ( "threads/{}" , thread_id) ) . await
591597 }
592598
@@ -781,6 +787,22 @@ impl OpenAIClient {
781787 let url = Self :: query_params ( limit, None , after, None , "batches" . to_string ( ) ) ;
782788 self . get ( & url) . await
783789 }
790+
791+ pub async fn list_models ( & mut self ) -> Result < ModelsResponse , APIError > {
792+ self . get ( "models" ) . await
793+ }
794+
795+ pub async fn retrieve_model ( & mut self , model_id : String ) -> Result < ModelResponse , APIError > {
796+ self . get ( & format ! ( "models/{}" , model_id) ) . await
797+ }
798+
799+ pub async fn delete_model (
800+ & mut self ,
801+ model_id : String ,
802+ ) -> Result < common:: DeletionStatus , APIError > {
803+ self . delete ( & format ! ( "models/{}" , model_id) ) . await
804+ }
805+
784806 fn build_url_with_preserved_query ( & self , path : & str ) -> Result < String , url:: ParseError > {
785807 let ( base, query_opt) = match self . api_endpoint . split_once ( '?' ) {
786808 Some ( ( b, q) ) => ( b. trim_end_matches ( '/' ) , Some ( q) ) ,
@@ -797,6 +819,7 @@ impl OpenAIClient {
797819 }
798820 Ok ( url. to_string ( ) )
799821 }
822+
800823 fn query_params (
801824 limit : Option < i64 > ,
802825 order : Option < String > ,
0 commit comments