Skip to content

Commit

Permalink
Merge pull request #67 from jodendaal/develop
Browse files Browse the repository at this point in the history
Removal of TextEdit and Deprecated Models
  • Loading branch information
jodendaal committed Mar 25, 2023
2 parents b26c016 + ef77ec5 commit 5a1ee34
Show file tree
Hide file tree
Showing 30 changed files with 305 additions and 580 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ name: OpenAI.NET Build

on:
push:
branches: [ "main" ]
branches: [ "main","develop" ]

jobs:

Expand All @@ -64,6 +64,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0


# Install the .NET Core workload
- name: Install .NET Core
Expand All @@ -88,6 +89,13 @@ jobs:
- name: Execute acceptance tests
run: dotnet test src/OpenAI.Net.Acceptance.Tests/OpenAI.Net.Acceptance.Tests.csproj --configuration Release

# Execute Integration tests in the solution
- name: Execute Integration Tests
run: dotnet test src/OpenAI.Net.Integration.Tests/OpenAI.Net.Integration.Tests.csproj --configuration Release
env:
Apikey: ${{ secrets.APIKEY }}
ApiUrl: ${{ secrets.APIURL }}

# Install Stryker
- name: Install Stryker
run: dotnet tool install dotnet-stryker --tool-path src/OpenAI.Net.Tests
Expand All @@ -105,15 +113,19 @@ jobs:
run: dotnet build src/OpenAI.Net.sln --configuration Release

- name: Publish NuGet
if: github.ref == 'refs/heads/main'
run: dotnet nuget push src/OpenAI.Net/bin/Release/**\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json

- name: Add GitHub Packages Source
if: github.ref == 'refs/heads/main'
run: dotnet nuget add source --username jodendaal --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/jodendaal/index.json"

- name: Publish NuGet to GitHub Packages
if: github.ref == 'refs/heads/main'
run: dotnet nuget push src/OpenAI.Net/bin/Release/**\*.nupkg --skip-duplicate --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"

- name: Create Test Coverage Badge
if: github.ref == 'refs/heads/main'
uses: simon-k/dotnet-code-coverage-badge@v1.0.0
id: create_coverage_badge
with:
Expand All @@ -125,9 +137,11 @@ jobs:
gist-auth-token: ${{ secrets.GIST_AUTH_TOKEN }}

- name: Print code coverage
if: github.ref == 'refs/heads/main'
run: echo "Code coverage percentage ${{steps.create_coverage_badge.outputs.percentage}}%"

- name: Print badge data
if: github.ref == 'refs/heads/main'
run: echo "Badge data ${{steps.test_step.outputs.badge}}"

# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,15 @@ var response = await OpenAIService.Audio.GetTranslation(@"Audio\Translation.m4a"

### Text Edit
```csharp
var response = await service.TextEdit.Get("Fix the spelling mistakes", "What day of the wek is it?", (o =>{
o.TopP = 0.1;
o.Temperature = 100;
}));
var messages = new List<Message>
{
Message.Create(ChatRoleType.System, "You are a spell checker. Fix the spelling mistakes"),
Message.Create(ChatRoleType.User, "What day of the wek is it?"),
};

var response = await OpenAIService.Chat.Get(messages, o => {
o.MaxTokens = 1000;
});
```

### Image Edit
Expand Down Expand Up @@ -335,8 +340,6 @@ This should provide confidence in the library going forwards.
- [x] [Completions](https://platform.openai.com/docs/api-reference/completions)
- [x] [Create completion](https://platform.openai.com/docs/api-reference/completions/create)
- [x] [Create completion with streaming](https://platform.openai.com/docs/api-reference/completions#completions/create-stream)
- [x] [Edits](https://platform.openai.com/docs/api-reference/edits)
- [x] [Create edit](https://platform.openai.com/docs/api-reference/edits/create)
- [x] [Images](https://platform.openai.com/docs/api-reference/images)
- [x] [Create image](https://platform.openai.com/docs/api-reference/images/create)
- [x] [Create image edit](https://platform.openai.com/docs/api-reference/images/)
Expand Down
26 changes: 0 additions & 26 deletions src/OpenAI.Net.Acceptance.Tests/TextEditTests.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/OpenAI.Net.Integration.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public BaseTest()
{
var configuration = new ConfigurationBuilder()
.AddUserSecrets<BaseTest>()
.AddEnvironmentVariables()
.Build();

Config = new TestConfig(configuration);
Expand Down
21 changes: 19 additions & 2 deletions src/OpenAI.Net.Integration.Tests/ChatCompletionService_Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task Get(string model, bool isSuccess, HttpStatusCode statusCode)
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (isSuccess)
{
Assert.That(response.Result!.Choices.FirstOrDefault()!.Message.Content, Is.EqualTo("\n\nThis is a test."), "Choices are not mapped correctly");
Assert.That(response.Result!.Choices.FirstOrDefault()!.Message.Content.Trim(), Is.EqualTo("This is a test."), "Choices are not mapped correctly");
}
}

Expand All @@ -53,8 +53,25 @@ public async Task GetWithListExtension(string model, bool isSuccess, HttpStatusC
Assert.That(response.Result?.Choices?.Count() == 1, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
if (isSuccess)
{
Assert.That(response.Result?.Choices?.FirstOrDefault()?.Message.Content.Contains("Globe Life Field"), Is.EqualTo(true), "Incorrect answer");
Assert.That(response.Result?.Choices?.FirstOrDefault()?.Message.Content.Contains("Globe Life Field",StringComparison.InvariantCultureIgnoreCase), Is.EqualTo(true), $"Incorrect answer {response.Result?.Choices?.FirstOrDefault()?.Message.Content}");
}
}

[Test]
public async Task TetEditReplacement()
{
var messages = new List<Message>
{
Message.Create(ChatRoleType.System, "You are a spell checker. Fix the spelling mistakes"),
Message.Create(ChatRoleType.User, "What day of the wek is it?"),
};

var response = await OpenAIService.Chat.Get(messages, o => {
o.MaxTokens = 1000;
});

Assert.That(response.IsSuccess, Is.True);
Assert.That(response.Result?.Choices[0].Message.Content, Is.EqualTo("What day of the week is it?"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public async Task GetStream()

await foreach(var response in OpenAIService.Chat.GetStream(request))
{
Console.WriteLine(response?.Result?.Choices[0].Delta?.Content);
Assert.True(response?.IsSuccess, "Failed to get chat stream", response?.ErrorMessage);
}
}
Expand All @@ -31,7 +30,6 @@ public async Task GetStreamWithListExtension()

await foreach (var response in OpenAIService.Chat.GetStream(messages))
{
Console.WriteLine(response?.Result?.Choices[0].Delta?.Content);
Assert.True(response?.IsSuccess, "Failed to get chat stream", response?.ErrorMessage);
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/OpenAI.Net.Integration.Tests/EmbeddingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using OpenAI.Net.Models;
using OpenAI.Net.Models.Requests;

namespace OpenAI.Net.Integration.Tests
{
public class EmbeddingService: BaseTest
{
[Test]
public async Task Create()
{
var request = new EmbeddingsRequest("this is a test", OpenAIDefaults.EmbeddingsModel);
var response = await OpenAIService.Embeddings.Create(request);

Assert.That(response.IsSuccess, Is.True);
Assert.That(response.Result?.Data?.Count(), Is.GreaterThanOrEqualTo(1));
}
}
}
4 changes: 2 additions & 2 deletions src/OpenAI.Net.Integration.Tests/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ public async Task Remove()
Assert.That(response.IsSuccess, Is.EqualTo(true), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));

await Task.Delay(2000);
await Task.Delay(5000);

var retrieveFileResponse = await OpenAIService.Files.GetContent(response?.Result?.Id);
Assert.That(retrieveFileResponse.IsSuccess, Is.EqualTo(true), "Request failed");
Assert.That(retrieveFileResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));

await Task.Delay(2000);
await Task.Delay(5000);

var deleteResponse = await OpenAIService.Files.Delete(response?.Result?.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace OpenAI.Net.Integration.Tests
{
internal class ImplicitInitialiseAndReturn : BaseTest
{
[TestCase(ModelTypes.TextDavinciEdit001,true, HttpStatusCode.OK,TestName = "GetById_When_Success")]
[TestCase(ModelTypes.GPT35Turbo,true, HttpStatusCode.OK,TestName = "GetById_When_Success")]
public async Task GetById(string model,bool isSuccess, HttpStatusCode statusCode)
{
var response = await GetResponse();

Assert.That(response.Id == ModelTypes.TextDavinciEdit001, Is.EqualTo(isSuccess), "Implicit conversion failed");
Assert.That(response.Id == ModelTypes.GPT35Turbo, Is.EqualTo(isSuccess), "Implicit conversion failed");
}

private async Task<ModelInfo> GetResponse()
{
var result = await OpenAIService.Models.Get(ModelTypes.TextDavinciEdit001);
var result = await OpenAIService.Models.Get(ModelTypes.GPT35Turbo);
if (result.IsSuccess)
{
return result;
Expand Down
78 changes: 46 additions & 32 deletions src/OpenAI.Net.Integration.Tests/ModelsService.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
using System.Net;

namespace OpenAI.Net.Integration.Tests
{
internal class ModelsService : BaseTest
{
[TestCase(ModelTypes.TextDavinciEdit001,true, HttpStatusCode.OK,TestName = "GetById_When_Success")]
[TestCase("invalid_model", false, HttpStatusCode.NotFound,TestName = "GetById_When_Invalid_Model_Fail")]
public async Task GetById(string model,bool isSuccess, HttpStatusCode statusCode)
{


var response = await OpenAIService.Models.Get(model);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Id == ModelTypes.TextDavinciEdit001, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
}

[TestCase(true, HttpStatusCode.OK)]
public async Task GetAll(bool isSuccess, HttpStatusCode statusCode)
{


var response = await OpenAIService.Models.Get();

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data.Count() > 0, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
}
}
}
using Newtonsoft.Json;
using System.Linq;
using System.Net;
using System.Reflection;

namespace OpenAI.Net.Integration.Tests
{
internal class ModelsService : BaseTest
{
[TestCase(ModelTypes.GPT35Turbo,true, HttpStatusCode.OK,TestName = "GetById_When_Success")]
[TestCase("invalid_model", false, HttpStatusCode.NotFound,TestName = "GetById_When_Invalid_Model_Fail")]
public async Task GetById(string model,bool isSuccess, HttpStatusCode statusCode)
{
var response = await OpenAIService.Models.Get(model);

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Id == ModelTypes.GPT35Turbo, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
}

[TestCase(true, HttpStatusCode.OK)]
public async Task GetAll(bool isSuccess, HttpStatusCode statusCode)
{
var response = await OpenAIService.Models.Get();

Assert.That(response.IsSuccess, Is.EqualTo(isSuccess), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(statusCode));
Assert.That(response.Result?.Data.Count() > 0, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
}

[TestCase(true, HttpStatusCode.OK)]
public async Task ValidateModelTypesModel(bool isSuccess, HttpStatusCode statusCode)
{
var response = await OpenAIService.Models.Get();
var allModels = response?.Result?.Data.Select(i => i.Id).ToList()!;
var definedModelTypes = typeof(ModelTypes).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).Select(fieldInfo => fieldInfo.GetRawConstantValue()?.ToString());

var invalidModelTypes = definedModelTypes.Where(model => !allModels.Contains(model)).ToList();
var missingModelTypes = allModels.Where(id => !id.Contains("ft-personal") && !id.Contains("gpt-3.5-turbo-0301")).Where(model => !definedModelTypes.Contains(model)).ToList();


Assert.That(invalidModelTypes.Count, Is.EqualTo(0), $"Invalid models found {string.Join("\r\n", invalidModelTypes)}");
Assert.That(missingModelTypes.Count, Is.EqualTo(0), $"Missing models found {string.Join("\r\n", missingModelTypes)}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
Expand Down
11 changes: 11 additions & 0 deletions src/OpenAI.Net.Integration.Tests/TextCompletionService_Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,16 @@ public async Task GetListExtension(string model, bool isSuccess, HttpStatusCode
Assert.That(response?.Result?.Choices?.Length == 2, Is.EqualTo(isSuccess), "Choices are not mapped correctly");
});
}

[Test]
public async Task GetWithDefaultModel()
{
var request = new TextCompletionRequest(OpenAIDefaults.TextCompletionModel, "Say this is a test");
var response = await OpenAIService.TextCompletion.Get(request);

Assert.That(response.IsSuccess, Is.EqualTo(true), "Request failed");
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(response.Result?.Choices?.Length == 1, Is.EqualTo(true), "Choices are not mapped correctly");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public async Task GetStream()

var request = new TextCompletionRequest(ModelTypes.TextDavinci003, multipleQuestions) { MaxTokens = 1024, N = null};

await foreach(var t in OpenAIService.TextCompletion.GetStream(request))
await foreach(var response in OpenAIService.TextCompletion.GetStream(request))
{
Console.WriteLine(t?.Result?.Choices[0].Text);
Assert.That(response.IsSuccess);
}
}
}
Expand Down

0 comments on commit 5a1ee34

Please sign in to comment.