Skip to content

Commit 8c0978e

Browse files
authored
Merge pull request #60 from betalgo/dev
v6.6.3
2 parents 8d29178 + 84f0a79 commit 8c0978e

File tree

8 files changed

+49
-25
lines changed

8 files changed

+49
-25
lines changed

OpenAI.Playground/TestHelpers/CompletionTestHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static async Task RunSimpleCompletionTest(IOpenAIService sdk)
1717
{
1818
Prompt = "Once upon a time",
1919
// PromptAsList = new []{"Once upon a time"},
20-
MaxTokens = 5
20+
MaxTokens = 5,
21+
LogProbs = 1,
2122
}, Models.Davinci);
2223

2324
if (completionResult.Successful)

OpenAI.SDK/Managers/OpenAIService.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,7 @@ public partial class OpenAIService : IOpenAIService
1313

1414
[ActivatorUtilitiesConstructor]
1515
public OpenAIService(HttpClient httpClient, IOptions<OpenAiOptions> settings)
16-
{
17-
settings.Value.Validate();
18-
19-
_httpClient = httpClient;
20-
_httpClient.BaseAddress = new Uri(settings.Value.BaseDomain);
21-
var authKey = settings.Value.ApiKey;
22-
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {authKey}");
23-
var organization = settings.Value.Organization;
24-
if (!string.IsNullOrEmpty(organization))
25-
{
26-
_httpClient.DefaultRequestHeaders.Add("OpenAI-Organization", $"{organization}");
27-
}
28-
29-
_endpointProvider = new OpenAiEndpointProvider(settings.Value.ApiVersion);
30-
_engineId = OpenAiOptions.DefaultEngineId;
31-
}
16+
: this(settings.Value, httpClient) { }
3217

3318
public OpenAIService(OpenAiOptions settings, HttpClient? httpClient = null)
3419
{

OpenAI.SDK/ObjectModels/RequestModels/CompletionCreateRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace OpenAI.GPT3.ObjectModels.RequestModels
1010
/// <summary>
1111
/// Create Completion Request Model
1212
/// </summary>
13-
public record CompletionCreateRequest : IModelValidate, IOpenAiModels.ITemperature, IOpenAiModels.IModel, IOpenAiModels.ILogProbs, IOpenAiModels.IUser
13+
public record CompletionCreateRequest : IModelValidate, IOpenAiModels.ITemperature, IOpenAiModels.IModel, IOpenAiModels.ILogProbsRequest, IOpenAiModels.IUser
1414
{
1515
/// <summary>
1616
/// The prompt(s) to generate completions for, encoded as a string, a list of strings, or a list of token lists.

OpenAI.SDK/ObjectModels/SharedModels/ChoiceResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace OpenAI.GPT3.ObjectModels.SharedModels;
44

5-
public record ChoiceResponse : IOpenAiModels.ILogProbs
5+
public record ChoiceResponse : IOpenAiModels.ILogProbsResponse
66
{
77
[JsonPropertyName("text")] public string Text { get; set; }
88

99
[JsonPropertyName("index")] public int? Index { get; set; }
1010

1111
[JsonPropertyName("finish_reason")] public string FinishReason { get; set; }
1212

13-
[JsonPropertyName("logprobs")] public int? LogProbs { get; set; }
13+
[JsonPropertyName("logprobs")] public LogProbsResponse LogProbs { get; set; }
1414
}

OpenAI.SDK/ObjectModels/SharedModels/IOpenAiModels.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ public interface IModel
1212
string Model { get; set; }
1313
}
1414

15-
public interface ILogProbs
15+
public interface ILogProbsRequest
1616
{
1717
int? LogProbs { get; set; }
1818
}
1919

20+
public interface ILogProbsResponse
21+
{
22+
LogProbsResponse LogProbs { get; set; }
23+
}
24+
2025
public interface ITemperature
2126
{
2227
float? Temperature { get; set; }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Linq;
2+
using System.Text.Json.Serialization;
3+
4+
namespace OpenAI.GPT3.ObjectModels.SharedModels;
5+
6+
public record LogProbsResponse
7+
{
8+
[JsonPropertyName("tokens")] public List<string> Tokens { get; set; }
9+
10+
[JsonPropertyName("token_logprobs")] public List<double> TokenLogProbs { get; set; }
11+
12+
[JsonPropertyName("top_logprobs")] public List<Dictionary<string, double>> TopLogProbsRaw { get; set; }
13+
14+
public List<TopLogProbResponse> TopLogProbs => TopLogProbsRaw.SelectMany(r => r.Select(a=> new TopLogProbResponse()
15+
{
16+
Key = a.Key,
17+
LogProp= a.Value
18+
})).ToList();
19+
20+
[JsonPropertyName("text_offset")] public List<int> TextOffset { get; set; }
21+
}
22+
23+
public class TopLogProbResponse
24+
{
25+
public string Key { get; set; }
26+
public double LogProp { get; set; }
27+
}

OpenAI.SDK/OpenAI.GPT3.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageProjectUrl>https://openai.com/</PackageProjectUrl>
1010
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
1111
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
12-
<Version>6.6.2</Version>
12+
<Version>6.6.3</Version>
1313
<Authors>Tolga Kayhan, Betalgo</Authors>
1414
<Company>Betalgo Up Ltd.</Company>
1515
<Product>OpenAI GPT-3 and DALL·E dotnet SDK</Product>
@@ -19,6 +19,8 @@
1919
<PackageId>Betalgo.$(AssemblyName)</PackageId>
2020
<PackageReadmeFile>Readme.md</PackageReadmeFile>
2121
<GenerateDocumentationFile>True</GenerateDocumentationFile>
22+
<RepositoryUrl>https://github.com/betalgo/openai.git</RepositoryUrl>
23+
<RepositoryType>git</RepositoryType>
2224
</PropertyGroup>
2325
<ItemGroup>
2426
<None Include="..\Readme.md">

Readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Dotnet SDK for OpenAI GTP-3 and DALL·E
1+
# Dotnet SDK for OpenAI GPT-3 and DALL·E
22

33
[![Betalgo.OpenAI.GPT3](https://img.shields.io/nuget/v/Betalgo.OpenAI.GPT3?style=for-the-badge)](https://www.nuget.org/packages/Betalgo.OpenAI.GPT3/)
44

55
```
66
Install-Package Betalgo.OpenAI.GPT3
77
```
88

9-
Dotnet SDK for OpenAI GTP-3 and DALL·E
9+
Dotnet SDK for OpenAI GPT-3 and DALL·E
1010
*Unofficial*.
1111
*GPT-3 doesn't have any official .Net SDK.*
1212

@@ -109,8 +109,12 @@ As you can guess I do not accept any damage caused by use of the library. You ar
109109

110110

111111
## Changelog
112+
### 6.6.3
113+
* Bug-fix, now we are handling logprops response properly, thanks to @KosmonikOS
114+
* Code clean-up, thanks to @KosmonikOS
115+
112116
### 6.6.2
113-
* Bug-fix,added jsonignore for `stop` and `stopAsList`, thanks to @Patapum
117+
* Bug-fix,added jsonignore for `stop` and `stopAsList`, thanks to @Patapum
114118

115119
### 6.6.1
116120
* **Breaking change**.

0 commit comments

Comments
 (0)