Skip to content

Commit db6cd71

Browse files
authored
Merge pull request #24 from betalgo/dev
Version 6.4.0
2 parents e5a6424 + 5062b6e commit db6cd71

39 files changed

+387
-239
lines changed

OpenAI.Playground/Program.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@
1313
var serviceCollection = new ServiceCollection();
1414
serviceCollection.AddScoped(_ => configuration);
1515

16-
// Laser cat eyes will help us to track request and responses between OpenAI server and our client
17-
//It is in Beta version, if you have consider about your data privacy or if you don't want to use it just comment out from here
18-
19-
//get your app key from https://lasercateyes.com and put it under ApiSettings.json or secrets.json
16+
// Laser cat eyes is a tool that shows your requests and responses between OpenAI server and your client.
17+
// Get your app key from https://lasercateyes.com for FREE and put it under ApiSettings.json or secrets.json.
18+
// It is in Beta version, if you don't want to use it just comment out below line.
2019
serviceCollection.AddLaserCatEyesHttpClientListener();
20+
2121
serviceCollection.AddOpenAIService();
2222
//serviceCollection.AddOpenAIService(settings => { settings.ApiKey = "TEST"; });
2323

24-
25-
//// to here, and uncomment from here
26-
//serviceCollection.AddHttpClient<IOpenAIService, OpenAIService>();
27-
//// to here
2824
var serviceProvider = serviceCollection.BuildServiceProvider();
2925
var sdk = serviceProvider.GetRequiredService<IOpenAIService>();
3026

3127
await ModelTestHelper.FetchModelsTest(sdk);
28+
//await ModerationTestHelper.CreateModerationTest(sdk);
3229
//await CompletionTestHelper.RunSimpleCompletionTest(sdk);
3330
//await EmbeddingTestHelper.RunSimpleEmbeddingTest(sdk);
3431
//await FileTestHelper.RunSimpleFileTest(sdk);

OpenAI.Playground/TestHelpers/CompletionTestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static async Task RunSimpleCompletionTest(IOpenAIService sdk)
1313
try
1414
{
1515
ConsoleExtensions.WriteLine("Completion Test:", ConsoleColor.DarkCyan);
16-
var completionResult = await sdk.Completions.Create(new CompletionCreateRequest()
16+
var completionResult = await sdk.Completions.CreateCompletion(new CompletionCreateRequest()
1717
{
1818
Prompt = "Once upon a time",
1919
MaxTokens = 5

OpenAI.Playground/TestHelpers/EmbeddingTestHelper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using OpenAI.GPT3.Interfaces;
22
using OpenAI.GPT3.ObjectModels;
33
using OpenAI.GPT3.ObjectModels.RequestModels;
4-
using System.ComponentModel.DataAnnotations;
5-
using System.Numerics;
64

75
namespace OpenAI.Playground.TestHelpers
86
{
@@ -15,9 +13,9 @@ public static async Task RunSimpleEmbeddingTest(IOpenAIService sdk)
1513
try
1614
{
1715
ConsoleExtensions.WriteLine("Embedding Test:", ConsoleColor.DarkCyan);
18-
var embeddingResult = await sdk.Embeddings.Create(new EmbeddingCreateRequest()
16+
var embeddingResult = await sdk.Embeddings.CreateEmbedding(new EmbeddingCreateRequest()
1917
{
20-
Input = new List<string> { "The quick brown fox jumped over the lazy dog." },
18+
Input = new List<string> {"The quick brown fox jumped over the lazy dog."},
2119
Model = Models.TextSearchAdaDocV1
2220
});
2321

OpenAI.Playground/TestHelpers/FileTestHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public static async Task RunSimpleFileTest(IOpenAIService sdk)
2727
}
2828

2929
ConsoleExtensions.WriteLine("Listing files", ConsoleColor.Cyan);
30-
var uploadedFiles = await sdk.Files.FileList();
30+
var uploadedFiles = await sdk.Files.ListFile();
3131
// Need to wait for file processing before deleting it.
3232

3333
ConsoleExtensions.WriteLine("Need to wait for file processing", ConsoleColor.White);
3434
await Task.Delay(10_000);
3535
foreach (var uploadedFile in uploadedFiles.Data)
3636
{
3737
ConsoleExtensions.WriteLine($"Retrieving {uploadedFile.FileName}", ConsoleColor.DarkCyan);
38-
var retrieveFileResponse = await sdk.Files.FileRetrieve(uploadedFile.Id);
38+
var retrieveFileResponse = await sdk.Files.RetrieveFile(uploadedFile.Id);
3939
if (retrieveFileResponse.Successful)
4040
{
4141
ConsoleExtensions.WriteLine($"{retrieveFileResponse.FileName} retrieved", ConsoleColor.DarkGreen);
@@ -47,7 +47,7 @@ public static async Task RunSimpleFileTest(IOpenAIService sdk)
4747

4848
// var fileContent = sdk.Files.RetrieveFileContent(file.Id);
4949
ConsoleExtensions.WriteLine($"Deleting file {uploadedFile.FileName}", ConsoleColor.DarkCyan);
50-
var deleteResponse = await sdk.Files.FileDelete(uploadedFile.Id);
50+
var deleteResponse = await sdk.Files.DeleteFile(uploadedFile.Id);
5151
if (deleteResponse.Successful)
5252
{
5353
ConsoleExtensions.WriteLine($"{retrieveFileResponse.FileName} deleted", ConsoleColor.DarkGreen);
@@ -71,11 +71,11 @@ public static async Task CleanAllFiles(IOpenAIService sdk)
7171
try
7272
{
7373
Console.WriteLine("Starting to clean All Files");
74-
var uploadedFiles = await sdk.Files.FileList();
74+
var uploadedFiles = await sdk.Files.ListFile();
7575
foreach (var uploadedFile in uploadedFiles.Data)
7676
{
7777
Console.WriteLine(uploadedFile.FileName);
78-
var deleteResponse = await sdk.Files.FileDelete(uploadedFile.Id);
78+
var deleteResponse = await sdk.Files.DeleteFile(uploadedFile.Id);
7979
}
8080
}
8181
catch (Exception e)

OpenAI.Playground/TestHelpers/FineTuningTestHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public static async Task RunCaseStudyIsTheModelMakingUntrueStatements(IOpenAISer
5656

5757
do
5858
{
59-
var completionResult = await sdk.FineTunes.FineTuneCompletions(new FineTuneCompletionsRequest()
59+
var completionResult = await sdk.Completions.CreateCompletion(new CompletionCreateRequest()
6060
{
6161
MaxTokens = 1,
6262
Prompt = @"https://t.co/f93xEd2 Excited to share my latest blog post! ->",
6363
Model = retrieveFineTuneResponse.FineTunedModel,
64-
Logprobs = 2
64+
LogProbs = 2
6565
});
6666
if (completionResult.Successful)
6767
{

OpenAI.Playground/TestHelpers/ModelTestHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static async Task FetchModelsTest(IOpenAIService sdk)
1111
try
1212
{
1313
ConsoleExtensions.WriteLine("Fetching Model List", ConsoleColor.DarkCyan);
14-
var engineList = await sdk.Models.ModelList();
14+
var engineList = await sdk.Models.ListModel();
1515
if (engineList == null)
1616
{
1717
ConsoleExtensions.WriteLine("Fetching Model List failed", ConsoleColor.DarkRed);
@@ -25,7 +25,7 @@ public static async Task FetchModelsTest(IOpenAIService sdk)
2525
{
2626
ConsoleExtensions.WriteLine($"Retrieving Model:{engineItem.Id}", ConsoleColor.DarkCyan);
2727

28-
var retrieveEngineResponse = await sdk.Models.ModelRetrieve(engineItem.Id);
28+
var retrieveEngineResponse = await sdk.Models.RetrieveModel(engineItem.Id);
2929
if (retrieveEngineResponse.Successful)
3030
{
3131
Console.WriteLine(retrieveEngineResponse);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using OpenAI.GPT3.Interfaces;
2+
using OpenAI.GPT3.ObjectModels.RequestModels;
3+
4+
namespace OpenAI.Playground.TestHelpers
5+
{
6+
public class ModerationTestHelper
7+
{
8+
public static async Task CreateModerationTest(IOpenAIService sdk)
9+
{
10+
ConsoleExtensions.WriteLine("Create Moderation test is starting:", ConsoleColor.Cyan);
11+
12+
try
13+
{
14+
ConsoleExtensions.WriteLine("Create Moderation test", ConsoleColor.DarkCyan);
15+
var moderationResponse = await sdk.Moderation.CreateModeration(new CreateModerationRequest()
16+
{
17+
Input = "I want to kill them."
18+
});
19+
if (moderationResponse.Results.FirstOrDefault()?.Flagged != true)
20+
{
21+
ConsoleExtensions.WriteLine("Create Moderation test failed", ConsoleColor.DarkRed);
22+
}
23+
24+
ConsoleExtensions.WriteLine("Create Moderation test passed.", ConsoleColor.DarkGreen);
25+
}
26+
catch (Exception e)
27+
{
28+
Console.WriteLine(e);
29+
throw;
30+
}
31+
}
32+
}
33+
}

OpenAI.SDK/Interfaces/ICompletion.cs renamed to OpenAI.SDK/Interfaces/ICompletionService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace OpenAI.GPT3.Interfaces;
88
/// Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of
99
/// alternative tokens at each position.
1010
/// </summary>
11-
public interface ICompletion
11+
public interface ICompletionService
1212
{
1313
/// <summary>
1414
/// Creates a new completion for the provided prompt and parameters
1515
/// </summary>
1616
/// <param name="engineId">The ID of the engine to use for this request</param>
1717
/// <param name="createCompletionModel"></param>
1818
/// <returns></returns>
19-
Task<CompletionCreateResponse> Create(CompletionCreateRequest createCompletionModel, string? engineId = null);
19+
Task<CompletionCreateResponse> CreateCompletion(CompletionCreateRequest createCompletionModel, string? engineId = null);
2020

2121
/// <summary>
2222
/// Creates a new completion for the provided prompt and parameters
@@ -26,6 +26,6 @@ public interface ICompletion
2626
/// <returns></returns>
2727
Task<CompletionCreateResponse> Create(CompletionCreateRequest createCompletionModel, Models.Model engineId)
2828
{
29-
return Create(createCompletionModel, engineId.EnumToString());
29+
return CreateCompletion(createCompletionModel, engineId.EnumToString());
3030
}
3131
}

OpenAI.SDK/Interfaces/IEmbedding.cs renamed to OpenAI.SDK/Interfaces/IEmbeddingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace OpenAI.GPT3.Interfaces;
66
/// <summary>
77
/// Creates an embedding vector representing the input text.
88
/// </summary>
9-
public interface IEmbedding
9+
public interface IEmbeddingService
1010
{
1111
/// <summary>
1212
/// Creates a new embedding for the provided input and parameters.
1313
/// </summary>
1414
/// <param name="createEmbeddingModel"></param>
1515
/// <returns></returns>
16-
Task<EmbeddingCreateResponse> Create(EmbeddingCreateRequest createEmbeddingModel);
16+
Task<EmbeddingCreateResponse> CreateEmbedding(EmbeddingCreateRequest createEmbeddingModel);
1717
}

OpenAI.SDK/Interfaces/IFile.cs renamed to OpenAI.SDK/Interfaces/IFileService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
namespace OpenAI.GPT3.Interfaces;
77

8-
public interface IFile
8+
public interface IFileService
99
{
1010
/// <summary>
1111
/// Returns a list of files that belong to the user's organization.
1212
/// </summary>
1313
/// <returns></returns>
14-
Task<FileListResponse> FileList();
14+
Task<FileListResponse> ListFile();
1515

1616
/// <summary>
1717
/// Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all
@@ -30,41 +30,41 @@ public interface IFile
3030
/// to validate the format of the uploaded file.
3131
/// </param>
3232
/// <returns></returns>
33-
Task<FileUploadResponse> FileUpload(string purpose, byte[] file, string fileName);
33+
Task<FileUploadResponse> UploadFile(string purpose, byte[] file, string fileName);
3434

3535
Task<FileUploadResponse> FileUpload(string purpose, Stream file, string fileName)
3636
{
37-
return FileUpload(purpose, file.ToByteArray(), fileName);
37+
return UploadFile(purpose, file.ToByteArray(), fileName);
3838
}
3939

4040
Task<FileUploadResponse> FileUpload(UploadFilePurposes.UploadFilePurpose purpose, Stream file, string fileName)
4141
{
42-
return FileUpload(purpose.EnumToString(), file.ToByteArray(), fileName);
42+
return UploadFile(purpose.EnumToString(), file.ToByteArray(), fileName);
4343
}
4444

4545
Task<FileUploadResponse> FileUpload(UploadFilePurposes.UploadFilePurpose purpose, byte[] file, string fileName)
4646
{
47-
return FileUpload(purpose.EnumToString(), file, fileName);
47+
return UploadFile(purpose.EnumToString(), file, fileName);
4848
}
4949

5050
/// <summary>
5151
/// Delete a file.
5252
/// </summary>
5353
/// <param name="fileId">The ID of the file to use for this request</param>
5454
/// <returns></returns>
55-
Task<FileDeleteResponse> FileDelete(string fileId);
55+
Task<FileDeleteResponse> DeleteFile(string fileId);
5656

5757
/// <summary>
5858
/// Returns information about a specific file.
5959
/// </summary>
6060
/// <param name="fileId">The ID of the file to use for this request</param>
6161
/// <returns></returns>
62-
Task<FileResponse> FileRetrieve(string fileId);
62+
Task<FileResponse> RetrieveFile(string fileId);
6363

6464
/// <summary>
6565
/// Returns the contents of the specified file
6666
/// </summary>
6767
/// <param name="fileId">The ID of the file to use for this request</param>
6868
/// <returns></returns>
69-
Task FileRetrieveContent(string fileId);
69+
Task RetrieveFileContent(string fileId);
7070
}

0 commit comments

Comments
 (0)