AzureClient

Struct AzureClient 

Source
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

Source

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.

Source

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");
Source

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
§Examples
use llm_kit_azure::AzureClient;

let client = AzureClient::new()
    .base_url("https://custom.endpoint.com/openai");
Source

pub fn api_key(self, api_key: impl Into<String>) -> Self

Sets the API key for authentication.

If not specified, the client will attempt to use the AZURE_API_KEY environment variable.

§Arguments
  • api_key - The API key
§Examples
use llm_kit_azure::AzureClient;

let client = AzureClient::new()
    .api_key("your-api-key");
Source

pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self

Adds a custom header to include in requests.

§Arguments
  • key - The header name
  • value - The header value
§Examples
use llm_kit_azure::AzureClient;

let client = AzureClient::new()
    .header("X-Custom-Header", "value");
Source

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);
Source

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");
Source

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);
Source

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

Source§

fn clone(&self) -> AzureClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AzureClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AzureClient

Source§

fn default() -> AzureClient

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,