pub struct AzureClient { /* private fields */ }Expand description
Builder for creating an Azure OpenAI provider.
Provides a fluent API for constructing an AzureOpenAIProvider with various configuration options.
§Examples
§Basic Usage with Resource Name
use llm_kit_azure::AzureClient;
let provider = AzureClient::new()
.resource_name("my-azure-resource")
.api_key("your-api-key")
.build();
let model = provider.chat_model("gpt-4-deployment");§Custom Base URL
use llm_kit_azure::AzureClient;
let provider = AzureClient::new()
.base_url("https://my-resource.openai.azure.com/openai")
.api_key("your-api-key")
.build();
let model = provider.chat_model("gpt-4-deployment");§With Custom Headers and API Version
use llm_kit_azure::AzureClient;
let provider = AzureClient::new()
.resource_name("my-resource")
.api_key("your-api-key")
.api_version("2024-02-15-preview")
.header("X-Custom-Header", "value")
.build();
let model = provider.chat_model("gpt-4-deployment");§Deployment-Based URLs (Legacy Format)
use llm_kit_azure::AzureClient;
let provider = AzureClient::new()
.resource_name("my-resource")
.api_key("your-api-key")
.use_deployment_based_urls(true)
.build();
let model = provider.chat_model("gpt-4-deployment");Implementations§
Source§impl AzureClient
impl AzureClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new client builder with default settings.
The default API version is “v1” and uses the v1 API URL format.
If no API key is provided, it will attempt to use the AZURE_API_KEY environment variable.
If no resource name or base URL is provided, it will attempt to use the AZURE_RESOURCE_NAME
or AZURE_BASE_URL environment variables.
Sourcepub fn resource_name(self, resource_name: impl Into<String>) -> Self
pub fn resource_name(self, resource_name: impl Into<String>) -> Self
Sets the Azure OpenAI resource name.
The resource name is used to construct the base URL:
https://{resource_name}.openai.azure.com/openai
§Arguments
resource_name- The Azure OpenAI resource name
§Examples
use llm_kit_azure::AzureClient;
let client = AzureClient::new()
.resource_name("my-azure-resource");Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Sets a custom base URL for API calls.
When set, this takes precedence over resource_name.
§Arguments
base_url- The base URL (e.g., “https://my-resource.openai.azure.com/openai”)
§Examples
use llm_kit_azure::AzureClient;
let client = AzureClient::new()
.base_url("https://custom.endpoint.com/openai");Sourcepub fn headers(self, headers: HashMap<String, String>) -> Self
pub fn headers(self, headers: HashMap<String, String>) -> Self
Sets multiple custom headers at once.
§Arguments
headers- A HashMap of header names to values
§Examples
use llm_kit_azure::AzureClient;
use std::collections::HashMap;
let mut headers = HashMap::new();
headers.insert("X-Custom-1".to_string(), "value1".to_string());
headers.insert("X-Custom-2".to_string(), "value2".to_string());
let client = AzureClient::new()
.headers(headers);Sourcepub fn api_version(self, api_version: impl Into<String>) -> Self
pub fn api_version(self, api_version: impl Into<String>) -> Self
Sets the API version to use in requests.
Azure OpenAI requires an API version parameter in all requests. Defaults to “v1” if not specified.
Common versions include:
- “2023-05-15”
- “2024-02-15-preview”
- “v1” (default)
§Arguments
api_version- The API version string
§Examples
use llm_kit_azure::AzureClient;
let client = AzureClient::new()
.api_version("2024-02-15-preview");Sourcepub fn use_deployment_based_urls(self, use_deployment_based_urls: bool) -> Self
pub fn use_deployment_based_urls(self, use_deployment_based_urls: bool) -> Self
Sets whether to use deployment-based URLs.
When true, uses legacy format:
{base_url}/deployments/{deployment_id}{path}?api-version={version}
When false (default), uses v1 API format:
{base_url}/v1{path}?api-version={version}
§Arguments
use_deployment_based_urls- Whether to use deployment-based URLs
§Examples
use llm_kit_azure::AzureClient;
let client = AzureClient::new()
.use_deployment_based_urls(true);Sourcepub fn build(self) -> AzureOpenAIProvider
pub fn build(self) -> AzureOpenAIProvider
Builds the Azure OpenAI provider.
This method constructs the provider settings from the builder configuration
and creates an AzureOpenAIProvider instance.
§Panics
Panics if neither resource name nor base URL is provided (either via builder or environment variables).
§Examples
use llm_kit_azure::AzureClient;
let provider = AzureClient::new()
.resource_name("my-resource")
.api_key("your-api-key")
.build();Trait Implementations§
Source§impl Clone for AzureClient
impl Clone for AzureClient
Source§fn clone(&self) -> AzureClient
fn clone(&self) -> AzureClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more