pub struct OpenAIEmbeddingClient { /* private fields */ }Expand description
An OpenAI (or OpenAI-compatible) embeddings client.
let client = OpenAIEmbeddingClient::from_env("text-embedding-3-small")?;
let batch = client
.get_embeddings(vec!["Hello, world!".into()], None)
.await?;
println!("{} dims", batch[0].dimensions());Implementations§
Source§impl OpenAIEmbeddingClient
impl OpenAIEmbeddingClient
Sourcepub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self
Create a client for the given API key and default embedding model.
Sourcepub fn from_env(model: impl Into<String>) -> Result<Self>
pub fn from_env(model: impl Into<String>) -> Result<Self>
Build a client from the environment: OPENAI_API_KEY (required) and
optional OPENAI_BASE_URL. The model falls back through
OPENAI_EMBEDDING_MODEL when the argument is empty — mirroring
upstream’s model or OPENAI_EMBEDDING_MODEL resolution.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Override the base URL (for OpenAI-compatible servers).
Sourcepub fn with_organization(self, org: impl Into<String>) -> Self
pub fn with_organization(self, org: impl Into<String>) -> Self
Set the organization header.
Trait Implementations§
Source§impl Clone for OpenAIEmbeddingClient
impl Clone for OpenAIEmbeddingClient
Source§fn clone(&self) -> OpenAIEmbeddingClient
fn clone(&self) -> OpenAIEmbeddingClient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl EmbeddingClient for OpenAIEmbeddingClient
impl EmbeddingClient for OpenAIEmbeddingClient
Source§fn get_embeddings<'life0, 'async_trait>(
&'life0 self,
values: Vec<String>,
options: Option<EmbeddingGenerationOptions>,
) -> Pin<Box<dyn Future<Output = Result<GeneratedEmbeddings>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_embeddings<'life0, 'async_trait>(
&'life0 self,
values: Vec<String>,
options: Option<EmbeddingGenerationOptions>,
) -> Pin<Box<dyn Future<Output = Result<GeneratedEmbeddings>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate embeddings for the given values (one per value, in order).
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAIEmbeddingClient
impl !UnwindSafe for OpenAIEmbeddingClient
impl Freeze for OpenAIEmbeddingClient
impl Send for OpenAIEmbeddingClient
impl Sync for OpenAIEmbeddingClient
impl Unpin for OpenAIEmbeddingClient
impl UnsafeUnpin for OpenAIEmbeddingClient
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