pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
auth: impl Into<AzureOpenAIAuth>,
api_version: &str,
azure_endpoint: &str,
) -> Self
pub fn new( auth: impl Into<AzureOpenAIAuth>, api_version: &str, azure_endpoint: &str, ) -> Self
Creates a new Azure OpenAI client.
§Arguments
auth- Azure OpenAI API key or token required for authenticationapi_version- API version to use (e.g., “2024-10-21” for GA, “2024-10-01-preview” for preview)azure_endpoint- Azure OpenAI endpoint URL, for example: https://{your-resource-name}.openai.azure.com
Sourcepub fn from_api_key(
api_key: &str,
api_version: &str,
azure_endpoint: &str,
) -> Self
pub fn from_api_key( api_key: &str, api_version: &str, azure_endpoint: &str, ) -> Self
Creates a new Azure OpenAI client from an API key.
§Arguments
api_key- Azure OpenAI API key required for authenticationapi_version- API version to use (e.g., “2024-10-21” for GA, “2024-10-01-preview” for preview)azure_endpoint- Azure OpenAI endpoint URL
Sourcepub fn from_token(token: &str, api_version: &str, azure_endpoint: &str) -> Self
pub fn from_token(token: &str, api_version: &str, azure_endpoint: &str) -> Self
Creates a new Azure OpenAI client from a token.
§Arguments
token- Azure OpenAI token required for authenticationapi_version- API version to use (e.g., “2024-10-21” for GA, “2024-10-01-preview” for preview)azure_endpoint- Azure OpenAI endpoint URL
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create a new Azure OpenAI client from the AZURE_API_KEY or AZURE_TOKEN, AZURE_API_VERSION, and AZURE_ENDPOINT environment variables.
Sourcepub fn embedding_model(&self, model: &str) -> EmbeddingModel
pub fn embedding_model(&self, model: &str) -> 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
§Example
use rig::providers::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let embedding_model = azure.embedding_model(azure::TEXT_EMBEDDING_3_LARGE);Sourcepub fn embedding_model_with_ndims(
&self,
model: &str,
ndims: usize,
) -> EmbeddingModel
pub fn embedding_model_with_ndims( &self, model: &str, ndims: usize, ) -> EmbeddingModel
Create an embedding model with the given name and the number of dimensions in the embedding generated by the model.
§Example
use rig::providers::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let embedding_model = azure.embedding_model("model-unknown-to-rig", 3072);Sourcepub fn embeddings<D: Embed>(
&self,
model: &str,
) -> EmbeddingsBuilder<EmbeddingModel, D>
pub fn embeddings<D: Embed>( &self, model: &str, ) -> EmbeddingsBuilder<EmbeddingModel, D>
Create an embedding builder with the given embedding model.
§Example
use rig::providers::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let embeddings = azure.embeddings(azure::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::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let gpt4 = azure.completion_model(azure::GPT_4);Sourcepub fn transcription_model(&self, model: &str) -> TranscriptionModel
pub fn transcription_model(&self, model: &str) -> TranscriptionModel
Create a transcription model with the given name.
§Example
use rig::providers::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let whisper = azure.transcription_model("model-unknown-to-rig");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::azure::{Client, self};
// Initialize the Azure OpenAI client
let azure = Client::new("YOUR_API_KEY", "YOUR_API_VERSION", "YOUR_ENDPOINT");
let agent = azure.agent(azure::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.