pub struct Client<T = Client> { /* private fields */ }Implementations§
Source§impl Client<Client>
impl Client<Client>
Sourcepub fn builder(api_key: &str) -> ClientBuilder<'_, Client>
pub fn builder(api_key: &str) -> ClientBuilder<'_, Client>
Create a new OpenAI client builder.
§Example
use rig::providers::openai::{ClientBuilder, self};
// Initialize the OpenAI client
let openai_client = Client::builder("your-open-ai-api-key")
.build()Sourcepub fn new(api_key: &str) -> Self
pub fn new(api_key: &str) -> Self
Create a new OpenAI client. For more control, use the builder method.
pub fn from_env() -> Self
Source§impl<T> Client<T>
impl<T> Client<T>
Sourcepub fn extractor_completions_api<U>(
&self,
model: &str,
) -> ExtractorBuilder<CompletionModel<T>, U>where
U: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync,
CompletionModel<T>: CompletionModel,
pub fn extractor_completions_api<U>(
&self,
model: &str,
) -> ExtractorBuilder<CompletionModel<T>, U>where
U: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync,
CompletionModel<T>: CompletionModel,
Create an extractor builder with the given completion model. Intended for use exclusively with the Chat Completions API. Useful for using extractors with Chat Completion compliant APIs.
Trait Implementations§
Source§impl<T> AudioGenerationClient for Client<T>
Available on crate feature audio only.
impl<T> AudioGenerationClient for Client<T>
Available on crate feature
audio only.Source§fn audio_generation_model(&self, model: &str) -> Self::AudioGenerationModel
fn audio_generation_model(&self, model: &str) -> Self::AudioGenerationModel
Create an audio generation model with the given name.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let gpt4 = openai.audio_generation_model(openai::TTS_1);Source§type AudioGenerationModel = AudioGenerationModel<T>
type AudioGenerationModel = AudioGenerationModel<T>
The AudioGenerationModel used by the Client
Source§impl<T> CompletionClient for Client<T>
impl<T> CompletionClient for Client<T>
Source§fn completion_model(&self, model: &str) -> Self::CompletionModel
fn completion_model(&self, model: &str) -> Self::CompletionModel
Create a completion model with the given name.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let gpt4 = openai.completion_model(openai::GPT_4);Source§type CompletionModel = ResponsesCompletionModel<T>
type CompletionModel = ResponsesCompletionModel<T>
The type of CompletionModel used by the client.
Source§fn agent(&self, model: &str) -> AgentBuilder<Self::CompletionModel>
fn agent(&self, model: &str) -> AgentBuilder<Self::CompletionModel>
Create an agent builder with the given completion model. Read more
Source§fn extractor<T>(
&self,
model: &str,
) -> ExtractorBuilder<Self::CompletionModel, T>
fn extractor<T>( &self, model: &str, ) -> ExtractorBuilder<Self::CompletionModel, T>
Create an extractor builder with the given completion model.
Source§impl<T> EmbeddingsClient for Client<T>
impl<T> EmbeddingsClient for Client<T>
Source§type EmbeddingModel = EmbeddingModel<T>
type EmbeddingModel = EmbeddingModel<T>
The type of EmbeddingModel used by the Client
Source§fn embedding_model(&self, model: &str) -> Self::EmbeddingModel
fn embedding_model(&self, model: &str) -> Self::EmbeddingModel
Create an embedding model with the given name.
Note: default embedding dimension of 0 will be used if model is not known.
If this is the case, it’s better to use function
embedding_model_with_ndims Read moreSource§fn embedding_model_with_ndims(
&self,
model: &str,
ndims: usize,
) -> Self::EmbeddingModel
fn embedding_model_with_ndims( &self, model: &str, ndims: usize, ) -> Self::EmbeddingModel
Create an embedding model with the given name and the number of dimensions in the embedding generated by the model. Read more
Source§fn embeddings<D: Embed>(
&self,
model: &str,
) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
fn embeddings<D: Embed>( &self, model: &str, ) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
Create an embedding builder with the given embedding model. Read more
Source§fn embeddings_with_ndims<D: Embed>(
&self,
model: &str,
ndims: usize,
) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
fn embeddings_with_ndims<D: Embed>( &self, model: &str, ndims: usize, ) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
Create an embedding builder with the given name and the number of dimensions in the embedding generated by the model. Read more
Source§impl<T> ImageGenerationClient for Client<T>
Available on crate feature image only.
impl<T> ImageGenerationClient for Client<T>
Available on crate feature
image only.Source§fn image_generation_model(&self, model: &str) -> Self::ImageGenerationModel
fn image_generation_model(&self, model: &str) -> Self::ImageGenerationModel
Create an image generation model with the given name.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let gpt4 = openai.image_generation_model(openai::DALL_E_3);Source§type ImageGenerationModel = ImageGenerationModel<T>
type ImageGenerationModel = ImageGenerationModel<T>
The ImageGenerationModel used by the Client
Source§impl<T> ProviderClient for Client<T>
impl<T> ProviderClient for Client<T>
Source§fn from_env() -> Self
fn from_env() -> Self
Create a new OpenAI client from the OPENAI_API_KEY environment variable.
Panics if the environment variable is not set.
fn from_val(input: ProviderValue) -> Self
Source§fn boxed(self) -> Box<dyn ProviderClient>where
Self: Sized + 'static,
fn boxed(self) -> Box<dyn ProviderClient>where
Self: Sized + 'static,
A helper method to box the client.
Source§fn from_env_boxed<'a>() -> Box<dyn ProviderClient + 'a>where
Self: Sized + 'a,
fn from_env_boxed<'a>() -> Box<dyn ProviderClient + 'a>where
Self: Sized + 'a,
Create a boxed client from the process’s environment.
Panics if an environment is improperly configured.
Source§fn from_val_boxed<'a>(input: ProviderValue) -> Box<dyn ProviderClient + 'a>where
Self: Sized + 'a,
fn from_val_boxed<'a>(input: ProviderValue) -> Box<dyn ProviderClient + 'a>where
Self: Sized + 'a,
Create a boxed client from the process’s environment.
Panics if an environment is improperly configured.
Source§impl<T> TranscriptionClient for Client<T>
impl<T> TranscriptionClient for Client<T>
Source§fn transcription_model(&self, model: &str) -> Self::TranscriptionModel
fn transcription_model(&self, model: &str) -> Self::TranscriptionModel
Create a transcription model with the given name.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let gpt4 = openai.transcription_model(openai::WHISPER_1);Source§type TranscriptionModel = TranscriptionModel<T>
type TranscriptionModel = TranscriptionModel<T>
The type of TranscriptionModel used by the Client
Source§impl<T> VerifyClient for Client<T>
impl<T> VerifyClient for Client<T>
Auto Trait Implementations§
impl<T> Freeze for Client<T>where
T: Freeze,
impl<T> RefUnwindSafe for Client<T>where
T: RefUnwindSafe,
impl<T> Send for Client<T>where
T: Send,
impl<T> Sync for Client<T>where
T: Sync,
impl<T> Unpin for Client<T>where
T: Unpin,
impl<T> UnwindSafe for Client<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsAudioGeneration for Twhere
T: AudioGenerationClientDyn + Clone + 'static,
impl<T> AsAudioGeneration for Twhere
T: AudioGenerationClientDyn + Clone + 'static,
Source§fn as_audio_generation(&self) -> Option<Box<dyn AudioGenerationClientDyn>>
fn as_audio_generation(&self) -> Option<Box<dyn AudioGenerationClientDyn>>
Available on crate feature
audio only.Source§impl<T> AsCompletion for Twhere
T: CompletionClientDyn + Clone + 'static,
impl<T> AsCompletion for Twhere
T: CompletionClientDyn + Clone + 'static,
fn as_completion(&self) -> Option<Box<dyn CompletionClientDyn>>
Source§impl<T> AsEmbeddings for Twhere
T: EmbeddingsClientDyn + Clone + 'static,
impl<T> AsEmbeddings for Twhere
T: EmbeddingsClientDyn + Clone + 'static,
fn as_embeddings(&self) -> Option<Box<dyn EmbeddingsClientDyn>>
Source§impl<T> AsImageGeneration for Twhere
T: ImageGenerationClientDyn + Clone + 'static,
impl<T> AsImageGeneration for Twhere
T: ImageGenerationClientDyn + Clone + 'static,
Source§fn as_image_generation(&self) -> Option<Box<dyn ImageGenerationClientDyn>>
fn as_image_generation(&self) -> Option<Box<dyn ImageGenerationClientDyn>>
Available on crate feature
image only.Source§impl<T> AsTranscription for Twhere
T: TranscriptionClientDyn + Clone + 'static,
impl<T> AsTranscription for Twhere
T: TranscriptionClientDyn + Clone + 'static,
fn as_transcription(&self) -> Option<Box<dyn TranscriptionClientDyn>>
Source§impl<T> AsVerify for Twhere
T: VerifyClientDyn + Clone + 'static,
impl<T> AsVerify for Twhere
T: VerifyClientDyn + Clone + 'static,
Source§impl<T, M> AudioGenerationClientDyn for Twhere
T: AudioGenerationClient<AudioGenerationModel = M>,
M: AudioGenerationModel + 'static,
impl<T, M> AudioGenerationClientDyn for Twhere
T: AudioGenerationClient<AudioGenerationModel = M>,
M: AudioGenerationModel + 'static,
Source§fn audio_generation_model<'a>(
&self,
model: &str,
) -> Box<dyn AudioGenerationModelDyn + 'a>
fn audio_generation_model<'a>( &self, model: &str, ) -> Box<dyn AudioGenerationModelDyn + 'a>
Available on crate feature
audio only.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
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
Source§impl<T, M, R> CompletionClientDyn for Twhere
T: CompletionClient<CompletionModel = M>,
M: CompletionModel<StreamingResponse = R> + 'static,
R: Clone + Unpin + GetTokenUsage + 'static,
impl<T, M, R> CompletionClientDyn for Twhere
T: CompletionClient<CompletionModel = M>,
M: CompletionModel<StreamingResponse = R> + 'static,
R: Clone + Unpin + GetTokenUsage + 'static,
Source§fn completion_model<'a>(&self, model: &str) -> Box<dyn CompletionModelDyn + 'a>
fn completion_model<'a>(&self, model: &str) -> Box<dyn CompletionModelDyn + 'a>
Create a completion model with the given name.
Source§fn agent<'a>(&self, model: &str) -> AgentBuilder<CompletionModelHandle<'a>>
fn agent<'a>(&self, model: &str) -> AgentBuilder<CompletionModelHandle<'a>>
Create an agent builder with the given completion model.
Source§impl<M, T> EmbeddingsClientDyn for Twhere
T: EmbeddingsClient<EmbeddingModel = M>,
M: EmbeddingModel + 'static,
impl<M, T> EmbeddingsClientDyn for Twhere
T: EmbeddingsClient<EmbeddingModel = M>,
M: EmbeddingModel + 'static,
Source§fn embedding_model<'a>(&self, model: &str) -> Box<dyn EmbeddingModelDyn + 'a>
fn embedding_model<'a>(&self, model: &str) -> Box<dyn EmbeddingModelDyn + 'a>
Create an embedding model with the given name.
Note: default embedding dimension of 0 will be used if model is not known.
If this is the case, it’s better to use function
embedding_model_with_ndimsSource§fn embedding_model_with_ndims<'a>(
&self,
model: &str,
ndims: usize,
) -> Box<dyn EmbeddingModelDyn + 'a>
fn embedding_model_with_ndims<'a>( &self, model: &str, ndims: usize, ) -> Box<dyn EmbeddingModelDyn + 'a>
Create an embedding model with the given name and the number of dimensions in the embedding generated by the model.
Source§impl<T, M> ImageGenerationClientDyn for Twhere
T: ImageGenerationClient<ImageGenerationModel = M>,
M: ImageGenerationModel + 'static,
impl<T, M> ImageGenerationClientDyn for Twhere
T: ImageGenerationClient<ImageGenerationModel = M>,
M: ImageGenerationModel + 'static,
Source§fn image_generation_model<'a>(
&self,
model: &str,
) -> Box<dyn ImageGenerationModelDyn + 'a>
fn image_generation_model<'a>( &self, model: &str, ) -> Box<dyn ImageGenerationModelDyn + 'a>
Available on crate feature
image only.Create an image generation model with the given name.
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> 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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<M, T> TranscriptionClientDyn for Twhere
T: TranscriptionClient<TranscriptionModel = M>,
M: TranscriptionModel + 'static,
impl<M, T> TranscriptionClientDyn for Twhere
T: TranscriptionClient<TranscriptionModel = M>,
M: TranscriptionModel + 'static,
Source§fn transcription_model<'a>(
&self,
model: &str,
) -> Box<dyn TranscriptionModelDyn + 'a>
fn transcription_model<'a>( &self, model: &str, ) -> Box<dyn TranscriptionModelDyn + 'a>
Create a transcription model with the given name.