Skip to content

Commit

Permalink
Added docs for ChatCompletionsClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalvarezl committed Sep 19, 2024
1 parent 0f0d7f1 commit 1ccac95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion sdk/openai/inference/src/clients/azure_openai_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl AzureOpenAIClient {
}

impl AzureOpenAIClientMethods for AzureOpenAIClient {

/// Returns the endpoint [`Url`] of the client.
fn endpoint(&self) -> &Url {
&self.endpoint
Expand Down
24 changes: 24 additions & 0 deletions sdk/openai/inference/src/clients/chat_completions_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ use crate::{
use azure_core::{Context, Method, Response, Result};
use futures::{Stream, StreamExt};

/// A [`ChatCompletionsClient`]'s methods. This trait can be used for mocking.
pub trait ChatCompletionsClientMethods {
/// Creates a new chat completion.
///
/// # Arguments
/// * `deployment_name` - The name of the deployment in Azure. In OpenAI it is the model name to be used.
/// * `chat_completions_request` - The request specifying the chat completion to be created.
#[allow(async_fn_in_trait)]
async fn create_chat_completions(
&self,
deployment_name: impl AsRef<str>,
chat_completions_request: &CreateChatCompletionsRequest,
) -> Result<Response<CreateChatCompletionsResponse>>;

/// Creates a new chat completion and returns a streamed response.
///
/// # Arguments
/// * `deployment_name` - The name of the deployment in Azure. In OpenAI it is the model name to be used.
/// * `chat_completions_request` - The request specifying the chat completion to be created.
#[allow(async_fn_in_trait)]
async fn stream_chat_completions(
&self,
Expand All @@ -23,7 +34,9 @@ pub trait ChatCompletionsClientMethods {
) -> Result<impl Stream<Item = Result<CreateChatCompletionsStreamResponse>>>;
}

/// A client for Chat Completions related operations.
pub struct ChatCompletionsClient {
/// The underlying HTTP client with an associated pipeline.
base_client: Box<dyn BaseOpenAIClientMethods>,
}

Expand All @@ -34,6 +47,11 @@ impl ChatCompletionsClient {
}

impl ChatCompletionsClientMethods for ChatCompletionsClient {
/// Creates a new chat completion.
///
/// # Arguments
/// * `deployment_name` - The name of the deployment in Azure. In OpenAI it is the model name to be used.
/// * `chat_completions_request` - The request specifying the chat completion to be created.
async fn create_chat_completions(
&self,
deployment_name: impl AsRef<str>,
Expand All @@ -50,6 +68,11 @@ impl ChatCompletionsClientMethods for ChatCompletionsClient {
.await
}

/// Creates a new chat completion and returns a streamed response.
///
/// # Arguments
/// * `deployment_name` - The name of the deployment in Azure. In OpenAI it is the model name to be used.
/// * `chat_completions_request` - The request specifying the chat completion to be created.
async fn stream_chat_completions(
&self,
deployment_name: impl AsRef<str>,
Expand All @@ -71,6 +94,7 @@ impl ChatCompletionsClientMethods for ChatCompletionsClient {
}
}

/// A placeholder type to provide an implementation for the [`EventStreamer`] trait specifically for chat completions.
struct ChatCompletionsStreamHandler;

impl EventStreamer<CreateChatCompletionsStreamResponse> for ChatCompletionsStreamHandler {
Expand Down

0 comments on commit 1ccac95

Please sign in to comment.