Skip to content

Commit

Permalink
Made auth classes private
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalvarezl committed Sep 13, 2024
1 parent 7ae0883 commit c0eeef5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
45 changes: 22 additions & 23 deletions sdk/openai/inference/src/clients/azure_openai_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ impl AzureOpenAIClient {
client_options: Option<AzureOpenAIClientOptions>,
) -> Result<Self> {
let endpoint = Url::parse(endpoint.as_ref())?;
let key_credential = AzureKeyCredential::new(secret.into());

let options = client_options.unwrap_or_default();
let auth_policy: Arc<dyn Policy> = key_credential.clone().into();

let auth_policy: Arc<dyn Policy> = AzureKeyCredential::new(secret.into()).into();
let version_policy: Arc<dyn Policy> = options.api_service_version.clone().into();
let per_call_policies: Vec<Arc<dyn Policy>> = vec![auth_policy, version_policy];

let pipeline = Self::new_pipeline(per_call_policies, options.client_options.clone());
let pipeline = new_pipeline(per_call_policies, options.client_options.clone());

Ok(AzureOpenAIClient {
endpoint,
Expand All @@ -37,24 +37,6 @@ impl AzureOpenAIClient {
})
}

fn new_pipeline(
per_call_policies: Vec<Arc<dyn Policy>>,
options: azure_core::ClientOptions,
) -> azure_core::Pipeline {
let crate_name = option_env!("CARGO_PKG_NAME");
let crate_version = option_env!("CARGO_PKG_VERSION");
// should I be using per_call_policies here too or are they used by default on retries too?
let per_retry_policies = Vec::new();

azure_core::Pipeline::new(
crate_name,
crate_version,
options,
per_call_policies,
per_retry_policies,
)
}

pub fn endpoint(&self) -> &Url {
&self.endpoint
}
Expand All @@ -69,8 +51,7 @@ impl AzureOpenAIClient {
) -> Result<CreateChatCompletionsResponse> {
let url = Url::parse(&format!(
"{}/openai/deployments/{}/chat/completions",
&self.endpoint,
deployment_name
&self.endpoint, deployment_name
))?;

let context = Context::new();
Expand All @@ -89,3 +70,21 @@ impl AzureOpenAIClient {
response.into_body().json().await
}
}

fn new_pipeline(
per_call_policies: Vec<Arc<dyn Policy>>,
options: azure_core::ClientOptions,
) -> azure_core::Pipeline {
let crate_name = option_env!("CARGO_PKG_NAME");
let crate_version = option_env!("CARGO_PKG_VERSION");
// should I be using per_call_policies here too or are they used by default on retries too?
let per_retry_policies = Vec::new();

azure_core::Pipeline::new(
crate_name,
crate_version,
options,
per_call_policies,
per_retry_policies,
)
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@

pub struct ChatCompletionsClient;
2 changes: 1 addition & 1 deletion sdk/openai/inference/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod auth;
mod auth;
mod clients;
mod models;
mod options;
Expand Down
4 changes: 2 additions & 2 deletions sdk/openai/inference/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod service_version;
mod azure_openai_client_options;
mod openai_client_options;
mod service_version;

pub use service_version::AzureServiceVersion;
pub use azure_openai_client_options::*;
pub use openai_client_options::*;
pub use service_version::AzureServiceVersion;
7 changes: 5 additions & 2 deletions sdk/openai/inference/src/options/service_version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::sync::Arc;
use async_trait::async_trait;
use std::sync::Arc;

use azure_core::{Context, Policy, PolicyResult, Request};

Expand Down Expand Up @@ -50,7 +50,10 @@ impl Policy for AzureServiceVersion {
request: &mut Request,
next: &[Arc<dyn Policy>],
) -> PolicyResult {
request.url_mut().query_pairs_mut().append_pair("api-version", &self.to_string());
request
.url_mut()
.query_pairs_mut()
.append_pair("api-version", &self.to_string());
next[0].send(ctx, request, &next[1..]).await
}
}
Expand Down

0 comments on commit c0eeef5

Please sign in to comment.