pub struct OpenAiClient { /* private fields */ }
Expand description
This is main client structure required for all requests.
It is passed as a reference parameter into all API operations.
It is also holds actual reqwest::Client
http client, that performs requests.
§Usage example
use openai_req::OpenAiClient;
let client = OpenAiClient::new("{YOUR_API_KEY}");
Implementations§
Source§impl OpenAiClient
impl OpenAiClient
Sourcepub fn new(key: &str) -> Self
pub fn new(key: &str) -> Self
simplest constructor, uses default https://api.openai.com/v1 url, and creates new default client with connection pool for connections
Sourcepub fn with_client(key: &str, client: &Client) -> Self
pub fn with_client(key: &str, client: &Client) -> Self
reqwest library recommends re-using single client, so if you run access to multiple api-s, pass client into constructor. Also use this constructor if you want to customize your client (for example set different timeout, or use proxy)
Sourcepub fn with_url(key: &str, url: &str) -> Self
pub fn with_url(key: &str, url: &str) -> Self
if you want to change base url from https://api.openai.com/v1 to something else - you can
Sourcepub fn with_url_and_client(key: &str, url: &str, client: &Client) -> Self
pub fn with_url_and_client(key: &str, url: &str, client: &Client) -> Self
this constructor allows you to customise everything: client, key and base url for all requests
Trait Implementations§
Source§impl Clone for OpenAiClient
impl Clone for OpenAiClient
Source§fn clone(&self) -> OpenAiClient
fn clone(&self) -> OpenAiClient
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for OpenAiClient
impl !RefUnwindSafe for OpenAiClient
impl Send for OpenAiClient
impl Sync for OpenAiClient
impl Unpin for OpenAiClient
impl !UnwindSafe for OpenAiClient
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