api_openai/
client_api_accessors.rs

1//! API Accessor Methods for `OpenAI` Client
2//!
3//! This module provides convenience accessor methods for all `OpenAI` API categories.
4//! Each method returns a specialized API client configured with the parent Client.
5
6use mod_interface::mod_interface;
7
8mod private
9{
10  use crate::
11  {
12    client ::Client,
13    environment ::{ OpenaiEnvironment, EnvironmentInterface },
14    assistants ::Assistants,
15    chat ::Chat,
16    embeddings ::Embeddings,
17    files ::Files,
18    fine_tuning ::FineTuning,
19    images ::Images,
20    models ::Models,
21    realtime ::Realtime,
22    responses ::Responses,
23    vector_stores ::VectorStores,
24  };
25
26  #[ cfg( feature = "audio" ) ]
27  use crate::audio::Audio;
28
29  #[ cfg( feature = "moderation" ) ]
30  use crate::moderations::Moderations;
31
32  /// Extension trait providing API accessor methods for Client
33  pub trait ClientApiAccessors< E >
34  where
35    E : OpenaiEnvironment + EnvironmentInterface + Send + Sync + 'static,
36  {
37    /// Returns an `Assistants` API client.
38    fn assistants( &self ) -> Assistants< '_, E >;
39
40    /// Returns an `Audio` API client.
41    #[ cfg( feature = "audio" ) ]
42    fn audio( &self ) -> Audio< '_, E >;
43
44    /// Returns a `Chat` API client.
45    fn chat( &self ) -> Chat< '_, E >;
46
47    /// Returns an `Embeddings` API client.
48    fn embeddings( &self ) -> Embeddings< '_, E >;
49
50    /// Returns a `Files` API client.
51    fn files( &self ) -> Files< '_, E >;
52
53    /// Returns a `FineTuning` API client.
54    fn fine_tuning( &self ) -> FineTuning< '_, E >;
55
56    /// Returns an `Images` API client.
57    fn images( &self ) -> Images< '_, E >;
58
59    /// Returns a `Models` API client.
60    fn models( &self ) -> Models< '_, E >;
61
62    /// Returns a `Moderations` API client.
63    #[ cfg( feature = "moderation" ) ]
64    fn moderations( &self ) -> Moderations< '_, E >;
65
66    /// Returns a `Realtime` API client.
67    fn realtime( &self ) -> Realtime< '_, E >;
68
69    /// Returns a `Responses` API client.
70    fn responses( &self ) -> Responses< '_, E >;
71
72    /// Returns a `VectorStores` API client.
73    fn vector_stores( &self ) -> VectorStores< '_, E >;
74  }
75
76  impl< E > ClientApiAccessors< E > for Client< E >
77  where
78    E : OpenaiEnvironment + EnvironmentInterface + Send + Sync + 'static,
79  {
80    #[ inline ]
81    fn assistants( &self ) -> Assistants< '_, E >
82    {
83      Assistants::new( self )
84    }
85
86    #[ inline ]
87    #[ cfg( feature = "audio" ) ]
88    fn audio( &self ) -> Audio< '_, E >
89    {
90      Audio::new( self )
91    }
92
93    #[ inline ]
94    fn chat( &self ) -> Chat< '_, E >
95    {
96      Chat::new( self )
97    }
98
99    #[ inline ]
100    fn embeddings( &self ) -> Embeddings< '_, E >
101    {
102      Embeddings::new( self )
103    }
104
105    #[ inline ]
106    fn files( &self ) -> Files< '_, E >
107    {
108      Files::new( self )
109    }
110
111    #[ inline ]
112    fn fine_tuning( &self ) -> FineTuning< '_, E >
113    {
114      FineTuning::new( self )
115    }
116
117    #[ inline ]
118    fn images( &self ) -> Images< '_, E >
119    {
120      Images::new( self )
121    }
122
123    #[ inline ]
124    fn models( &self ) -> Models< '_, E >
125    {
126      Models::new( self )
127    }
128
129    #[ inline ]
130    #[ cfg( feature = "moderation" ) ]
131    fn moderations( &self ) -> Moderations< '_, E >
132    {
133      Moderations::new( self )
134    }
135
136    #[ inline ]
137    fn realtime( &self ) -> Realtime< '_, E >
138    {
139      Realtime::new( self )
140    }
141
142    #[ inline ]
143    fn responses( &self ) -> Responses< '_, E >
144    {
145      Responses::new( self )
146    }
147
148    #[ inline ]
149    fn vector_stores( &self ) -> VectorStores< '_, E >
150    {
151      VectorStores::new( self )
152    }
153  }
154}
155
156mod_interface!
157{
158  exposed use
159  {
160    ClientApiAccessors,
161  };
162}