Skip to content

Commit

Permalink
Merge pull request #392 from betalgo/dev
Browse files Browse the repository at this point in the history
7.3.0
  • Loading branch information
kayhantolga authored Oct 17, 2023
2 parents a212749 + c86d26f commit 74db2ed
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 58 deletions.
6 changes: 3 additions & 3 deletions OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
// | / \ / \ | \ /) | ( \ /o\ / ) | (\ / | / \ / \ |
// |-----------------------------------------------------------------------|

//await ChatCompletionTestHelper.RunSimpleChatCompletionTest(sdk);
await ChatCompletionTestHelper.RunSimpleChatCompletionTest(sdk);
//await ChatCompletionTestHelper.RunSimpleCompletionStreamTest(sdk);
//await ChatCompletionTestHelper.RunChatFunctionCallTest(sdk);
await FineTuningJobTestHelper.RunCaseStudyIsTheModelMakingUntrueStatements(sdk);
//await FineTuningJobTestHelper.RunCaseStudyIsTheModelMakingUntrueStatements(sdk);
// Whisper
//await AudioTestHelper.RunSimpleAudioCreateTranscriptionTest(sdk);
//await AudioTestHelper.RunSimpleAudioCreateTranslationTest(sdk);
Expand All @@ -55,7 +55,7 @@
//await ImageTestHelper.RunSimpleCreateImageTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageEditTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageVariationTest(sdk);
//await ModerationTestHelper.CreateModerationTest(sdk);
await ModerationTestHelper.CreateModerationTest(sdk);
//await CompletionTestHelper.RunSimpleCompletionTest(sdk);
//await CompletionTestHelper.RunSimpleCompletionTest2(sdk);
//await CompletionTestHelper.RunSimpleCompletionTest3(sdk);
Expand Down
8 changes: 4 additions & 4 deletions OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AzureOpenAiEndpointProvider(string apiVersion, string deploymentId)
_deploymentId = deploymentId;
}

private string Prefix => $"/{ApiPrefix}/{DeploymentsPrefix}/{WebUtility.UrlEncode(_deploymentId)}";
private string Prefix => $"{ApiPrefix}/{DeploymentsPrefix}/{WebUtility.UrlEncode(_deploymentId)}";
private string QueryString => $"?api-version={_apiVersion}";


Expand Down Expand Up @@ -58,12 +58,12 @@ public string FilesUpload()

public string FileRetrieve(string fileId)
{
return $"/{Prefix}/files/{fileId}{QueryString}";
return $"{Prefix}/files/{fileId}{QueryString}";
}

public string FileRetrieveContent(string fileId)
{
return $"/{Prefix}/files/{fileId}/content{QueryString}";
return $"{Prefix}/files/{fileId}/content{QueryString}";
}

public string FineTuneCreate()
Expand Down Expand Up @@ -103,7 +103,7 @@ public string FineTuningJobCreate()

public string FineTuningJobList(FineTuningJobListRequest? fineTuningJobListRequest)
{
var url = $"/{Prefix}/fine_tuning/jobs";
var url = $"{Prefix}/fine_tuning/jobs";
if (fineTuningJobListRequest != null)
{
var queryParams = new List<string>();
Expand Down
56 changes: 28 additions & 28 deletions OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,42 @@ public OpenAiEndpointProvider(string apiVersion)

public string ModelRetrieve(string model)
{
return $"/{_apiVersion}/models/{model}";
return $"{_apiVersion}/models/{model}";
}

public string FileDelete(string fileId)
{
return $"/{_apiVersion}/files/{fileId}";
return $"{_apiVersion}/files/{fileId}";
}

public string CompletionCreate()
{
return $"/{_apiVersion}/completions";
return $"{_apiVersion}/completions";
}

public string ChatCompletionCreate()
{
return $"/{_apiVersion}/chat/completions";
return $"{_apiVersion}/chat/completions";
}

public string AudioCreateTranscription()
{
return $"/{_apiVersion}/audio/transcriptions";
return $"{_apiVersion}/audio/transcriptions";
}

public string AudioCreateTranslation()
{
return $"/{_apiVersion}/audio/translations";
return $"{_apiVersion}/audio/translations";
}

public string EditCreate()
{
return $"/{_apiVersion}/edits";
return $"{_apiVersion}/edits";
}

public string ModelsList()
{
return $"/{_apiVersion}/models";
return $"{_apiVersion}/models";
}

public string FilesList()
Expand All @@ -64,52 +64,52 @@ public string FilesUpload()

public string FileRetrieve(string fileId)
{
return $"/{_apiVersion}/files/{fileId}";
return $"{_apiVersion}/files/{fileId}";
}

public string FileRetrieveContent(string fileId)
{
return $"/{_apiVersion}/files/{fileId}/content";
return $"{_apiVersion}/files/{fileId}/content";
}

public string FineTuneCreate()
{
return $"/{_apiVersion}/fine-tunes";
return $"{_apiVersion}/fine-tunes";
}

public string FineTuneList()
{
return $"/{_apiVersion}/fine-tunes";
return $"{_apiVersion}/fine-tunes";
}

public string FineTuneRetrieve(string fineTuneId)
{
return $"/{_apiVersion}/fine-tunes/{fineTuneId}";
return $"{_apiVersion}/fine-tunes/{fineTuneId}";
}

public string FineTuneCancel(string fineTuneId)
{
return $"/{_apiVersion}/fine-tunes/{fineTuneId}/cancel";
return $"{_apiVersion}/fine-tunes/{fineTuneId}/cancel";
}

public string FineTuneListEvents(string fineTuneId)
{
return $"/{_apiVersion}/fine-tunes/{fineTuneId}/events";
return $"{_apiVersion}/fine-tunes/{fineTuneId}/events";
}

public string FineTuneDelete(string fineTuneId)
{
return $"/{_apiVersion}/models/{fineTuneId}";
return $"{_apiVersion}/models/{fineTuneId}";
}

public string FineTuningJobCreate()
{
return $"/{_apiVersion}/fine_tuning/jobs";
return $"{_apiVersion}/fine_tuning/jobs";
}

public string FineTuningJobList(FineTuningJobListRequest? fineTuningJobListRequest)
{
var url = $"/{_apiVersion}/fine_tuning/jobs";
var url = $"{_apiVersion}/fine_tuning/jobs";
if (fineTuningJobListRequest != null)
{
var queryParams = new List<string>();
Expand All @@ -126,51 +126,51 @@ public string FineTuningJobList(FineTuningJobListRequest? fineTuningJobListReque

public string FineTuningJobRetrieve(string fineTuningJobId)
{
return $"/{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}";
return $"{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}";
}

public string FineTuningJobCancel(string fineTuningJobId)
{
return $"/{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}/cancel";
return $"{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}/cancel";
}

public string FineTuningJobListEvents(string fineTuningJobId)
{
return $"/{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}/events";
return $"{_apiVersion}/fine_tuning/jobs/{fineTuningJobId}/events";
}

public string ModelsDelete(string modelId)
{
return $"/{_apiVersion}/models/{modelId}";
return $"{_apiVersion}/models/{modelId}";
}

public string EmbeddingCreate()
{
return $"/{_apiVersion}/embeddings";
return $"{_apiVersion}/embeddings";
}

public string ModerationCreate()
{
return $"/{_apiVersion}/moderations";
return $"{_apiVersion}/moderations";
}

public string ImageCreate()
{
return $"/{_apiVersion}/images/generations";
return $"{_apiVersion}/images/generations";
}

public string ImageEditCreate()
{
return $"/{_apiVersion}/images/edits";
return $"{_apiVersion}/images/edits";
}

public string ImageVariationCreate()
{
return $"/{_apiVersion}/images/variations";
return $"{_apiVersion}/images/variations";
}

private string Files()
{
return $"/{_apiVersion}/files";
return $"{_apiVersion}/files";
}
}
6 changes: 6 additions & 0 deletions OpenAI.SDK/Extensions/HttpclientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static async Task<TResponse> PostAndReadAsAsync<TResponse>(this HttpClien
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
}, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

Expand Down Expand Up @@ -47,6 +48,7 @@ private static HttpResponseMessage SendRequestPreNet6(HttpClient client, HttpReq
{
var responseTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
var response = responseTask.GetAwaiter().GetResult();
response.EnsureSuccessStatusCode();
return response;
}

Expand All @@ -62,18 +64,21 @@ private static HttpRequestMessage CreatePostEventStreamRequest(string uri, HttpC
public static async Task<TResponse> PostFileAndReadAsAsync<TResponse>(this HttpClient client, string uri, HttpContent content, CancellationToken cancellationToken = default)
{
var response = await client.PostAsync(uri, content, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

public static async Task<string> PostFileAndReadAsStringAsync(this HttpClient client, string uri, HttpContent content, CancellationToken cancellationToken = default)
{
var response = await client.PostAsync(uri, content, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync(cancellationToken) ?? throw new InvalidOperationException();
}

public static async Task<TResponse> DeleteAndReadAsAsync<TResponse>(this HttpClient client, string uri, CancellationToken cancellationToken = default)
{
var response = await client.DeleteAsync(uri, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<TResponse>(cancellationToken: cancellationToken) ?? throw new InvalidOperationException();
}

Expand All @@ -99,6 +104,7 @@ public static async Task<byte[]> ReadAsByteArrayAsync(this HttpContent content,
public static async Task<Stream> GetStreamAsync(this HttpClient client, string requestUri, CancellationToken cancellationToken)
{
var response = await client.GetAsync(requestUri, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStreamAsync(cancellationToken);
}

Expand Down
18 changes: 18 additions & 0 deletions OpenAI.SDK/ObjectModels/ResponseModels/CreateModerationResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ public record Categories

[JsonPropertyName("hate/threatening")] public bool HateThreatening { get; set; }

[JsonPropertyName("harassment")] public bool Harassment { get; set; }

[JsonPropertyName("harassment/threatening")]
public bool HarassmentThreatening { get; set; }

[JsonPropertyName("self-harm")] public bool SelfHarm { get; set; }
[JsonPropertyName("self-harm/intent")] public bool SelfHarmIntent { get; set; }

[JsonPropertyName("self-harm/instructions")]
public bool SelfHarmInstructions { get; set; }

[JsonPropertyName("sexual")] public bool Sexual { get; set; }

Expand All @@ -44,7 +53,16 @@ public record CategoryScores

[JsonPropertyName("hate/threatening")] public float HateThreatening { get; set; }

[JsonPropertyName("harassment")] public float Harassment { get; set; }

[JsonPropertyName("harassment/threatening")]
public float HarassmentThreatening { get; set; }

[JsonPropertyName("self-harm")] public float SelfHarm { get; set; }
[JsonPropertyName("self-harm/intent")] public float SelfHarmIntent { get; set; }

[JsonPropertyName("self-harm/instructions")]
public float SelfHarmInstructions { get; set; }

[JsonPropertyName("sexual")] public float Sexual { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>OpenAI SDK by Betalgo</Title>
<Version>7.2.0</Version>
<Version>7.3.0</Version>
<Authors>Tolga Kayhan, Betalgo</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>OpenAI ChatGPT, Whisper, GPT-4 and DALL·E dotnet SDK</Product>
Expand Down
2 changes: 1 addition & 1 deletion OpenAI.Utilities/OpenAI.Utilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Betalgo.OpenAI" Version="7.1.4" />
<PackageReference Include="Betalgo.OpenAI" Version="7.2.0" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.Data.Analysis" Version="0.20.1" />
Expand Down
28 changes: 7 additions & 21 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Dotnet SDK for OpenAI Chat GPT, Whisper, GPT-4 ,GPT-3 and DALL·E
#### This library used be to known as `Betalgo.OpenAI.GPT3`, now it has a new package Id `Betalgo.OpenAI`.

## Checkout the wiki page:
https://github.com/betalgo/openai/wiki
https://github.com/betalgo/openai/wiki
or [![Static Badge](https://img.shields.io/badge/API%20Docs-RobiniaDocs-43bc00?logo=readme&logoColor=white)](https://www.robiniadocs.com/d/betalgo-openai/api/OpenAI.ObjectModels.RequestModels.ChatMessage.html)
## Checkout new ***experimantal*** utilities library:
[![Betalgo.OpenAI.Utilities](https://img.shields.io/nuget/v/Betalgo.OpenAI.Utilities?style=for-the-badge)](https://www.nuget.org/packages/Betalgo.OpenAI.Utilities/)
```
Expand Down Expand Up @@ -223,6 +224,11 @@ I will always be using the latest libraries, and future releases will frequently
I am incredibly busy. If I forgot your name, please accept my apologies and let me know so I can add it to the list.

## Changelog
### Version 7.3.0
- Updated Moderation categories as reported by @dmki.
- **Breaking Changes:**
- Introduced the use of `EnsureStatusCode()` after making requests.Please adjust your code accordingly for handling failure cases. Thanks to @miroljub1995 for reporting.
- Previously, we used to override paths in the base domain, but this behavior has now changed. If you were using `abc.com/mypath` as the base domain, we used to ignore `/mypath`. This will no longer be the case, and the code will now respect `/mypath`. Thanks to @Hzw576816 for reporting.
### 7.2.0
- Added Chatgpt Finetununig support thanks to @aghimir3
- Default Azure Openai version increased thanks to @mac8005
Expand All @@ -234,23 +240,3 @@ I am incredibly busy. If I forgot your name, please accept my apologies and let
- This release was a bit late and took longer than expected due to a couple of reasons. The future was quite big, and I couldn't cover all possibilities. However, I believe I have covered most of the function definitions (with some details missing). Additionally, I added an option to build it manually. If you don't know what I mean, you don't need to worry. I plan to cover the rest of the function definition in the next release. Until then, you can discover this by playing in the playground or in the source code. This version also support using other libraries to export your function definition.
- We now have support for functions! Big cheers to @rzubek for completing most of this feature.
- Additionally, we have made bug fixes and improvements. Thanks to @choshinyoung, @yt3trees, @WeihanLi, @N0ker, and all the bug reporters. (Apologies if I missed any names. Please let me know if I missed your name and you have a commit.)
### 7.1.2-beta
- Bugfix https://github.com/betalgo/openai/pull/302
- Added support for Function role https://github.com/betalgo/openai/issues/303
### 7.1.0-beta
- Function Calling: We're releasing this version to bring in a new feature that lets you call functions faster. But remember, this version might not be perfectly stable and we might change it a lot later. A big shout-out to @rzubek for helping us add this feature. Although I liked his work, I didn't have enough time to look into it thoroughly. Still, the tests I did showed it was working, so I decided to add his feature to our code. This lets everyone use it now. Even though I'm busy moving houses and didn't have much time, seeing @rzubek's help made things a lot easier for me.
- Support for New Models: This update also includes support for new models that OpenAI recently launched. I've also changed the naming style to match OpenAI's. Model names will no longer start with 'chat'; instead, they'll start with 'gpt_3_5' and so on.
### 7.0.0
- The code now supports .NET 7.0. Big cheers to @BroMarduk for making this happen.
- The library now automatically disposes of the Httpclient when it's created by the constructor. This feature is thanks to @BroMarduk.
- New support has been added for using more than one instance at the same time. Check out this [link](https://github.com/betalgo/openai/wiki/Working-with-Multiple-Instances) for more details. Thanks to @remixtedi for bringing this to my attention.
- A lot of small improvements have been done by @BroMarduk.
- **Breaking Changes** 😢
- I've removed 'GPT3' from the namespace, so you might need to modify some aspects of your project. But don't worry, it's pretty simple! For instance, instead of writing `using OpenAI.GPT3.Interfaces`, you'll now write `using OpenAI.Interfaces`.
- The order of the OpenAI constructor parameters has changed. It now takes 'options' first, then 'httpclient'.
```csharp
//Before
var openAiService = new OpenAIService(httpClient, options);
//Now
var openAiService = new OpenAIService(options, httpClient);
```

0 comments on commit 74db2ed

Please sign in to comment.