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
@@ -99,7 +99,7 @@ impl Config for OpenAIConfig {
99
99
self . project_id . as_str ( ) . parse ( ) . unwrap ( ) ,
100
100
) ;
101
101
}
102
-
102
+
103
103
// API key can also be found in [`reqwest::Client`] headers.
104
104
if !self . api_key ( ) . expose_secret ( ) . is_empty ( ) {
105
105
headers. insert (
@@ -126,7 +126,7 @@ impl Config for OpenAIConfig {
126
126
& self . api_base
127
127
}
128
128
129
- fn api_key ( & self ) -> & Secret < String > {
129
+ fn api_key ( & self ) -> & SecretString {
130
130
& self . api_key
131
131
}
132
132
0 commit comments