enhance: supports Azure OpenAI REST API (#695)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-11-14 14:56:21 +08:00
parent 3c5a4741bf
commit e3ffe3ef6c
No known key found for this signature in database

View file

@ -155,7 +155,12 @@ namespace SourceGit.Models
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) }; var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(60) };
if (!string.IsNullOrEmpty(ApiKey)) 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"); var req = new StringContent(JsonSerializer.Serialize(chat, JsonCodeGen.Default.OpenAIChatRequest), Encoding.UTF8, "application/json");
try try