summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-26 13:48:55 +0800
committerGitHub <noreply@github.com>2024-06-26 13:48:55 +0800
commit2e1dc1f7d58f037e83a184f4c9e662696d1425be (patch)
tree6530c186a24b5a9d0897812675dd0471af7a1ce9
parent95bad975f4fb47fe86df1837660a1341009ea12a (diff)
downloadaichat-2e1dc1f7d58f037e83a184f4c9e662696d1425be.tar.gz
refactor: improve azure-openai (#652)
-rwxr-xr-xArgcfile.sh32
-rw-r--r--src/client/azure_openai.rs12
2 files changed, 29 insertions, 15 deletions
diff --git a/Argcfile.sh b/Argcfile.sh
index 5f04b6f..7433e26 100755
--- a/Argcfile.sh
+++ b/Argcfile.sh
@@ -159,7 +159,11 @@ models() {
# @flag -S --no-stream
# @arg text~
chat-openai-compatible() {
- _openai_chat "$@"
+ _wrapper curl -i "$argc_api_base/chat/completions" \
+-X POST \
+-H "Content-Type: application/json" \
+-H "Authorization: Bearer $argc_api_key" \
+-d "$(_build_body openai "$@")"
}
# @cmd List models by openai-compatible api
@@ -169,6 +173,20 @@ models-openai-compatible() {
_openai_models
}
+# @cmd Chat with azure-openai api
+# @option --api-url! $$
+# @option --api-key! $$
+# @option -m --model! $$
+# @flag -S --no-stream
+# @arg text~
+chat-azure-openai() {
+ _wrapper curl -i "$argc_api_url" \
+-X POST \
+-H "Content-Type: application/json" \
+-H "api-key: $argc_api_key" \
+-d "$(_build_body openai "$@")"
+}
+
# @cmd Chat with gemini api
# @env GEMINI_API_KEY!
# @option -m --model=gemini-1.0-pro-latest $GEMINI_MODEL
@@ -397,20 +415,10 @@ _argc_before() {
fi
}
-_openai_chat() {
- api_base="${api_base:-"$argc_api_base"}"
- api_key="${api_key:-"$argc_api_key"}"
- _wrapper curl -i $curl_args "$api_base/chat/completions" \
--X POST \
--H "Content-Type: application/json" \
--H "Authorization: Bearer $api_key" \
--d "$(_build_body openai "$@")"
-}
-
_openai_models() {
api_base="${api_base:-"$argc_api_base"}"
api_key="${api_key:-"$argc_api_key"}"
- _wrapper curl $curl_args "$api_base/models" \
+ _wrapper curl "$api_base/models" \
-H "Authorization: Bearer $api_key" \
}
diff --git a/src/client/azure_openai.rs b/src/client/azure_openai.rs
index 058a53e..e3e9f16 100644
--- a/src/client/azure_openai.rs
+++ b/src/client/azure_openai.rs
@@ -49,7 +49,7 @@ impl AzureOpenAIClient {
self.model.name()
);
- debug!("AzureOpenAI Request: {url} {body}");
+ debug!("AzureOpenAI Chat Completions Request: {url} {body}");
let builder = client.post(url).header("api-key", api_key).json(&body);
@@ -66,9 +66,15 @@ impl AzureOpenAIClient {
let body = openai_build_embeddings_body(data, &self.model);
- let url = format!("{api_base}/embeddings");
+ let url = format!(
+ "{}/openai/deployments/{}/embeddings?api-version=2024-02-01",
+ &api_base,
+ self.model.name()
+ );
+
+ debug!("AzureOpenAI Embeddings Request: {url} {body}");
- let builder = client.post(url).bearer_auth(api_key).json(&body);
+ let builder = client.post(url).header("api-key", api_key).json(&body);
Ok(builder)
}