Skip to content

Commit f2cdf45

Browse files
authored
add a permissive deserialization using Default for OpenAIConfig and AzureConfig (#108)
1 parent f9bf345 commit f2cdf45

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

async-openai/src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Client configurations: [OpenAIConfig] for OpenAI, [AzureConfig] for Azure OpenAI Service.
22
use reqwest::header::{HeaderMap, AUTHORIZATION};
3+
use serde::Deserialize;
34

45
/// Default v1 API base url
56
pub const OPENAI_API_BASE: &str = "https://api.openai.com/v1";
@@ -19,7 +20,8 @@ pub trait Config: Clone {
1920
}
2021

2122
/// Configuration for OpenAI API
22-
#[derive(Clone, Debug)]
23+
#[derive(Clone, Debug, Deserialize)]
24+
#[serde(default)]
2325
pub struct OpenAIConfig {
2426
api_base: String,
2527
api_key: String,
@@ -101,7 +103,8 @@ impl Config for OpenAIConfig {
101103
}
102104

103105
/// Configuration for Azure OpenAI Service
104-
#[derive(Clone, Debug)]
106+
#[derive(Clone, Debug, Deserialize)]
107+
#[serde(default)]
105108
pub struct AzureConfig {
106109
api_version: String,
107110
deployment_id: String,

0 commit comments

Comments
 (0)