forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project compiles and runs, but request errors
- Loading branch information
1 parent
1e0a8b0
commit 28c2c40
Showing
6 changed files
with
111 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod azure_key_credential; | ||
mod openai_key_credential; | ||
// mod openai_key_credential; | ||
|
||
pub(crate) use azure_key_credential::*; | ||
pub(crate) use openai_key_credential::*; | ||
// pub(crate) use openai_key_credential::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 51 additions & 1 deletion
52
sdk/openai/inference/src/clients/chat_completions_client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,51 @@ | ||
pub struct ChatCompletionsClient; | ||
use super::BaseOpenAIClientMethods; | ||
use crate::{request::CreateChatCompletionsRequest, response::CreateChatCompletionsResponse}; | ||
use azure_core::{Context, Method, Result}; | ||
|
||
pub trait ChatCompletionsClientMethods { | ||
#[allow(async_fn_in_trait)] | ||
async fn create_chat_completions( | ||
&self, | ||
deployment_name: impl AsRef<str>, | ||
chat_completions_request: &CreateChatCompletionsRequest, | ||
) -> Result<CreateChatCompletionsResponse>; | ||
} | ||
|
||
pub struct ChatCompletionsClient { | ||
base_client: Box<dyn BaseOpenAIClientMethods>, | ||
} | ||
|
||
impl ChatCompletionsClient { | ||
pub fn new(base_client: Box<dyn BaseOpenAIClientMethods>) -> Self { | ||
Self { base_client } | ||
} | ||
} | ||
|
||
impl ChatCompletionsClientMethods for ChatCompletionsClient { | ||
async fn create_chat_completions( | ||
&self, | ||
deployment_name: impl AsRef<str>, | ||
chat_completions_request: &CreateChatCompletionsRequest, | ||
) -> Result<CreateChatCompletionsResponse> { | ||
let base_url = self.base_client.base_url(Some(deployment_name.as_ref()))?; | ||
let request_url = base_url.join("chat/completions")?; | ||
|
||
let context = Context::new(); | ||
|
||
let mut request = azure_core::Request::new(request_url, Method::Post); | ||
// this was replaced by the AzureServiceVersion policy, not sure what is the right approach | ||
// adding the mandatory header shouldn't be necessary if the pipeline was setup correctly (?) | ||
// request.add_mandatory_header(&self.key_credential); | ||
|
||
request.set_json(chat_completions_request)?; | ||
|
||
let response = self | ||
.base_client | ||
.pipeline() | ||
.send::<CreateChatCompletionsResponse>(&context, &mut request) | ||
.await?; | ||
response.into_body().json().await | ||
|
||
// todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
pub mod azure_openai_client; | ||
pub mod chat_completions_client; | ||
pub mod openai_client; | ||
mod azure_openai_client; | ||
mod chat_completions_client; | ||
mod openai_client; | ||
|
||
pub use azure_openai_client::{AzureOpenAIClient, AzureOpenAIClientMethods}; | ||
pub use chat_completions_client::{ChatCompletionsClient, ChatCompletionsClientMethods}; | ||
|
||
pub trait BaseOpenAIClientMethods { | ||
fn base_url(&self, deployment_name: Option<&str>) -> azure_core::Result<azure_core::Url>; | ||
|
||
fn pipeline(&self) -> &azure_core::Pipeline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
mod auth; | ||
mod clients; | ||
pub mod clients; | ||
mod models; | ||
mod options; | ||
|
||
pub use clients::azure_openai_client::*; | ||
pub use clients::openai_client::*; | ||
pub use models::*; | ||
pub use options::*; |