https://github.com/stefh/openai
OpenAI related projects
https://github.com/stefh/openai
Last synced: 8 months ago
JSON representation
OpenAI related projects
- Host: GitHub
- URL: https://github.com/stefh/openai
- Owner: StefH
- License: mit
- Created: 2023-04-18T18:54:41.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-10T15:18:55.000Z (over 2 years ago)
- Last Synced: 2024-04-14T13:08:16.662Z (about 2 years ago)
- Language: C#
- Size: 3.41 MB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenAI
OpenAI related projects...
## OpenAI.Polly
This is an extension for the [OpenAI](https://github.com/OkGoDoIt/OpenAI-API-dotnet) project: a C#/.NET SDK for accessing the OpenAI GPT-3 API, ChatGPT, and DALL-E 2.
[Polly](https://github.com/App-vNext/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
}
}
```
### Usage
```csharp
IOpenAIAPI openAiAPI = new OpenAIAPI("Your OpenAI API-Key", "Your Organization ID");
float[] embeddings = await openAiAPI.Embeddings.WithRetry(embeddings => embeddings.GetEmbeddingsAsync("What is a cat?"));
```
### Logging using Dependency Injection
If you want to use a logger to log these exceptions, use the following code during your Dependency Injection configuration phase:
```csharp
var serviceProvider = ...; // The service provider you use for Dependency Injection
serviceProvider.UseOpenAIWithPolly();
```
Note that these exceptions are logged as `Debug` level.
## :books:
See also https://mstack.nl/blogs/20230623-chatgpt-question-pdf-document/