-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Azure support; Update to .NET 8
- Loading branch information
Showing
25 changed files
with
199 additions
and
89 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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.0", | ||
"rollForward": "latestMajor", | ||
"allowPrerelease": true | ||
} | ||
} |
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,15 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>e883db38-8c66-433b-a1cf-301b5b3b2171</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.9" /> | ||
<PackageReference Include="OpenAI.ChatGPT.EntityFrameworkCore" Version="2.8.0" /> | ||
<PackageReference Include="OpenAI.ChatGPT.EntityFrameworkCore" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace OpenAI.ChatGpt; | ||
|
||
/// <summary> | ||
/// Azure OpenAI services client | ||
/// </summary> | ||
/// <remarks> | ||
/// Docs: https://learn.microsoft.com/en-us/azure/ai-services/openai/reference | ||
/// Models availability by zones: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models | ||
/// </remarks> | ||
public class AzureOpenAiClient : OpenAiClient | ||
{ | ||
private readonly string _apiVersion; | ||
private const string DefaultApiVersion = "2023-12-01-preview"; | ||
|
||
//https://github.com/Azure/azure-rest-api-specs/tree/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference | ||
|
||
/// <summary> | ||
/// Creates Azure OpenAI services client | ||
/// </summary> | ||
/// <param name="endpointUrl"> Endpoint URL like https://{your-resource-name}.openai.azure.com/</param> | ||
/// <param name="deploymentName"> Deployment name from the page https://oai.azure.com/deployment</param> | ||
/// <param name="azureKey">Azure OpenAI API Key</param> | ||
/// <param name="apiVersion">Azure OpenAI API version</param> | ||
/// <remarks> | ||
/// See currently available API versions: https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#completions | ||
/// </remarks> | ||
public AzureOpenAiClient( | ||
string endpointUrl, | ||
string deploymentName, | ||
string azureKey, | ||
string apiVersion = DefaultApiVersion) | ||
{ | ||
if (string.IsNullOrWhiteSpace(azureKey)) | ||
throw new ArgumentException("Value cannot be null or whitespace.", nameof(azureKey)); | ||
|
||
_apiVersion = apiVersion ?? throw new ArgumentNullException(nameof(apiVersion)); | ||
HttpClient = new HttpClient() | ||
{ | ||
BaseAddress = new Uri($"{endpointUrl}/openai/deployments/{deploymentName}/"), | ||
DefaultRequestHeaders = | ||
{ | ||
{ "api-key", azureKey } | ||
} | ||
}; | ||
IsHttpClientInjected = false; | ||
} | ||
|
||
public AzureOpenAiClient(HttpClient httpClient, string apiVersion) : base(httpClient) | ||
{ | ||
_apiVersion = apiVersion ?? throw new ArgumentNullException(nameof(apiVersion)); | ||
} | ||
|
||
protected override string GetChatCompletionsEndpoint() | ||
{ | ||
return $"chat/completions?api-version={_apiVersion}"; | ||
} | ||
} |
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
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
Oops, something went wrong.