Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add with_headers method #245

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

chore: add with_headers method #245

wants to merge 4 commits into from

Conversation

b0xtch
Copy link

@b0xtch b0xtch commented Jul 19, 2024

Support custom headers required for observability applications

    let client = Client::with_config(
        OpenAIConfig::default()
            .with_api_base(api_base)
            .with_headers(HashMap::from([(
                "Helicone-Auth".to_string(),
                format!("Bearer {}", config_env_var("HELICONE_API_KEY")?),
            )])),
    );

@64bit
Copy link
Owner

64bit commented Jul 24, 2024

Thanks for the PR, I'll leave review seperately

@@ -31,17 +33,28 @@ pub trait Config: Clone {
pub struct OpenAIConfig {
api_base: String,
api_key: Secret<String>,
#[serde(deserialize_with = "deserialize_header_map")]
headers: HashMap<String, String>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use native HeaderMap instead of custom conversion with custom deserializer.

impl Default for OpenAIConfig {
fn default() -> Self {
Self {
api_base: OPENAI_API_BASE.to_string(),
api_key: std::env::var("OPENAI_API_KEY")
.unwrap_or_else(|_| "".to_string())
.into(),
headers: HashMap::new(),
Copy link
Owner

@64bit 64bit Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this is platform independent - this and with_headers could be a nice addition to AzureConfig as well for consistency. Not required though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants