Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI-DotNet 6.3.2 #55

Merged
merged 6 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ jobs:
- name: Build Pack and Publish NuGet Package
run: |
$projectPath = "${{ github.workspace }}\OpenAI-DotNet"
dotnet build $projectPath --configuration Release
dotnet build --configuration Release
dotnet pack $projectPath --configuration Release --include-symbols
$out = "$projectPath\bin\Release"
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Recurse -ErrorAction SilentlyContinue
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Exclude '*symbols*' -Recurse -ErrorAction SilentlyContinue

if ($packagePath) {
Write-Host Package path: $packagePath
Expand All @@ -59,7 +60,7 @@ jobs:
$isRelease = "${{ github.ref == 'refs/heads/main' }}"

if ($isRelease -eq 'true') {
dotnet nuget push $packagePath --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push $packagePath.FullName --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}

$version = $packagePath.Name -replace "^OpenAI-DotNet.(.*).nupkg$",'$1'
Expand All @@ -70,5 +71,7 @@ jobs:
if: always()
with:
name: OpenAI-DotNet.${{ env.PACKAGE_VERSION }}
path: ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
path: |
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.symbols.nupkg
if-no-files-found: ignore
16 changes: 16 additions & 0 deletions OpenAI-DotNet-Proxy/OpenAI-DotNet-Proxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>OpenAI_DotNet_Proxy</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<LangVersion>latest</LangVersion>
<OutputPath>..\OpenAI-DotNet\bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenAI-DotNet\OpenAI-DotNet.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Net.Http.Headers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Authentication;
using System.Threading.Tasks;
using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue;

namespace OpenAI.Proxy
{
Expand All @@ -21,6 +23,30 @@ public class OpenAIProxyStartup
private OpenAIClient openAIClient;
private IAuthenticationFilter authenticationFilter;

// Copied from https://github.com/microsoft/reverse-proxy/blob/51d797986b1fea03500a1ad173d13a1176fb5552/src/ReverseProxy/Forwarder/RequestUtilities.cs#L61-L83
private static readonly HashSet<string> ExcludedHeaders = new HashSet<string>()
{
HeaderNames.Connection,
HeaderNames.TransferEncoding,
HeaderNames.KeepAlive,
HeaderNames.Upgrade,
"Proxy-Connection",
"Proxy-Authenticate",
"Proxy-Authentication-Info",
"Proxy-Authorization",
"Proxy-Features",
"Proxy-Instruction",
"Security-Scheme",
"ALPN",
"Close",
HeaderNames.TE,
#if NET
HeaderNames.AltSvc,
#else
"Alt-Svc",
#endif
};

public void ConfigureServices(IServiceCollection services) { }

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down Expand Up @@ -74,8 +100,10 @@ private static async Task HealthEndpoint(HttpContext context)
{
// Respond with a 200 OK status code and a plain text message
context.Response.StatusCode = StatusCodes.Status200OK;
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync("OK");
const string contentType = "text/plain";
context.Response.ContentType = contentType;
const string content = "OK";
await context.Response.WriteAsync(content);
}

/// <summary>
Expand All @@ -101,19 +129,22 @@ private async Task HandleRequest(HttpContext httpContext, string endpoint)
var proxyResponse = await openAIClient.Client.SendAsync(openAIRequest, HttpCompletionOption.ResponseHeadersRead);
httpContext.Response.StatusCode = (int)proxyResponse.StatusCode;

foreach (var header in proxyResponse.Headers)
foreach (var (key, value) in proxyResponse.Headers)
{
httpContext.Response.Headers[header.Key] = header.Value.ToArray();
if (ExcludedHeaders.Contains(key)) { continue; }
httpContext.Response.Headers[key] = value.ToArray();
}

foreach (var header in proxyResponse.Content.Headers)
foreach (var (key, value) in proxyResponse.Content.Headers)
{
httpContext.Response.Headers[header.Key] = header.Value.ToArray();
if (ExcludedHeaders.Contains(key)) { continue; }
httpContext.Response.Headers[key] = value.ToArray();
}

httpContext.Response.ContentType = proxyResponse.Content.Headers.ContentType?.ToString() ?? string.Empty;
const string streamingContent = "text/event-stream";

if (httpContext.Response.ContentType.Equals("text/event-stream"))
if (httpContext.Response.ContentType.Equals(streamingContent))
{
var stream = await proxyResponse.Content.ReadAsStreamAsync();
await WriteServerStreamEventsAsync(httpContext, stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\OpenAI-DotNet-Proxy\OpenAI-DotNet-Proxy.csproj" />
<ProjectReference Include="..\OpenAI-DotNet\OpenAI-DotNet.csproj" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion OpenAI-DotNet-Tests/TestFixture_01_Models.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace OpenAI.Tests
Expand All @@ -20,7 +21,7 @@ public async Task Test_2_RetrieveModelDetails()
var models = await OpenAIClient.ModelsEndpoint.GetModelsAsync();
Console.WriteLine($"Found {models.Count} models!");

foreach (var model in models)
foreach (var model in models.OrderBy(model => model.Id))
{
Console.WriteLine($"{model.Id} | Owner: {model.OwnedBy}");

Expand Down
6 changes: 6 additions & 0 deletions OpenAI-DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI-DotNet", "OpenAI-DotNet\OpenAI-DotNet.csproj", "{76B6480E-154A-4341-B530-AFE04B254360}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI-DotNet-Proxy", "OpenAI-DotNet-Proxy\OpenAI-DotNet-Proxy.csproj", "{A4D454D4-C21C-49D3-85A7-B4950358C6E7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI-DotNet-Tests", "OpenAI-DotNet-Tests\OpenAI-DotNet-Tests.csproj", "{066EC5A5-47CE-4B91-B924-F236644037C1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAI-DotNet-Tests-Proxy", "OpenAI-DotNet-Tests-Proxy\OpenAI-DotNet-Tests-Proxy.csproj", "{F8B5D079-FD33-4A9E-92C4-CC88C911CFF3}"
Expand All @@ -19,6 +21,10 @@ Global
{76B6480E-154A-4341-B530-AFE04B254360}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76B6480E-154A-4341-B530-AFE04B254360}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76B6480E-154A-4341-B530-AFE04B254360}.Release|Any CPU.Build.0 = Release|Any CPU
{A4D454D4-C21C-49D3-85A7-B4950358C6E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4D454D4-C21C-49D3-85A7-B4950358C6E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4D454D4-C21C-49D3-85A7-B4950358C6E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4D454D4-C21C-49D3-85A7-B4950358C6E7}.Release|Any CPU.Build.0 = Release|Any CPU
{066EC5A5-47CE-4B91-B924-F236644037C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{066EC5A5-47CE-4B91-B924-F236644037C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{066EC5A5-47CE-4B91-B924-F236644037C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
3 changes: 2 additions & 1 deletion OpenAI-DotNet/Audio/AudioEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
namespace OpenAI.Audio
{
/// <summary>
/// Speech to text.
/// Transforms audio into text.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/audio"/>
/// </summary>
public sealed class AudioEndpoint : BaseEndPoint
{
Expand Down
4 changes: 4 additions & 0 deletions OpenAI-DotNet/Chat/ChatEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace OpenAI.Chat
{
/// <summary>
/// Given a chat conversation, the model will return a chat completion response.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/chat"/>
/// </summary>
public sealed class ChatEndpoint : BaseEndPoint
{
/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Completions/CompletionsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace OpenAI.Completions
/// The way you “program” the API to do a task is by simply describing the task in plain english or providing
/// a few written examples. This simple approach works for a wide range of use cases, including summarization,
/// translation, grammar correction, question answering, chatbots, composing emails, and much more
/// (see the prompt library for inspiration).
/// (see the prompt library for inspiration).<br/>
/// <see href="https://beta.openai.com/docs/api-reference/completions"/>
/// </summary>
public sealed class CompletionsEndpoint : BaseEndPoint
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Edits/EditsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI.Edits
{
/// <summary>
/// Given a prompt and an instruction, the model will return an edited version of the prompt.
/// Given a prompt and an instruction, the model will return an edited version of the prompt.<br/>
/// <see href="https://beta.openai.com/docs/api-reference/edits"/>
/// </summary>
public sealed class EditsEndpoint : BaseEndPoint
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Embeddings/EmbeddingsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace OpenAI.Embeddings
{
/// <summary>
/// Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.
/// Get a vector representation of a given input that can be easily consumed by machine learning models and algorithms.<br/>
/// <see href="https://beta.openai.com/docs/guides/embeddings"/>
/// </summary>
public sealed class EmbeddingsEndpoint : BaseEndPoint
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Files/FilesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace OpenAI.Files
{
/// <summary>
/// Files are used to upload documents that can be used with features like Fine-tuning.
/// Files are used to upload documents that can be used with features like Fine-tuning.<br/>
/// <see href="https://beta.openai.com/docs/api-reference/fine-tunes"/>
/// </summary>
public class FilesEndpoint : BaseEndPoint
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/FineTuning/FineTuningEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace OpenAI.FineTuning
{
/// <summary>
/// Manage fine-tuning jobs to tailor a model to your specific training data.
/// Manage fine-tuning jobs to tailor a model to your specific training data.<br/>
/// <see href="https://beta.openai.com/docs/guides/fine-tuning"/>
/// </summary>
public class FineTuningEndpoint : BaseEndPoint
Expand Down
3 changes: 2 additions & 1 deletion OpenAI-DotNet/Images/ImagesEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace OpenAI.Images
{
/// <summary>
/// Creates an image given a prompt.
/// Given a prompt and/or an input image, the model will generate a new image.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/images"/>
/// </summary>
public sealed class ImagesEndpoint : BaseEndPoint
{
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Moderations/ModerationsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenAI.Moderations
{
/// <summary>
/// The moderation endpoint is a tool you can use to check whether content complies with OpenAI's content policy.
/// Developers can thus identify content that our content policy prohibits and take action, for instance by filtering it.
/// Developers can thus identify content that our content policy prohibits and take action, for instance by filtering it.<br/>
/// <see href="https://beta.openai.com/docs/api-reference/moderations"/>
/// </summary>
public sealed class ModerationsEndpoint : BaseEndPoint
Expand Down
93 changes: 8 additions & 85 deletions OpenAI-DotNet/OpenAI-DotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,104 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Stephen Hodgson</Authors>
<Product>OpenAI-DotNet</Product>
<Description>A simple C# .NET client library for OpenAI to use chat-gpt, gpt-4, gpt-3.5-turbo and Dall-E though their RESTful API (currently in beta). Independently developed, this is not an official library and I am not affiliated with OpenAI. An OpenAI API account is required.

Forked from [OpenAI-API-dotnet](https://github.com/OkGoDoIt/OpenAI-API-dotnet).

More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet-api).
</Description>
<Copyright>2023</Copyright>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageLicenseExpression>CC0-1.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/RageAgainstThePixel/OpenAI-DotNet</PackageProjectUrl>
<RepositoryUrl>https://github.com/RageAgainstThePixel/OpenAI-DotNet</RepositoryUrl>
<PackageTags>OpenAI, AI, ML, API, gpt-4, gpt-3.5-tubo, gpt-3, chatGPT, chat-gpt, gpt-2, gpt</PackageTags>
<Title>OpenAI API</Title>
<PackageReleaseNotes>Bump version to 6.3.1
- Fixed apikey requiring sk- prefix with Azure OpenAI
Bump version to 6.3.0
- Removed OpenAI-DotNet-Proxy and put it directly in packge on its own
Bump version to 6.2.0
- Added OpenAI-DotNet-Proxy project and package.
- Added support for custom domains
- Updated unit tests
- Updated docs
Bump version to 6.1.0
- Added support for gpt-4 models
Bump version to 6.0.1
- Updated package info
- Updated docs
Bump version to 6.0.0
- Added support for Azure OpenAI
Bump version to 5.1.2
- Fixed an issue when deleting personal account fine tuned models
Bump version to 5.1.1
- Refactored Model validation
- Added additional default models
- Deprecate OpenAIClient.DefaultModel
- Implemented chat completion streaming
- Refactored immutable types
Bump version to 5.1.0
- Add support for Audio endpoint and Whisper models
- Audio Speech to text
- Audio translation
Bump version to 5.0.2
- Support multiple inputs in embedding
- Added better model validation in all endpoints
Bump version to 5.0.1
- Fixed chat parameters
Bump version to 5.0.0
- Added Chat endpoint
Bump version to 4.4.4
- ImageEditRequest mask is now optional so long as texture has alpha transparency
- ImageVariationRequest added constructor overload for memory stream image
- Updated AuthInfo parameter validation
- Renamed OPEN_AI_ORGANIZATION_ID -&gt; OPENAI_ORGANIZATION_ID
Bump version to 4.4.3
- added `OPEN_AI_ORGANIZATION_ID` environment variable
- deprecated `Organization` use `OrganizationId` instead
Bump version to 4.4.2
- Removed a useless assert
- Updated docs
Bump version to 4.4.1
- hotfix to CompletionsEndpoint to use IEnumerable&lt;string&gt;
- hotfix to cleanup Images endpoints
Bump version to 4.4.0
- Renamed Choice.Logprobs -&gt; Choice.LogProbabilities
- Renamed OpenAI.Completions.Logprobs -&gt; OpenAI.Completions.OpenAI.Completions
- Renamed CompletionRequest parameter names:
- max_tokens -&gt; maxTokens
- top_p -&gt; topP
- Updated CompletionRequest to accept IEnumerable&lt;string&gt; values for prompts and stopSequences
- Refactored all endpoints to use new response validation extension
- Added `CancellationToken` to most endpoints that had long running operations</PackageReleaseNotes>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
<PackageId>OpenAI-DotNet</PackageId>
<Version>6.3.1</Version>
<Company>RageAgainstThePixel</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Assets\OpenAI-DotNet-Icon.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
<NuspecFile>OpenAI-DotNet.nuspec</NuspecFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<None Update="Assets\OpenAI-DotNet-Icon.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
Loading