pub struct OpenAI { /* private fields */ }Expand description
An OpenAI-shaped provider: its OpenAIConfig on a transport. Every
model it builds sends through that transport.
use rig_core::completion::CompletionRequest;
use rig_core::providers::openai::{self, OpenAIConfig};
let openai = OpenAIConfig::from_env()?.connect(http);
let model = openai.completion(openai::GPT_5_2);
let response = model.call(CompletionRequest::new("Capital of France?")).await?;Implementations§
Source§impl OpenAI
impl OpenAI
Sourcepub fn with_http(self, http: impl HttpClientExt + 'static) -> Self
pub fn with_http(self, http: impl HttpClientExt + 'static) -> Self
The same configuration, sending through http.
Sourcepub fn config(&self) -> &OpenAIConfig
pub fn config(&self) -> &OpenAIConfig
The configuration this client sends with.
Source§impl OpenAI
impl OpenAI
Sourcepub fn new(api_key: impl Into<Secret>) -> Self
Available on crate feature reqwest only.
pub fn new(api_key: impl Into<Secret>) -> Self
reqwest only.Official OpenAI with api_key, on the shared reqwest client.
Sourcepub fn from_env() -> Result<Self, EnvError>
Available on crate feature reqwest only.
pub fn from_env() -> Result<Self, EnvError>
reqwest only.Official OpenAI from OPENAI_API_KEY and the optional
OPENAI_BASE_URL, on the shared reqwest client.
Sourcepub fn completion(&self, model: impl Into<String>) -> Model<OpenAiWire>
pub fn completion(&self, model: impl Into<String>) -> Model<OpenAiWire>
The completion model for model on the configuration’s
completion_route.
Sourcepub fn responses(&self, model: impl Into<String>) -> Model<Responses>
pub fn responses(&self, model: impl Into<String>) -> Model<Responses>
The Responses model for model: POST /responses.
Sourcepub fn chat(&self, model: impl Into<String>) -> Model<Chat>
pub fn chat(&self, model: impl Into<String>) -> Model<Chat>
The Chat Completions model for model.
Sourcepub fn embedding(
&self,
model: impl Into<String>,
ndims: Option<usize>,
) -> Model<Embeddings>
pub fn embedding( &self, model: impl Into<String>, ndims: Option<usize>, ) -> Model<Embeddings>
The embedding model for model, ndims wide when set.
Sourcepub fn transcription(&self, model: impl Into<String>) -> Model<Transcriptions>
pub fn transcription(&self, model: impl Into<String>) -> Model<Transcriptions>
The transcription model for model.
Sourcepub fn image_generation(&self, model: impl Into<String>) -> Model<Images>
Available on crate feature image only.
pub fn image_generation(&self, model: impl Into<String>) -> Model<Images>
image only.The image-generation model for model.
Sourcepub fn audio_generation(&self, model: impl Into<String>) -> Model<Speech>
Available on crate feature audio only.
pub fn audio_generation(&self, model: impl Into<String>) -> Model<Speech>
audio only.The speech model for model.
Sourcepub async fn list_models(&self) -> Result<ModelList, ProviderError>
pub async fn list_models(&self) -> Result<ModelList, ProviderError>
The models this provider serves, every page followed.
Sourcepub async fn verify(&self) -> Result<(), ProviderError>
pub async fn verify(&self) -> Result<(), ProviderError>
Check that the provider accepts the configured credential. A 401 or
403 reply is ProviderError::InvalidAuthentication.
Sourcepub async fn authenticate(
self,
authenticator: &Authenticator,
) -> Result<Self, AuthError>
pub async fn authenticate( self, authenticator: &Authenticator, ) -> Result<Self, AuthError>
This client with the ChatGPT subscription credential authenticator
resolves, reading or refreshing it through this client’s transport:
the access token, and the account it belongs to when one is named.
Every other setting is kept.
use rig_core::providers::chatgpt::{self, auth::{AuthSource, Authenticator, DeviceCodeHandler}};
use rig_core::providers::openai::OpenAIConfig;
let authenticator = Authenticator::new(AuthSource::OAuth, None, DeviceCodeHandler::default(), true);
let chatgpt = OpenAIConfig::with_key(&chatgpt::DIALECT, "")
.connect(http)
.authenticate(&authenticator)
.await?;Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAI
impl !UnwindSafe for OpenAI
impl Freeze for OpenAI
impl Send for OpenAI
impl Sync for OpenAI
impl Unpin for OpenAI
impl UnsafeUnpin for OpenAI
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more