Skip to content

Commit 370cff6

Browse files
committed
fix reporting somewhat, organize stats. Not really any new capabilities, though.
1 parent 9f0f96b commit 370cff6

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

OpenAI_API/EndpointBase.cs

+9-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
23
using System;
34
using System.Collections.Generic;
45
using System.Diagnostics;
@@ -154,33 +155,18 @@ private async Task<HttpResponseMessage> HttpRequestRaw(string url = null, HttpMe
154155
{
155156
throw new HttpRequestException("OpenAI had an internal server error, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url));
156157
}
158+
else if (resultAsString.IndexOf("504 Gateway Time-out") !=-1)
159+
{
160+
//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
161+
throw new HttpRequestException("OpenAI had a 504 Gateway Time-out, which can happen occasionally. Please retry your request. " + GetErrorMessage(resultAsString, response, Endpoint, url));
162+
}
157163
else
158164
{
159165
var errorToThrow = new HttpRequestException(GetErrorMessage(resultAsString, response, Endpoint, url));
160166
ApiErrorResponse? parsedError;
161-
try
162-
{
163-
parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString);
164-
}
165-
catch (Exception ex)
166-
{
167-
//typically gateway timeout 504
168-
//"<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"
169-
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")
170-
{
171-
parsedError = new ApiErrorResponse();
172-
parsedError.Error = new ApiErrorResponseError();
173-
parsedError.Error.Message = "504 Gateway Time-out";
174-
parsedError.Error.ErrorType = "Gateway Time-out";
175-
parsedError.Error.Parameter = "N/A";
176-
parsedError.Error.ErrorCode = "504";
177-
}
178-
else
179-
{
180-
var a = 3;
181-
throw ex;
182-
}
183-
}
167+
168+
parsedError = JsonConvert.DeserializeObject<ApiErrorResponse>(resultAsString);
169+
184170
try
185171
{
186172
errorToThrow.Data.Add("message", parsedError.Error.Message);

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ messageWithImage.images.Add(ImageInput.FromImageUrl("https://rogerpincombe.com/t
179179
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"));
180180
```
181181

182-
183182
#### Conversation History Context Length Management
184183
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:
185184

@@ -262,8 +261,6 @@ Console.WriteLine(results);
262261
*/
263262
```
264263

265-
266-
267264
### Completions API
268265
Completions are considered legacy by OpenAI. The Completion API is accessed via `OpenAIAPI.Completions`:
269266

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

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

410-
411407
### Moderation
412408
The Moderation API is accessed via `OpenAIAPI.Moderation`:
413409

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

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

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

0 commit comments

Comments
 (0)