pub struct OpenAiAdapterOptions { /* private fields */ }Expand description
Builder-style configuration for constructing OpenAiAdapter.
§Typical usage
use artificial_openai::OpenAiAdapterOptions;
let backend = OpenAiAdapterOptions::new_from_env()
.build()
.expect("OPENAI_API_KEY must be set");The builder pattern keeps future options (proxy URL, organisation ID, …)
backwards compatible without breaking existing build() calls.
Implementations§
Source§impl OpenAiAdapterOptions
impl OpenAiAdapterOptions
Sourcepub fn new_from_env() -> Self
pub fn new_from_env() -> Self
Convenience constructor that tries to load the OPENAI_API_KEY
environment variable.
§Panics
Never panics. Missing keys only surface during Self::build.
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Set API key explicitly.
Sourcepub fn with_retry_policy(self, retry: RetryPolicy) -> Self
pub fn with_retry_policy(self, retry: RetryPolicy) -> Self
Set a retry policy for OpenAI HTTP calls.
Sourcepub fn with_http_timeouts(self, timeouts: HttpTimeoutConfig) -> Self
pub fn with_http_timeouts(self, timeouts: HttpTimeoutConfig) -> Self
Set HTTP timeout configuration for upstream requests.
Sourcepub fn build(self) -> Result<OpenAiAdapter>
pub fn build(self) -> Result<OpenAiAdapter>
Finalise the builder and return a ready-to-use adapter.
§Errors
ArtificialError::Invalid– if the API key is missing.
Trait Implementations§
Source§impl Default for OpenAiAdapterOptions
impl Default for OpenAiAdapterOptions
Source§fn default() -> OpenAiAdapterOptions
fn default() -> OpenAiAdapterOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OpenAiAdapterOptions
impl RefUnwindSafe for OpenAiAdapterOptions
impl Send for OpenAiAdapterOptions
impl Sync for OpenAiAdapterOptions
impl Unpin for OpenAiAdapterOptions
impl UnsafeUnpin for OpenAiAdapterOptions
impl UnwindSafe for OpenAiAdapterOptions
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