kind_openai/
auth.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/// Any type that can provide a bearer auth token.
pub trait AuthTokenProvider: Clone {
    async fn resolve(&self) -> Option<String>;
}

/// Auth token provided that takes the auth token from the environment variable `OPENAI_API_KEY`.
#[derive(Clone)]
pub struct EnvironmentAuthTokenProvider;

impl EnvironmentAuthTokenProvider {
    const ENV_VAR: &'static str = "OPENAI_API_KEY";
}

impl AuthTokenProvider for EnvironmentAuthTokenProvider {
    async fn resolve(&self) -> Option<String> {
        std::env::var(Self::ENV_VAR).ok()
    }
}