Skip to content

Commit

Permalink
Version 6.6.1 Support for string or stringArray properties
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhantolga committed Dec 26, 2022
1 parent d366495 commit 5dea415
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 17 deletions.
4 changes: 2 additions & 2 deletions OpenAI.Playground/OpenAI.Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="1.0.6" />
<PackageReference Include="LaserCatEyes.HttpClientListener" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
var sdk = serviceProvider.GetRequiredService<IOpenAIService>();

//await ModelTestHelper.FetchModelsTest(sdk);
await EditTestHelper.RunSimpleEditCreateTest(sdk);
//await EditTestHelper.RunSimpleEditCreateTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageEditTest(sdk);
//await ImageTestHelper.RunSimpleCreateImageVariationTest(sdk);
//await ModerationTestHelper.CreateModerationTest(sdk);
//await CompletionTestHelper.RunSimpleCompletionTest(sdk);
await CompletionTestHelper.RunSimpleCompletionTest(sdk);
//await EmbeddingTestHelper.RunSimpleEmbeddingTest(sdk);
//await FileTestHelper.RunSimpleFileTest(sdk);
////await FineTuningTestHelper.CleanUpAllFineTunings(sdk); //!!!!! will delete all fine-tunings
Expand Down
1 change: 1 addition & 0 deletions OpenAI.Playground/TestHelpers/CompletionTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static async Task RunSimpleCompletionTest(IOpenAIService sdk)
var completionResult = await sdk.Completions.CreateCompletion(new CompletionCreateRequest()
{
Prompt = "Once upon a time",
// PromptAsList = new []{"Once upon a time"},
MaxTokens = 5
}, Models.Davinci);

Expand Down
2 changes: 1 addition & 1 deletion OpenAI.Playground/TestHelpers/EmbeddingTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static async Task RunSimpleEmbeddingTest(IOpenAIService sdk)
ConsoleExtensions.WriteLine("Embedding Test:", ConsoleColor.DarkCyan);
var embeddingResult = await sdk.Embeddings.CreateEmbedding(new EmbeddingCreateRequest()
{
Input = new List<string> {"The quick brown fox jumped over the lazy dog."},
InputAsList = new List<string> {"The quick brown fox jumped over the lazy dog."},
Model = Models.TextSearchAdaDocV1
});

Expand Down
57 changes: 55 additions & 2 deletions OpenAI.SDK/ObjectModels/RequestModels/CompletionCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,38 @@ public record CompletionCreateRequest : IModelValidate, IOpenAiModels.ITemperatu
/// the model will generate as if from the beginning of a new document.
/// </summary>
/// <see cref="https://beta.openai.com/docs/api-reference/completions/create#completions/create-prompt" />
[JsonPropertyName("prompt")]
[JsonIgnore]
public string? Prompt { get; set; }

/// <summary>
/// The prompt(s) to generate completions for, encoded as a string, a list of strings, or a list of token lists.
/// Note that endoftext is the document separator that the model sees during training, so if a prompt is not specified
/// the model will generate as if from the beginning of a new document.
/// </summary>
/// <see cref="https://beta.openai.com/docs/api-reference/completions/create#completions/create-prompt" />
[JsonIgnore]
public IList<string>? PromptAsList { get; set; }

[JsonPropertyName("prompt")]
public IList<string>? PromptCalculated
{
get
{
if (Prompt != null && PromptAsList != null)
{
throw new ValidationException("Prompt and PromptAsList can not be assigned at the same time. One of them is should be null.");
}

if (Prompt != null)
{
return new List<string>() {Prompt};
}


return PromptAsList;
}
}

/// <summary>
/// The suffix that comes after a completion of inserted text.
/// </summary>
Expand Down Expand Up @@ -75,9 +104,33 @@ public record CompletionCreateRequest : IModelValidate, IOpenAiModels.ITemperatu
/// Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop
/// sequence.
/// </summary>
[JsonPropertyName("stop")]
public string? Stop { get; set; }

/// <summary>
/// Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop
/// sequence.
/// </summary>
public IList<string>? StopAsList { get; set; }

[JsonPropertyName("stop")]
public IList<string>? StopCalculated
{
get
{
if (Stop != null && StopAsList != null)
{
throw new ValidationException("Stop and StopAsList can not be assigned at the same time. One of them is should be null.");
}

if (Stop != null)
{
return new List<string>() {Stop};
}

return StopAsList;
}
}

/// <summary>
/// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far,
/// increasing the model's likelihood to talk about new topics.
Expand Down
41 changes: 34 additions & 7 deletions OpenAI.SDK/ObjectModels/RequestModels/CreateModerationRequest.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
using System.Text.Json.Serialization;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using OpenAI.GPT3.ObjectModels.SharedModels;

namespace OpenAI.GPT3.ObjectModels.RequestModels
{
public record CreateModerationRequest : IOpenAiModels.IModel
{
/// <summary>
/// The input text to classify
/// </summary>
[JsonPropertyName("input")]
public string Input { get; set; }

/// <summary>
/// Two content moderations models are available: text-moderation-stable and text-moderation-latest.
/// The default is text-moderation-latest which will be automatically upgraded over time. This ensures you are always
Expand All @@ -19,5 +14,37 @@ public record CreateModerationRequest : IOpenAiModels.IModel
/// </summary>
[JsonPropertyName("model")]
public string? Model { get; set; }

/// <summary>
/// The input text to classify
/// </summary>
[JsonIgnore]
public List<string>? InputAsList { get; set; }

/// <summary>
/// The input text to classify
/// </summary>
[JsonIgnore]
public string? Input { get; set; }


[JsonPropertyName("input")]
public IList<string>? InputCalculated
{
get
{
if (Input != null && InputAsList != null)
{
throw new ValidationException("Input and InputAsList can not be assigned at the same time. One of them is should be null.");
}

if (Input != null)
{
return new List<string>() {Input};
}

return InputAsList;
}
}
}
}
33 changes: 32 additions & 1 deletion OpenAI.SDK/ObjectModels/RequestModels/EmbeddingCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,39 @@ public record EmbeddingCreateRequest : IModelValidate, IOpenAiModels.IModel
/// observed inferior results when newlines are present.
/// </summary>
/// <see cref="https://beta.openai.com/docs/api-reference/embeddings/create#embeddings/create-input" />
[JsonIgnore]
public List<string>? InputAsList { get; set; }

/// <summary>
/// Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs
/// in a single request, pass an array of strings or array of token arrays. Each input must not exceed 2048 tokens in
/// length.
/// Unless your are embedding code, we suggest replacing newlines (`\n`) in your input with a single space, as we have
/// observed inferior results when newlines are present.
/// </summary>
/// <see cref="https://beta.openai.com/docs/api-reference/embeddings/create#embeddings/create-input" />
[JsonIgnore]
public string? Input { get; set; }


[JsonPropertyName("input")]
public List<string>? Input { get; set; }
public IList<string>? InputCalculated
{
get
{
if (Input != null && InputAsList != null)
{
throw new ValidationException("Input and InputAsList can not be assigned at the same time. One of them is should be null.");
}

if (Input != null)
{
return new List<string>() {Input};
}

return InputAsList;
}
}

/// <summary>
/// ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your
Expand Down
4 changes: 2 additions & 2 deletions OpenAI.SDK/OpenAI.GPT3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
<PackageProjectUrl>https://openai.com/</PackageProjectUrl>
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>6.6.0</Version>
<Version>6.6.1</Version>
<Authors>Tolga Kayhan, Betalgo</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>OpenAI GPT-3 and DALL·E dotnet SDK</Product>
<Description>Dotnet SDK for OpenAI GTP-3 and DALL·E</Description>
<RepositoryUrl>https://github.com/betalgo/openai/</RepositoryUrl>
<PackageTags>openAI,gpt-3,ai,betalgo,NLP,dalle,DALL·E,dall-e</PackageTags>
<PackageTags>openAI,gpt-3,ai,betalgo,NLP,dalle,DALL·E,dall-e,OpenAI,OpenAi,openAi,</PackageTags>
<PackageId>Betalgo.$(AssemblyName)</PackageId>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down

0 comments on commit 5dea415

Please sign in to comment.