1
1
//! Client configurations: [OpenAIConfig] for OpenAI, [AzureConfig] for Azure OpenAI Service.
2
2
use reqwest:: header:: { HeaderMap , AUTHORIZATION } ;
3
- use secrecy:: { ExposeSecret , Secret } ;
3
+ use secrecy:: { ExposeSecret , SecretString } ;
4
4
use serde:: Deserialize ;
5
5
6
6
/// Default v1 API base url
@@ -22,15 +22,15 @@ pub trait Config: Clone {
22
22
23
23
fn api_base ( & self ) -> & str ;
24
24
25
- fn api_key ( & self ) -> & Secret < String > ;
25
+ fn api_key ( & self ) -> & SecretString ;
26
26
}
27
27
28
28
/// Configuration for OpenAI API
29
29
#[ derive( Clone , Debug , Deserialize ) ]
30
30
#[ serde( default ) ]
31
31
pub struct OpenAIConfig {
32
32
api_base : String ,
33
- api_key : Secret < String > ,
33
+ api_key : SecretString ,
34
34
org_id : String ,
35
35
project_id : String ,
36
36
}
@@ -68,7 +68,7 @@ impl OpenAIConfig {
68
68
69
69
/// To use a different API key different from default OPENAI_API_KEY env var
70
70
pub fn with_api_key < S : Into < String > > ( mut self , api_key : S ) -> Self {
71
- self . api_key = Secret :: from ( api_key. into ( ) ) ;
71
+ self . api_key = SecretString :: from ( api_key. into ( ) ) ;
72
72
self
73
73
}
74
74
@@ -123,7 +123,7 @@ impl Config for OpenAIConfig {
123
123
& self . api_base
124
124
}
125
125
126
- fn api_key ( & self ) -> & Secret < String > {
126
+ fn api_key ( & self ) -> & SecretString {
127
127
& self . api_key
128
128
}
129
129
@@ -139,7 +139,7 @@ pub struct AzureConfig {
139
139
api_version : String ,
140
140
deployment_id : String ,
141
141
api_base : String ,
142
- api_key : Secret < String > ,
142
+ api_key : SecretString ,
143
143
}
144
144
145
145
impl Default for AzureConfig {
@@ -172,7 +172,7 @@ impl AzureConfig {
172
172
173
173
/// To use a different API key different from default OPENAI_API_KEY env var
174
174
pub fn with_api_key < S : Into < String > > ( mut self , api_key : S ) -> Self {
175
- self . api_key = Secret :: from ( api_key. into ( ) ) ;
175
+ self . api_key = SecretString :: from ( api_key. into ( ) ) ;
176
176
self
177
177
}
178
178
@@ -187,10 +187,7 @@ impl Config for AzureConfig {
187
187
fn headers ( & self ) -> HeaderMap {
188
188
let mut headers = HeaderMap :: new ( ) ;
189
189
190
- headers. insert (
191
- "api-key" ,
192
- self . api_key . expose_secret ( ) . as_str ( ) . parse ( ) . unwrap ( ) ,
193
- ) ;
190
+ headers. insert ( "api-key" , self . api_key . expose_secret ( ) . parse ( ) . unwrap ( ) ) ;
194
191
195
192
headers
196
193
}
@@ -206,7 +203,7 @@ impl Config for AzureConfig {
206
203
& self . api_base
207
204
}
208
205
209
- fn api_key ( & self ) -> & Secret < String > {
206
+ fn api_key ( & self ) -> & SecretString {
210
207
& self . api_key
211
208
}
212
209
0 commit comments