Skip to content

Commit

Permalink
OpenAI-DotNet 7.6.0 (#211)
Browse files Browse the repository at this point in the history
- Changed License to MIT
- Added OpenAI.Chat logprob parameters
- Added SourceLink references for debugging
- Added Docfx build workflow
  • Loading branch information
StephenHodgson authored Jan 2, 2024
1 parent 2365dfc commit 9d73280
Show file tree
Hide file tree
Showing 138 changed files with 682 additions and 146 deletions.
9 changes: 9 additions & 0 deletions .docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
###############
# folder #
###############
/**/DROP/
/**/TEMP/
/**/packages/
/**/bin/
/**/obj/
/**/api/
65 changes: 65 additions & 0 deletions .docs/docfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"metadata": [
{
"src": [
{
"src": "../OpenAI-DotNet/",
"files": [
"**.csproj"
],
"exclude": [
"**/bin/**",
"**/obj/**"
]
}
],
"dest": "api"
}
],
"build": {
"content": [
{
"files": [
"**/*.{md,yml}"
]
},
{
"src": "../OpenAI-DotNet-Proxy/",
"files": [
"/*.{md,yml}"
],
"dest": "OpenAI-DotNet-Proxy"
},
{
"src": "../",
"files": [
"/*.{md,yml}"
]
}
],
"resource": [
{
"src": "../OpenAI-DotNet/Assets",
"files": [
"*.png",
"*.svg",
"*.ico"
],
"dest" : "assets"
}
],
"output": "../_site",
"template": [
"default",
"modern"
],
"globalMetadata": {
"_appName": "OpenAI-DotNet",
"_appTitle": "OpenAI-DotNet",
"_appLogoPath": "assets/[email protected]",
"_appFaviconPath": "assets/[email protected]",
"_enableSearch": true,
"pdf": false
}
}
}
3 changes: 3 additions & 0 deletions .docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
redirect_url: README.html
---
4 changes: 4 additions & 0 deletions .docs/toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Proxy
href: OpenAI-DotNet-Proxy/Readme.html
- name: API
href: api/OpenAI.OpenAIClient.html
41 changes: 40 additions & 1 deletion .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nuget Publish
name: Build and Publish

on:
push:
Expand All @@ -24,6 +24,15 @@ on:
required: false
default: "6.0.x"

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: ${{ github.ref }}
cancel-in-progress: false

env:
DOTNET_VERSION: ${{ github.event.inputs.dotnet-version || '6.0.x' }}
PACKAGE_VERSION: ''
Expand Down Expand Up @@ -125,3 +134,33 @@ jobs:
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.nupkg
${{ github.workspace }}/OpenAI-DotNet/bin/Release/OpenAI-DotNet-Proxy.${{ env.PACKAGE_VERSION }}.symbols.nupkg
if-no-files-found: ignore

docs:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest

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

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

- name: build docfx
run: |
dotnet tool update -g docfx
docfx .docs/docfx.json
- uses: actions/upload-pages-artifact@v3
with:
path: '_site'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,12 @@ ASALocalRun/

# BeatPulse healthcheck temp database
healthchecksdb

# Visual Studio Code
.vscode

# Docfx
_site

# Unit Test Ouputs
OpenAI-DotNet-Tests/Assets/HelloWorld.mp3
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2021 Stephen Hodgson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 0 additions & 3 deletions LICENSE.md

This file was deleted.

4 changes: 3 additions & 1 deletion OpenAI-DotNet-Proxy/Proxy/AbstractAuthenticationFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Http;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Http;

namespace OpenAI.Proxy
{
Expand Down
4 changes: 3 additions & 1 deletion OpenAI-DotNet-Proxy/Proxy/IAuthenticationFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Security.Authentication;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Security.Authentication;
using Microsoft.AspNetCore.Http;

namespace OpenAI.Proxy
Expand Down
4 changes: 3 additions & 1 deletion OpenAI-DotNet-Proxy/Proxy/OpenAIProxyStartup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Builder;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
Expand Down
4 changes: 4 additions & 0 deletions OpenAI-DotNet-Proxy/toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Proxy
href: Readme.md
- name: API
href: ../api/OpenAI.OpenAIClient.html
4 changes: 3 additions & 1 deletion OpenAI-DotNet-Tests/AbstractTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Hosting;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using System;
using System.Net.Http;
Expand Down
62 changes: 62 additions & 0 deletions OpenAI-DotNet-Tests/TestFixture_03_Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,67 @@ public async Task Test_03_02_GetChatVisionStreaming()
Console.WriteLine($"{response.FirstChoice.Message.Role}: {response.FirstChoice} | Finish Reason: {response.FirstChoice.FinishDetails}");
response.GetUsage();
}

[Test]
public async Task Test_04_01_GetChatLogProbs()
{
Assert.IsNotNull(OpenAIClient.ChatEndpoint);
var messages = new List<Message>
{
new Message(Role.System, "You are a helpful assistant."),
new Message(Role.User, "Who won the world series in 2020?"),
new Message(Role.Assistant, "The Los Angeles Dodgers won the World Series in 2020."),
new Message(Role.User, "Where was it played?"),
};
var chatRequest = new ChatRequest(messages, Model.GPT3_5_Turbo, topLogProbs: 1);
var response = await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest);
Assert.IsNotNull(response);
Assert.IsNotNull(response.Choices);
Assert.IsNotEmpty(response.Choices);

foreach (var choice in response.Choices)
{
Console.WriteLine($"[{choice.Index}] {choice.Message.Role}: {choice} | Finish Reason: {choice.FinishReason}");
}

response.GetUsage();
}

[Test]
public async Task Test_04_02_GetChatLogProbsSteaming()
{
Assert.IsNotNull(OpenAIClient.ChatEndpoint);
var messages = new List<Message>
{
new Message(Role.System, "You are a helpful assistant."),
new Message(Role.User, "Who won the world series in 2020?"),
new Message(Role.Assistant, "The Los Angeles Dodgers won the World Series in 2020."),
new Message(Role.User, "Where was it played?"),
};
var chatRequest = new ChatRequest(messages, topLogProbs: 1);
var cumulativeDelta = string.Empty;
var response = await OpenAIClient.ChatEndpoint.StreamCompletionAsync(chatRequest, partialResponse =>
{
Assert.IsNotNull(partialResponse);
Assert.NotNull(partialResponse.Choices);
Assert.NotZero(partialResponse.Choices.Count);

foreach (var choice in partialResponse.Choices.Where(choice => choice.Delta?.Content != null))
{
cumulativeDelta += choice.Delta.Content;
}
});
Assert.IsNotNull(response);
Assert.IsNotNull(response.Choices);
var choice = response.FirstChoice;
Assert.IsNotNull(choice);
Assert.IsNotNull(choice.Message);
Assert.IsFalse(string.IsNullOrEmpty(choice.ToString()));
Console.WriteLine($"[{choice.Index}] {choice.Message.Role}: {choice} | Finish Reason: {choice.FinishReason}");
Assert.IsTrue(choice.Message.Role == Role.Assistant);
Assert.IsTrue(choice.Message.Content!.Equals(cumulativeDelta));
Console.WriteLine(response.ToString());
response.GetUsage();
}
}
}
3 changes: 2 additions & 1 deletion OpenAI-DotNet/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OpenAI-DotNet-Proxy")]
Expand Down
Binary file added OpenAI-DotNet/Assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions OpenAI-DotNet/Assistants/AssistantExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Files;
using OpenAI.Threads;
using System.Threading;
Expand Down Expand Up @@ -25,7 +27,7 @@ public static async Task<AssistantResponse> ModifyAsync(this AssistantResponse a
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>True, if the <see cref="assistant"/> was successfully deleted.</returns>
/// <returns>True, if the assistant was successfully deleted.</returns>
public static async Task<bool> DeleteAsync(this AssistantResponse assistant, CancellationToken cancellationToken = default)
=> await assistant.Client.AssistantsEndpoint.DeleteAssistantAsync(assistant.Id, cancellationToken).ConfigureAwait(false);

Expand All @@ -52,7 +54,7 @@ public static async Task<ListResponse<AssistantFileResponse>> ListFilesAsync(thi
=> await assistant.Client.AssistantsEndpoint.ListFilesAsync(assistant.Id, query, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Attach a file to the <see cref="assistant"/>.
/// Attach a file to the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="file">
Expand All @@ -65,7 +67,7 @@ public static async Task<AssistantFileResponse> AttachFileAsync(this AssistantRe
=> await assistant.Client.AssistantsEndpoint.AttachFileAsync(assistant.Id, file, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Uploads a new file at the specified <see cref="filePath"/> and attaches it to the <see cref="assistant"/>.
/// Uploads a new file at the specified path and attaches it to the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="filePath">The local file path to upload.</param>
Expand Down Expand Up @@ -100,7 +102,7 @@ public static async Task<AssistantFileResponse> RetrieveFileAsync(this Assistant
// => await assistantFile.Client.FilesEndpoint.DownloadFileAsync(assistantFile.Id, directory, deleteCachedFile, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Remove AssistantFile.
/// Remove the file from the assistant it is attached to.
/// </summary>
/// <remarks>
/// Note that removing an AssistantFile does not delete the original File object,
Expand All @@ -114,7 +116,7 @@ public static async Task<bool> RemoveFileAsync(this AssistantFileResponse file,
=> await file.Client.AssistantsEndpoint.RemoveFileAsync(file.AssistantId, file.Id, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Remove AssistantFile.
/// Remove the file from the assistant it is attached to.
/// </summary>
/// <remarks>
/// Note that removing an AssistantFile does not delete the original File object,
Expand All @@ -141,7 +143,7 @@ public static async Task<bool> DeleteFileAsync(this AssistantFileResponse file,
}

/// <summary>
/// Removes and Deletes a file from the <see cref="assistant"/>.
/// Removes and Deletes a file from the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="fileId">The ID of the file to delete.</param>
Expand Down
2 changes: 2 additions & 0 deletions OpenAI-DotNet/Assistants/AssistantFileResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Text.Json.Serialization;

Expand Down
4 changes: 3 additions & 1 deletion OpenAI-DotNet/Assistants/AssistantResponse.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenAI.Assistants
{
/// <summary>
/// Purpose-built AI that uses OpenAIs models and calls tools.
/// Purpose-built AI that uses OpenAI's models and calls tools.
/// </summary>
public sealed class AssistantResponse : BaseResponse
{
Expand Down
2 changes: 2 additions & 0 deletions OpenAI-DotNet/Assistants/AssistantsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Extensions;
using OpenAI.Files;
using System;
Expand Down
2 changes: 2 additions & 0 deletions OpenAI-DotNet/Assistants/CreateAssistantRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
Expand Down
4 changes: 3 additions & 1 deletion OpenAI-DotNet/Audio/AudioEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using OpenAI.Extensions;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Extensions;
using System;
using System.IO;
using System.Net.Http;
Expand Down
4 changes: 3 additions & 1 deletion OpenAI-DotNet/Audio/AudioResponseFormat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace OpenAI.Audio
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace OpenAI.Audio
{
public enum AudioResponseFormat
{
Expand Down
Loading

0 comments on commit 9d73280

Please sign in to comment.