pub struct Client { /* private fields */ }
Implementations§
source§impl Client
impl Client
sourcepub fn from_url(api_key: &str, base_url: &str) -> Self
pub fn from_url(api_key: &str, base_url: &str) -> Self
Create a new OpenAI client with the given API key and base API URL.
sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new OpenAI client from the OPENAI_API_KEY
environment variable.
Panics if the environment variable is not set.
sourcepub fn embedding_model(&self, model: &str) -> EmbeddingModel
pub fn embedding_model(&self, model: &str) -> EmbeddingModel
Create an embedding 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 embedding_model = openai.embedding_model(openai::TEXT_EMBEDDING_3_LARGE);
sourcepub fn embeddings(&self, model: &str) -> EmbeddingsBuilder<EmbeddingModel>
pub fn embeddings(&self, model: &str) -> EmbeddingsBuilder<EmbeddingModel>
Create an embedding builder with the given embedding model.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let embeddings = openai.embeddings(openai::TEXT_EMBEDDING_3_LARGE)
.simple_document("doc0", "Hello, world!")
.simple_document("doc1", "Goodbye, world!")
.build()
.await
.expect("Failed to embed documents");
sourcepub fn completion_model(&self, model: &str) -> CompletionModel
pub fn completion_model(&self, model: &str) -> 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);
sourcepub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
pub fn agent(&self, model: &str) -> AgentBuilder<CompletionModel>
Create an agent builder with the given completion model.
§Example
use rig::providers::openai::{Client, self};
// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");
let agent = openai.agent(openai::GPT_4)
.preamble("You are comedian AI with a mission to make people laugh.")
.temperature(0.0)
.build();
sourcepub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>(
&self,
model: &str,
) -> ExtractorBuilder<T, CompletionModel>
pub fn extractor<T: JsonSchema + for<'a> Deserialize<'a> + Serialize + Send + Sync>( &self, model: &str, ) -> ExtractorBuilder<T, CompletionModel>
Create an extractor builder with the given completion model.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)