OpenAI related projects...
This is an extension for the OpenAI project: a C#/.NET SDK for accessing the OpenAI GPT-3 API, ChatGPT, and DALL-E 2.
Polly is used to handle exceptions like:
Unhandled exception. System.Net.Http.HttpRequestException: Error at embeddings (https://api.openai.com/v1/embeddings) with HTTP status code: TooManyRequests. Content: {
"error": {
"message": "Rate limit reached for default-global-with-image-limits in organization org-*** on requests per min. Limit: 60 / min. Please try again in 1s. Contact support@openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method.",
"type": "requests",
"param": null,
"code": null
}
}
IOpenAIAPI openAiAPI = new OpenAIAPI("Your OpenAI API-Key", "Your Organization ID");
float[] embeddings = await openAiAPI.Embeddings.WithRetry(embeddings => embeddings.GetEmbeddingsAsync("What is a cat?"));
If you want to use a logger to log these exceptions, use the following code during your Dependency Injection configuration phase:
var serviceProvider = ...; // The service provider you use for Dependency Injection
serviceProvider.UseOpenAIWithPolly();
Note that these exceptions are logged as Debug
level.