Skip to content

Commit

Permalink
OpenAI-DotNet 5.1.2 (RageAgainstThePixel#42)
Browse files Browse the repository at this point in the history
- Fixed an issue when deleting personal account fine tuned models
  • Loading branch information
StephenHodgson committed Mar 10, 2023
1 parent 2cef872 commit 6b876d5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Publish-Nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
- name: Test Package ${{ matrix.configuration }}
run: dotnet test --configuration ${{ matrix.configuration }}
env:
TEST_OPENAI_SECRET_KEY: ${{ secrets.TEST_OPENAI_SECRET_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_ORGANIZATION_ID: ${{ secrets.OPENAI_ORGANIZATION_ID }}

- name: Publish Nuget Package
run: |
Expand Down
16 changes: 14 additions & 2 deletions OpenAI-DotNet-Tests/TestFixture_09_FineTuning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -201,17 +202,28 @@ public async Task Test_08_DeleteFineTunedModel()
Assert.IsNotNull(models);
Assert.IsNotEmpty(models);

foreach (var model in models)
try
{
if (model.OwnedBy == api.OpenAIAuthentication.OrganizationId)
foreach (var model in models)
{
if (model.OwnedBy.Contains("openai") ||
model.OwnedBy.Contains("system"))
{
continue;
}

Console.WriteLine(model);
var result = await api.ModelsEndpoint.DeleteFineTuneModelAsync(model);
Assert.IsNotNull(result);
Assert.IsTrue(result);
Console.WriteLine($"{model.Id} -> deleted");
break;
}
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("Your account does not have permissions to delete models.");
}
}
}
}
17 changes: 12 additions & 5 deletions OpenAI-DotNet/Models/ModelsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ public async Task<bool> DeleteFineTuneModelAsync(string modelId)
throw new Exception($"Failed to get {modelId} info!");
}

if (model.OwnedBy != Api.OpenAIAuthentication.OrganizationId)
try
{
throw new UnauthorizedAccessException($"{model.Id} is not owned by your organization.");
var response = await Api.Client.DeleteAsync($"{GetEndpoint()}/{model.Id}").ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync().ConfigureAwait(false);
return JsonSerializer.Deserialize<DeleteModelResponse>(responseAsString, Api.JsonSerializationOptions)?.Deleted ?? false;
}
catch (Exception e)
{
if (e.Message.Contains("api.delete"))
{
throw new UnauthorizedAccessException($"You do not have permissions to delete models for this organization.\n{e}");
}

var response = await Api.Client.DeleteAsync($"{GetEndpoint()}/{model.Id}").ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync().ConfigureAwait(false);
return JsonSerializer.Deserialize<DeleteModelResponse>(responseAsString, Api.JsonSerializationOptions)?.Deleted ?? false;
throw;
}
}
}
}
10 changes: 6 additions & 4 deletions OpenAI-DotNet/OpenAI-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Based on OpenAI-API by OKGoDoIt (Roger Pincombe)</Description>
<RepositoryUrl>https://github.com/RageAgainstThePixel/OpenAI-DotNet</RepositoryUrl>
<PackageTags>OpenAI, AI, ML, API, gpt, gpt-3, chatGPT</PackageTags>
<Title>OpenAI API</Title>
<PackageReleaseNotes>Bump version to 5.1.1
<PackageReleaseNotes>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
Expand Down Expand Up @@ -59,9 +61,9 @@ Bump version to 4.4.0
<AssemblyOriginatorKeyFile>OpenAI-DotNet.pfx</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>
<PackageId>OpenAI-DotNet</PackageId>
<Version>5.1.1</Version>
<AssemblyVersion>5.1.1.0</AssemblyVersion>
<FileVersion>5.1.1.0</FileVersion>
<Version>5.1.2</Version>
<AssemblyVersion>5.1.2.0</AssemblyVersion>
<FileVersion>5.1.2.0</FileVersion>
<Company>RageAgainstThePixel</Company>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
Expand Down

0 comments on commit 6b876d5

Please sign in to comment.