Skip to content

Commit

Permalink
OpenAI-DotNet 6.3.0 (RageAgainstThePixel#48)
Browse files Browse the repository at this point in the history
- Removed `OpenAI-DotNet-Proxy` and put it directly in package on its
own
  • Loading branch information
StephenHodgson committed Mar 16, 2023
1 parent 5228434 commit 3e571e9
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 228 deletions.
41 changes: 0 additions & 41 deletions .github/actions/build-and-publish/action.yaml

This file was deleted.

70 changes: 31 additions & 39 deletions .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on:
push:
branches:
- main
paths:
- OpenAI-DotNet/**
pull_request:
branches:
- '*'
paths:
- OpenAI-DotNet/**

workflow_dispatch:
inputs:
Expand All @@ -19,63 +23,51 @@ env:
DOTNET_VERSION: ${{ github.event.inputs.dotnet-version || '6.0.x' }}

jobs:
test:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- uses: microsoft/setup-msbuild@v1

- name: Test Packages
run: dotnet test --configuration Release
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_ORGANIZATION_ID: ${{ secrets.OPENAI_ORGANIZATION_ID }}

- name: No tests needed
run: echo "No tests needed as no files in the specified paths were modified."
- name: Build Pack and Publish NuGet Package
run: |
$projectPath = "${{ github.workspace }}\OpenAI-DotNet"
dotnet build $projectPath --configuration Release
$out = "$projectPath\bin\Release"
$packagePath = Get-ChildItem -Path $out -File -Include '*.nupkg' -Recurse -ErrorAction SilentlyContinue
build-openai-dotnet:
needs: test
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
if ($packagePath) {
Write-Host Package path: $packagePath
} else {
Write-Host Failed to find package at $out
exit 1
}
- uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
$isRelease = "${{ github.ref == 'refs/heads/main' }}"
- uses: microsoft/setup-msbuild@v1
if ($isRelease -eq 'true') {
dotnet nuget push $packagePath --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
}
- name: Build and Publish OpenAI-DotNet NuGet Package
uses: ./.github/actions/build-and-publish
with:
project_name: OpenAI-DotNet
nuget_api_key: ${{ secrets.NUGET_API_KEY }}
$version = $packagePath.Name -replace "^OpenAI-DotNet.(.*).nupkg$",'$1'
echo "PACKAGE_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
shell: pwsh

build-openai-dotnet-proxy:
needs: test
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- uses: microsoft/setup-msbuild@v1

- name: Build and Publish OpenAI-DotNet-Proxy NuGet Package
uses: ./.github/actions/build-and-publish
with:
project_name: OpenAI-DotNet-Proxy
nuget_api_key: ${{ secrets.NUGET_API_KEY }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: OpenAI-DotNet.${{ env.PACKAGE_VERSION }}
path: ${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet.${{ env.PACKAGE_VERSION }}.nupkg
if-no-files-found: ignore
5 changes: 0 additions & 5 deletions Directory.Build.props

This file was deleted.

41 changes: 0 additions & 41 deletions OpenAI-DotNet-Proxy/OpenAI-DotNet-Proxy.csproj

This file was deleted.

84 changes: 0 additions & 84 deletions OpenAI-DotNet-Proxy/Readme.md

This file was deleted.

1 change: 0 additions & 1 deletion OpenAI-DotNet-Tests-Proxy/OpenAI-DotNet-Tests-Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

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

Expand Down
6 changes: 0 additions & 6 deletions OpenAI-DotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ 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", "{DEF7D9FF-A356-48C7-937F-C13FF59DF68A}"
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 @@ -21,10 +19,6 @@ 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
{DEF7D9FF-A356-48C7-937F-C13FF59DF68A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DEF7D9FF-A356-48C7-937F-C13FF59DF68A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEF7D9FF-A356-48C7-937F-C13FF59DF68A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEF7D9FF-A356-48C7-937F-C13FF59DF68A}.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
7 changes: 5 additions & 2 deletions OpenAI-DotNet/OpenAI-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet-
<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.2.0
<PackageReleaseNotes>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
Expand Down Expand Up @@ -75,7 +77,7 @@ Bump version to 4.4.0
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
<PackageId>OpenAI-DotNet</PackageId>
<Version>$(OpenAIDotNetVersion)</Version>
<Version>6.3.0</Version>
<Company>RageAgainstThePixel</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Assets\OpenAI-DotNet-Icon.png</PackageIcon>
Expand All @@ -95,5 +97,6 @@ Bump version to 4.4.0
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
File renamed without changes.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Discord](https://img.shields.io/discord/855294214065487932.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xQgMW9ufN4)
[![NuGet version (OpenAI-DotNet)](https://img.shields.io/nuget/v/OpenAI-DotNet.svg?label=OpenAI-DotNet&logo=nuget)](https://www.nuget.org/packages/OpenAI-DotNet/)
[![NuGet version (OpenAI-DotNet-Proxy)](https://img.shields.io/nuget/v/OpenAI-DotNet-Proxy.svg?label=OpenAI-DotNet-Proxy&logo=nuget)](https://www.nuget.org/packages/OpenAI-DotNet-Proxy/)
[![Nuget Publish](https://github.com/RageAgainstThePixel/OpenAI-DotNet/actions/workflows/Publish-Nuget.yml/badge.svg)](https://github.com/RageAgainstThePixel/OpenAI-DotNet/actions/workflows/Publish-Nuget.yml)

A simple C# .NET client library for [OpenAI](https://openai.com/) to use 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.
Expand Down Expand Up @@ -150,13 +149,11 @@ var settings = new OpenAIClientSettings(resourceName: "your-resource", deploymen
var api = new OpenAIClient(auth, settings);
```

### :new: [OpenAI API Proxy](OpenAI-DotNet-Proxy/Readme.md)

[![NuGet version (OpenAI-DotNet-Proxy)](https://img.shields.io/nuget/v/OpenAI-DotNet-Proxy.svg?label=OpenAI-DotNet-Proxy&logo=nuget)](https://www.nuget.org/packages/OpenAI-DotNet-Proxy/)
### :new: OpenAI API Proxy

Using either the [OpenAI-DotNet](https://github.com/RageAgainstThePixel/OpenAI-DotNet) or [com.openai.unity](https://github.com/RageAgainstThePixel/com.openai.unity) packages directly in your front-end app may expose your API keys and other sensitive information. To mitigate this risk, it is recommended to set up an intermediate API that makes requests to OpenAI on behalf of your front-end app. This library can be utilized for both front-end and intermediary host configurations, ensuring secure communication with the OpenAI API.

#### Font End Example
#### Front End Example

In the front end example, you will need to securely authenticate your users using your preferred OAuth provider. Once the user is authenticated, exchange your custom auth token with your API key on the backend.

Expand All @@ -177,16 +174,16 @@ var settings = new OpenAIClientSettings(domain: "api.your-custom-domain.com");
var api = new OpenAIClient(auth, settings);
```

This setup allows your front end application to securely communicate with your backend that will be using the OpenAI-DotNet-Proxy, which then forwards requests to the OpenAI API. This ensures that your OpenAI API keys and other sensitive information remain secure throughout the process.
This setup allows your front end application to securely communicate with your backend that will be using the proxy service, which then forwards requests to the OpenAI API. This ensures that your OpenAI API keys and other sensitive information remain secure throughout the process.

#### Back End Example

In this example, we demonstrate how to set up and use `OpenAIProxyStartup` in a new ASP.NET Core web app. The proxy server will handle authentication and forward requests to the OpenAI API, ensuring that your API keys and other sensitive information remain secure.

1. Create a new [ASP.NET Core minimal web API](https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api?view=aspnetcore-6.0) project.
2. Add the OpenAI-DotNet-Proxy nuget package to your project.
a. Manually editing .csproj: `<PackageReference Include="OpenAI-DotNet-Proxy" />`
b. Powershell install: `Install-Package OpenAI-DotNet-Proxy`
2. Add the OpenAI-DotNet nuget package to your project.
- Powershell install: `Install-Package OpenAI-DotNet`
- Manually editing .csproj: `<PackageReference Include="OpenAI-DotNet" />`
3. Create a new class that inherits from `AbstractAuthenticationFilter` and override the `ValidateAuthentication` method. This will implement the `IAuthenticationFilter` that you will use to check user session token against your internal server.
4. In `Program.cs`, create a new proxy web application by calling `OpenAIProxyStartup.CreateDefaultHost` method, passing your custom `AuthenticationFilter` as a type argument.
5. Create `OpenAIAuthentication` and `OpenAIClientSettings` as you would normally with your API keys, org id, or Azure settings.
Expand Down

0 comments on commit 3e571e9

Please sign in to comment.