pub struct Config { /* private fields */ }Expand description
Connection settings for a client.
| Setting | Environment variable | Default |
|---|---|---|
api_key | TYPESAFE_API_KEY | none |
base_url | TYPESAFE_BASE_URL | https://api.typesafe.ai |
model | TYPESAFE_DEFAULT_MODEL | jev-latest |
timeout | 10 s per response | |
retry | RetryPolicy::default | |
header | extra request headers |
Config::from_env reads the environment variables, and the setters
override them. The API key is kept out of Debug output.
A missing key is not an error here, so an app can start without one. Calls
then fail with ErrorKind::NoApiKey without
making a request.
use std::time::Duration;
use typesafe::Config;
let config = Config::from_env()
.model("jev-1.13.0")
.timeout(Duration::from_secs(5));Implementations§
Source§impl Config
impl Config
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
The defaults, with the key, base URL and model taken from the environment where set. Blank values count as unset.
pub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Sourcepub fn model(self, model: impl Into<String>) -> Self
pub fn model(self, model: impl Into<String>) -> Self
The model calls use unless they name one. Pin a versioned model such as
jev-1.13.0 once thresholds are tuned; jev-latest moves when a new
release ships.
pub fn retry(self, retry: RetryPolicy) -> Self
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
An extra header sent with every request.
Sourcepub fn is_configured(&self) -> bool
pub fn is_configured(&self) -> bool
Whether there is an API key.
Sourcepub fn default_model(&self) -> &str
pub fn default_model(&self) -> &str
The model calls use unless they name one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more