From 0cfbd73e95344bad7669d24a3faac3f506d8ec27 Mon Sep 17 00:00:00 2001 From: Roger Date: Thu, 12 Jan 2023 04:45:42 -0800 Subject: [PATCH] Update to 1.3 and minor fix documentation errors --- OpenAI_API/Completions/CompletionEndpoint.cs | 18 +++++++------- OpenAI_API/Completions/CompletionRequest.cs | 8 +++---- OpenAI_API/Model/Model.cs | 2 -- OpenAI_API/Model/ModelsEndpoint.cs | 16 ++++++------- OpenAI_API/OpenAI_API.csproj | 25 +++++++++++++------- OpenAI_API/Search/SearchRequest.cs | 5 ++-- OpenAI_API/Search/SearchResponse.cs | 9 +++---- README.md | 5 ++-- 8 files changed, 49 insertions(+), 39 deletions(-) diff --git a/OpenAI_API/Completions/CompletionEndpoint.cs b/OpenAI_API/Completions/CompletionEndpoint.cs index 1759e24..37803e3 100644 --- a/OpenAI_API/Completions/CompletionEndpoint.cs +++ b/OpenAI_API/Completions/CompletionEndpoint.cs @@ -37,7 +37,7 @@ internal CompletionEndpoint(OpenAIAPI api) /// Ask the API to complete the prompt(s) using the specified request. This is non-streaming, so it will wait until the API returns the full result. /// /// The request to send to the API. This does not fall back to default values specified in . - /// Asynchronously returns the completion result. Look in its property for the completions. + /// Asynchronously returns the completion result. Look in its property for the completions. public async Task CreateCompletionAsync(CompletionRequest request) { if (Api.Auth?.ApiKey is null) @@ -83,7 +83,7 @@ public async Task CreateCompletionAsync(CompletionRequest requ /// /// The request to send to the API. This does not fall back to default values specified in . /// Overrides as a convenience. - /// Asynchronously returns the completion result. Look in its property for the completions, which should have a length equal to . + /// Asynchronously returns the completion result. Look in its property for the completions, which should have a length equal to . public Task CreateCompletionsAsync(CompletionRequest request, int numOutputs = 5) { request.NumChoicesPerPrompt = numOutputs; @@ -94,17 +94,17 @@ public Task CreateCompletionsAsync(CompletionRequest request, /// Ask the API to complete the prompt(s) using the specified parameters. This is non-streaming, so it will wait until the API returns the full result. Any non-specified parameters will fall back to default values specified in if present. /// /// The prompt to generate from - /// The model to use. You can use to see all of your available models, or use a standard model like . + /// The model to use. You can use to see all of your available models, or use a standard model like . /// How many tokens to complete to. Can return fewer if a stop sequence is hit. /// What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. It is generally recommend to use this or but not both. /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommend to use this or but not both. /// How many different choices to request for each prompt. /// The scale of the penalty applied if a token is already present at all. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. /// The scale of the penalty for how often a token is used. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. - /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. + /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. /// Echo back the prompt in addition to the completion. /// One or more sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. - /// Asynchronously returns the completion result. Look in its property for the completions. + /// Asynchronously returns the completion result. Look in its property for the completions. public Task CreateCompletionAsync(string prompt, Model model = null, int? max_tokens = null, @@ -232,11 +232,11 @@ public async Task StreamCompletionAsync(CompletionRequest request, Action - /// Ask the API to complete the prompt(s) using the specified request, and stream the results to the as they come in. + /// Ask the API to complete the prompt(s) using the specified request, and stream the results as they come in. /// If you are not using C# 8 supporting async enumerables or if you are using the .NET Framework, you may need to use instead. /// /// The request to send to the API. This does not fall back to default values specified in . - /// An async enumerable with each of the results as they come in. See for more details on how to consume an async enumerable. + /// An async enumerable with each of the results as they come in. See for more details on how to consume an async enumerable. public async IAsyncEnumerable StreamCompletionEnumerableAsync(CompletionRequest request) { if (Api.Auth?.ApiKey is null) @@ -293,14 +293,14 @@ public async IAsyncEnumerable StreamCompletionEnumerableAsync( /// If you are not using C# 8 supporting async enumerables or if you are using the .NET Framework, you may need to use instead. /// /// The prompt to generate from - /// The model to use. You can use to see all of your available models, or use a standard model like . + /// The model to use. You can use to see all of your available models, or use a standard model like . /// How many tokens to complete to. Can return fewer if a stop sequence is hit. /// What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. It is generally recommend to use this or but not both. /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommend to use this or but not both. /// How many different choices to request for each prompt. /// The scale of the penalty applied if a token is already present at all. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. /// The scale of the penalty for how often a token is used. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. - /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. + /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. /// Echo back the prompt in addition to the completion. /// One or more sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. /// An async enumerable with each of the results as they come in. See the C# docs for more details on how to consume an async enumerable. diff --git a/OpenAI_API/Completions/CompletionRequest.cs b/OpenAI_API/Completions/CompletionRequest.cs index 1d16ea9..583ca8f 100644 --- a/OpenAI_API/Completions/CompletionRequest.cs +++ b/OpenAI_API/Completions/CompletionRequest.cs @@ -15,7 +15,7 @@ namespace OpenAI_API public class CompletionRequest { /// - /// ID of the model to use. You can use to see all of your available models, or use a standard model like . + /// ID of the model to use. You can use to see all of your available models, or use a standard model like . /// [JsonProperty("model")] public string Model { get; set; } @@ -103,7 +103,7 @@ public string Prompt public bool Stream { get; internal set; } = false; /// - /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 5, the API will return a list of the 5 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. The maximum value for logprobs is 5. + /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 5, the API will return a list of the 5 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. The maximum value for logprobs is 5. /// [JsonProperty("logprobs")] public int? Logprobs { get; set; } @@ -209,7 +209,7 @@ public CompletionRequest(params string[] prompts) /// Creates a new with the specified parameters /// /// The prompt to generate from - /// The model to use. You can use to see all of your available models, or use a standard model like . + /// The model to use. You can use to see all of your available models, or use a standard model like . /// How many tokens to complete to. Can return fewer if a stop sequence is hit. /// What sampling temperature to use. Higher values means the model will take more risks. Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer. It is generally recommend to use this or but not both. /// The suffix that comes after a completion of inserted text @@ -217,7 +217,7 @@ public CompletionRequest(params string[] prompts) /// How many different choices to request for each prompt. /// The scale of the penalty applied if a token is already present at all. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. /// The scale of the penalty for how often a token is used. Should generally be between 0 and 1, although negative numbers are allowed to encourage token reuse. - /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. + /// Include the log probabilities on the logprobs most likely tokens, which can be found in -> . So for example, if logprobs is 10, the API will return a list of the 10 most likely tokens. If logprobs is supplied, the API will always return the logprob of the sampled token, so there may be up to logprobs+1 elements in the response. /// Echo back the prompt in addition to the completion. /// One or more sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence. public CompletionRequest( diff --git a/OpenAI_API/Model/Model.cs b/OpenAI_API/Model/Model.cs index 32d01af..1d321a4 100644 --- a/OpenAI_API/Model/Model.cs +++ b/OpenAI_API/Model/Model.cs @@ -46,8 +46,6 @@ public static implicit operator Model(string name) /// Represents an Model with the given id/ /// /// The id/ to use. - /// If the contains a colon (as is the case in the API's response), - /// the part before the colon is treated as the id/ and the following portion is considered the /// public Model(string name) { diff --git a/OpenAI_API/Model/ModelsEndpoint.cs b/OpenAI_API/Model/ModelsEndpoint.cs index 7856661..9c260ce 100644 --- a/OpenAI_API/Model/ModelsEndpoint.cs +++ b/OpenAI_API/Model/ModelsEndpoint.cs @@ -36,7 +36,7 @@ public Task> GetModelsAsync() } /// - /// Get details about a particular Model from the API, specifically properties such as and + /// Get details about a particular Model from the API, specifically properties such as and permissions. /// /// The id/name of the model to get more details about /// Asynchronously returns the with all available properties @@ -75,13 +75,13 @@ public static async Task> GetModelsAsync(APIAuthentication auth = nu } } - /// - /// Get details about a particular Model from the API, specifically properties such as and - /// - /// The id/name of the model to get more details about - /// API authentication in order to call the API endpoint. If not specified, attempts to use a default. - /// Asynchronously returns the with all available properties - public static async Task RetrieveModelDetailsAsync(string id, APIAuthentication auth = null) + /// + /// Get details about a particular Model from the API, specifically properties such as and permissions. + /// + /// The id/name of the model to get more details about + /// API authentication in order to call the API endpoint. If not specified, attempts to use a default. + /// Asynchronously returns the with all available properties + public static async Task RetrieveModelDetailsAsync(string id, APIAuthentication auth = null) { if (auth.ThisOrDefault()?.ApiKey is null) { diff --git a/OpenAI_API/OpenAI_API.csproj b/OpenAI_API/OpenAI_API.csproj index 70a4064..85c8c9e 100644 --- a/OpenAI_API/OpenAI_API.csproj +++ b/OpenAI_API/OpenAI_API.csproj @@ -6,23 +6,32 @@ true OkGoDoIt (Roger Pincombe) OpenAI API - A simple C# / .NET wrapper library to use with OpenAI's GPT-3 API (currently in beta). Independently developed, this is not an official library and I am not affiliated with OpenAI. An OpenAI API account is required. - + A simple C# / .NET wrapper library to use with OpenAI's GPT-3 API. Independently developed, this is not an official library and I am not affiliated with OpenAI. An OpenAI API account is required. + This library is licensed CC-0, in the public domain CC0-1.0 https://github.com/OkGoDoIt/OpenAI-API-dotnet https://github.com/OkGoDoIt/OpenAI-API-dotnet OpenAI, AI, ML, API OpenAI API - Added support for "echo" parameter, which echos back the prompt in responses (thanks to @GotMike!) Removed support for publishable API keys (and renamed secret keys to simply API keys) since OpenAI no longer supports publishable keys. Also fixed various typos in the documentation. - false - okgodoit-signing.pfx + 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 OpenAI - 1.2.0 - 1.2.0.0 - 1.2.0.0 + 1.3.0 + 1.3.0.0 + 1.3.0.0 + True + README.md + + + True + \ + + + diff --git a/OpenAI_API/Search/SearchRequest.cs b/OpenAI_API/Search/SearchRequest.cs index 994348d..b4bbb4f 100644 --- a/OpenAI_API/Search/SearchRequest.cs +++ b/OpenAI_API/Search/SearchRequest.cs @@ -6,7 +6,8 @@ namespace OpenAI_API { - public class SearchRequest + [Obsolete("OpenAI no long supports the Search endpoint")] + public class SearchRequest { [JsonProperty("documents")] @@ -16,7 +17,7 @@ public class SearchRequest public string Query { get; set; } /// - /// ID of the model to use. You can use to see all of your available models, or use a standard model like . Defaults to . + /// ID of the model to use. You can use to see all of your available models, or use a standard model like . Defaults to . /// [JsonProperty("model")] public string Model { get; set; } = OpenAI_API.Model.DavinciCode; diff --git a/OpenAI_API/Search/SearchResponse.cs b/OpenAI_API/Search/SearchResponse.cs index df8cc06..e1f625a 100644 --- a/OpenAI_API/Search/SearchResponse.cs +++ b/OpenAI_API/Search/SearchResponse.cs @@ -5,10 +5,11 @@ namespace OpenAI_API { - /// - /// Used internally to deserialize a result from the Document Search API - /// - public class SearchResult + /// + /// Used internally to deserialize a result from the Document Search API + /// + [Obsolete("OpenAI no long supports the Search endpoint")] + public class SearchResult { /// /// The index of the document as originally supplied diff --git a/README.md b/README.md index 2c34094..c895197 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,9 @@ A simple C# .NET wrapper library to use with OpenAI's GPT-3 API. More context [on my blog](https://rogerpincombe.com/openai-dotnet-api). ## Status -Updated to work with the current API as of January 12, 2023. Support for insertion, edits, and embedding is coming soon. -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. +Updated to work with the current API as of January 12, 2023. Deprecated 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. ## Quick Example