Skip to content

Commit

Permalink
fix reporting somewhat, organize stats. Not really any new capabiliti…
Browse files Browse the repository at this point in the history
…es, though.
  • Loading branch information
ernop committed Feb 25, 2024
1 parent 9f0f96b commit 370cff6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
32 changes: 9 additions & 23 deletions OpenAI_API/EndpointBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -154,33 +155,18 @@ private async Task<HttpResponseMessage> HttpRequestRaw(string url = null, HttpMe
{
throw new HttpRequestException("OpenAI had an internal server error, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url));
}
else if (resultAsString.IndexOf("504 Gateway Time-out") !=-1)
{
//resultAsString == "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n
throw new HttpRequestException("OpenAI had a 504 Gateway Time-out, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url));
}
else
{
var errorToThrow = new HttpRequestException(GetErrorMessage(resultAsString, response, Endpoint, url));
ApiErrorResponse? parsedError;
try
{
parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString);
}
catch (Exception ex)
{
//typically gateway timeout 504
//"<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n"
if (resultAsString == "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body>\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>openresty/1.21.4.2</center>\r\n</body>\r\n</html>\r\n")
{
parsedError = new ApiErrorResponse();
parsedError.Error = new ApiErrorResponseError();
parsedError.Error.Message = "504 Gateway Time-out";
parsedError.Error.ErrorType = "Gateway Time-out";
parsedError.Error.Parameter = "N/A";
parsedError.Error.ErrorCode = "504";
}
else
{
var a = 3;
throw ex;
}
}

parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString);

try
{
errorToThrow.Data.Add("message", parsedError.Error.Message);
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ messageWithImage.images.Add(ImageInput.FromImageUrl("https://rogerpincombe.com/t
chat.AppendUserInput("What colors do these logos have in common?", ImageInput.FromFile("path/to/logo.png"), ImageInput.FromImageUrl("https://rogerpincombe.com/templates/rp/center-aligned-no-shadow-small.png"));
```


#### Conversation History Context Length Management
If the chat conversation history gets too long, it may not fit into the context length of the model. By default, the earliest non-system message(s) will be removed from the chat history and the API call will be retried. You may disable this by setting `chat.AutoTruncateOnContextLengthExceeded = false`, or you can override the truncation algorithm like this:

Expand Down Expand Up @@ -262,8 +261,6 @@ Console.WriteLine(results);
*/
```



### Completions API
Completions are considered legacy by OpenAI. The Completion API is accessed via `OpenAIAPI.Completions`:

Expand Down Expand Up @@ -407,7 +404,6 @@ The embedding result contains a lot of metadata, the actual vector of floats is

For simplicity, you can directly ask for the vector of floats and disgard the extra metadata with `api.Embeddings.GetEmbeddingsAsync("test text here")`


### Moderation
The Moderation API is accessed via `OpenAIAPI.Moderation`:

Expand All @@ -424,7 +420,6 @@ Console.WriteLine(result.results[0].MainContentFlag);

The results are in `.results[0]` and have nice helper methods like `FlaggedCategories` and `MainContentFlag`.


### Files (for fine-tuning)
The Files API endpoint is accessed via `OpenAIAPI.Files`:

Expand Down

0 comments on commit 370cff6

Please sign in to comment.