From e3ffe3ef6cb69d761e026772c42e15abb803d121 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 14 Nov 2024 14:56:21 +0800 Subject: [PATCH] enhance: supports Azure OpenAI REST API (#695) Signed-off-by: leo --- src/Models/OpenAI.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Models/OpenAI.cs b/src/Models/OpenAI.cs index e9c7b5ed..0a83d8dc 100644 --- a/src/Models/OpenAI.cs +++ b/src/Models/OpenAI.cs @@ -155,7 +155,12 @@ namespace SourceGit.Models var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) }; if (!string.IsNullOrEmpty(ApiKey)) - client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}"); + { + if (Server.Contains("openai.azure.com/", StringComparison.Ordinal)) + client.DefaultRequestHeaders.Add("api-key", ApiKey); + else + client.DefaultRequestHeaders.Add("Authorization", $"Bearer {ApiKey}"); + } var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest), Encoding.UTF8, "application/json"); try