From b66b7b60c93502fdca9e083c203d84f26626cae2 Mon Sep 17 00:00:00 2001 From: Roger Date: Thu, 2 Feb 2023 21:13:29 -0800 Subject: [PATCH] Update readme, fix signing key, fix typos and spelling --- OpenAI_API/Completions/CompletionEndpoint.cs | 2 +- OpenAI_API/EndpointBase.cs | 4 +- OpenAI_API/Files/FilesEndpoint.cs | 2 +- OpenAI_API/Model/ModelsEndpoint.cs | 2 +- OpenAI_API/OpenAI_API.csproj | 12 ++--- README.md | 54 +++++++++++++++++--- 6 files changed, 58 insertions(+), 18 deletions(-) diff --git a/OpenAI_API/Completions/CompletionEndpoint.cs b/OpenAI_API/Completions/CompletionEndpoint.cs index 4cf18b1..eaf463f 100644 --- a/OpenAI_API/Completions/CompletionEndpoint.cs +++ b/OpenAI_API/Completions/CompletionEndpoint.cs @@ -17,7 +17,7 @@ public class CompletionEndpoint : EndpointBase public CompletionRequest DefaultCompletionRequestArgs { get; set; } = new CompletionRequest() { Model = Model.DavinciText }; /// - /// The name of the enpoint, which is the final path segment in the API URL. For example, "completions". + /// The name of the endpoint, which is the final path segment in the API URL. For example, "completions". /// protected override string Endpoint { get { return "completions"; } } diff --git a/OpenAI_API/EndpointBase.cs b/OpenAI_API/EndpointBase.cs index 2734e96..5d74cfa 100644 --- a/OpenAI_API/EndpointBase.cs +++ b/OpenAI_API/EndpointBase.cs @@ -12,7 +12,7 @@ namespace OpenAI_API { /// - /// A base object for any OpenAI API enpoint, encompassing common functionality + /// A base object for any OpenAI API endpoint, encompassing common functionality /// public abstract class EndpointBase { @@ -33,7 +33,7 @@ internal EndpointBase(OpenAIAPI api) } /// - /// The name of the enpoint, which is the final path segment in the API URL. Must be overriden in a derived class. + /// The name of the endpoint, which is the final path segment in the API URL. Must be overriden in a derived class. /// protected abstract string Endpoint { get; } diff --git a/OpenAI_API/Files/FilesEndpoint.cs b/OpenAI_API/Files/FilesEndpoint.cs index 9eb9dc0..6721a2e 100644 --- a/OpenAI_API/Files/FilesEndpoint.cs +++ b/OpenAI_API/Files/FilesEndpoint.cs @@ -18,7 +18,7 @@ public class FilesEndpoint : EndpointBase internal FilesEndpoint(OpenAIAPI api) : base(api) { } /// - /// The name of the enpoint, which is the final path segment in the API URL. For example, "files". + /// The name of the endpoint, which is the final path segment in the API URL. For example, "files". /// protected override string Endpoint { get { return "files"; } } diff --git a/OpenAI_API/Model/ModelsEndpoint.cs b/OpenAI_API/Model/ModelsEndpoint.cs index 18e819b..a197e68 100644 --- a/OpenAI_API/Model/ModelsEndpoint.cs +++ b/OpenAI_API/Model/ModelsEndpoint.cs @@ -10,7 +10,7 @@ namespace OpenAI_API.Models public class ModelsEndpoint : EndpointBase { /// - /// The name of the enpoint, which is the final path segment in the API URL. For example, "models". + /// The name of the endpoint, which is the final path segment in the API URL. For example, "models". /// protected override string Endpoint { get { return "models"; } } diff --git a/OpenAI_API/OpenAI_API.csproj b/OpenAI_API/OpenAI_API.csproj index aa84576..0b17cc1 100644 --- a/OpenAI_API/OpenAI_API.csproj +++ b/OpenAI_API/OpenAI_API.csproj @@ -13,16 +13,14 @@ https://github.com/OkGoDoIt/OpenAI-API-dotnet OpenAI, AI, ML, API OpenAI API - Updated to work with the current API as of January 12, 2023. Deprecate the Search endpoint as OpenAI has removed that API. This version includes breaking changes around specifying models to keep up with OpenAI API changes. If you had any code which used the old "engines", that will need to be updated to "models". Support for insertion, edits, and embedding is coming soon. - True - D:\OneDrive - Roger Pincombe\Assets\rsa keys\okgodoit-signing.pfx - false + Updated to work with the current API as of February 2, 2023. Added Files and Embedding endpoints. Removed the Search endpoint as OpenAI has removed that API. OpenAI - 1.3.0 - 1.3.0.0 - 1.3.0.0 + 1.4.0 + 1.4.0.0 + 1.4.0.0 True README.md + True diff --git a/README.md b/README.md index f1df16b..86a11f6 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ A simple C# .NET wrapper library to use with OpenAI's GPT-3 API. More context [ ## Status Updated to work with the current API as of February 2, 2023. Added Files and Embedding endpoints. Removed the Search endpoint as OpenAI has removed that API. -Thank you [@GotMike](https://github.com/gotmike), [@metjuperry](https://github.com/metjuperry), and [@Alexei000](https://github.com/Alexei000) for your contributions! +Thank you [@GotMike](https://github.com/gotmike), [@gmilano](https://github.com/gmilano), [@metjuperry](https://github.com/metjuperry), and [@Alexei000](https://github.com/Alexei000) for your contributions! ## Quick Example ```csharp var api = new OpenAI_API.OpenAIAPI(); -var result = await api.Completions.CreateCompletionAsync("One Two Three One Two", temperature: 0.1); -Console.WriteLine(result.ToString()); +var result = await api.Completions.GetCompletion("One Two Three One Two"); +Console.WriteLine(result); // should print something starting with "Three" ``` @@ -66,7 +66,7 @@ OpenAIAPI api = new OpenAIAPI(new APIAuthentication("YOUR_API_KEY","org-yourOrgH The Completion API is accessed via `OpenAIAPI.Completions`: ```csharp -CreateCompletionAsync(CompletionRequest request) +async Task CreateCompletionAsync(CompletionRequest request) // for example var result = await api.Completions.CreateCompletionAsync(new CompletionRequest("One Two Three One Two", model: Model.CurieText, temperature: 0.1)); @@ -92,7 +92,7 @@ await foreach (var token in api.Completions.StreamCompletionEnumerableAsync(new Or if using classic .NET framework or C# <8.0: ```csharp -StreamCompletionAsync(CompletionRequest request, Action resultHandler) +async Task StreamCompletionAsync(CompletionRequest request, Action resultHandler) // for example await api.Completions.StreamCompletionAsync( @@ -100,9 +100,51 @@ await api.Completions.StreamCompletionAsync( res => ResumeTextbox.Text += res.ToString()); ``` +### Embeddings +The Embedding API is accessed via `OpenAIAPI.Embeddings`: + +```csharp +async Task CreateEmbeddingAsync(EmbeddingRequest request) + +// for example +var result = await api.Embeddings.CreateEmbeddingAsync(new EmbeddingRequest("A test text for embedding", model: Model.AdaTextEmbedding)); +// or +var result = await api.Completions.CreateCompletionAsync("A test text for embedding"); +``` + +The embedding result contains a lot of metadata, the actual vector of floats is in result.Data[].Embedding. + +For simplicity, you can directly ask for the vector of floats and disgard the extra metadata with `api.Embeddings.GetEmbeddingsAsync("test text here")` + +### Files (for fine-tuning) +The Files API endpoint is accessed via `OpenAIAPI.Files`: + +```csharp +// uploading +async Task UploadFileAsync(string filePath, string purpose = "fine-tune") + +// for example +var response = await api.Files.UploadFileAsync("fine-tuning-data.jsonl"); +Console.Write(response.Id); //the id of the uploaded file + +// listing +async Task> GetFilesAsync() + +// for example +var response = await api.Files.GetFilesAsync(); +foreach (var file in response) +{ + Console.WriteLine(file.Name) +} +``` + +There are also methods to get file contents, delete a file, etc. + +The fine-tuning endpoint itself has not yet been implemented, but will be added soon. + ## Documentation -Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to ping me on Twitter [@OkGoDoIt](https://twitter.com/OkGoDoIt) if you have any questions. Better documentation may come later. +Every single class, method, and property has extensive XML documentation, so it should show up automatically in IntelliSense. That combined with the official OpenAI documentation should be enough to get started. Feel free to open an issue here if you have any questions. Better documentation may come later. ## License ![CC-0 Public Domain](https://licensebuttons.net/p/zero/1.0/88x31.png)