Skip to content

Commit 639eaa4

Browse files
committed
add BaseConfig and new Config
Enabling extra configs that can be opted in, which may be needed for LLM services other than OpenAI
1 parent 6ee3ac7 commit 639eaa4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

async-openai/src/config.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ pub const OPENAI_ORGANIZATION_HEADER: &str = "OpenAI-Organization";
1212
/// Calls to the Assistants API require that you pass a Beta header
1313
pub const OPENAI_BETA_HEADER: &str = "OpenAI-Beta";
1414

15-
/// [crate::Client] relies on this for every API call on OpenAI
16-
/// or Azure OpenAI service
17-
pub trait Config: 'static + Debug + Send + Sync {
15+
pub trait BaseConfig: 'static + Debug + Send + Sync {
1816
fn headers(&self) -> HeaderMap;
1917
fn url(&self, path: &str) -> String;
2018
fn query(&self) -> Vec<(&str, &str)>;
@@ -24,6 +22,18 @@ pub trait Config: 'static + Debug + Send + Sync {
2422
fn api_key(&self) -> &Secret<String>;
2523
}
2624

25+
/// [crate::Client] relies on this for every API call on OpenAI
26+
/// or Azure OpenAI service
27+
pub trait Config<Extra = ()>: BaseConfig {
28+
fn extra_configs(&self) -> &Extra;
29+
}
30+
31+
impl<T: BaseConfig> Config<()> for T {
32+
fn extra_configs(&self) -> &() {
33+
&()
34+
}
35+
}
36+
2737
/// Configuration for OpenAI API
2838
#[derive(Clone, Debug, Deserialize)]
2939
#[serde(default)]
@@ -74,7 +84,7 @@ impl OpenAIConfig {
7484
}
7585
}
7686

77-
impl Config for OpenAIConfig {
87+
impl BaseConfig for OpenAIConfig {
7888
fn headers(&self) -> HeaderMap {
7989
let mut headers = HeaderMap::new();
8090
if !self.org_id.is_empty() {
@@ -167,7 +177,7 @@ impl AzureConfig {
167177
}
168178
}
169179

170-
impl Config for AzureConfig {
180+
impl BaseConfig for AzureConfig {
171181
fn headers(&self) -> HeaderMap {
172182
let mut headers = HeaderMap::new();
173183

0 commit comments

Comments
 (0)