OpenAIToolkit 1.0.3
dotnet add package OpenAIToolkit --version 1.0.3
NuGet\Install-Package OpenAIToolkit -Version 1.0.3
<PackageReference Include="OpenAIToolkit" Version="1.0.3" />
<PackageVersion Include="OpenAIToolkit" Version="1.0.3" />
<PackageReference Include="OpenAIToolkit" />
paket add OpenAIToolkit --version 1.0.3
#r "nuget: OpenAIToolkit, 1.0.3"
#:package OpenAIToolkit@1.0.3
#addin nuget:?package=OpenAIToolkit&version=1.0.3
#tool nuget:?package=OpenAIToolkit&version=1.0.3
OpenAIToolkit
OpenAIToolkit is a .NET library that provides a convenient way to interact with the OpenAI API. It simplifies the process of creating assistants, managing threads, and performing various operations using the OpenAI API.
Installation
You can install OpenAIToolkit via NuGet Package Manager in Visual Studio or by running the following command in the Package Manager Console:
Install-Package OpenAIToolkit
Configuration
Before using the services provided by OpenAIToolkit, configure the toolkit with your API key and other necessary parameters
var configuration = new OpenAIToolkitConfiguration
{
ApiKey = "YOUR_API_KEY",
BaseUrl = "https://api.openai.com/v1/",
DefaultTimeout = 60 // Timeout in seconds
};
### AssistanceService
The `AssistanceService` class provides methods for creating assistants, managing threads, and interacting with the OpenAI API.
#### Creating an Assistant
To create a new assistant, use the `CreateAssistantAsync` method:
```csharp
var assistanceService = new AssistanceService("YOUR_API_KEY", loggerMock.Object);
var createAssistantRequest = new CreateAssistantRequest
{
Model = "gpt-3.5-turbo",
Name = "Test Assistant",
Instructions = "You are a helpful assistant."
};
var assistantResponse = await assistanceService.CreateAssistantAsync(createAssistantRequest);
string assistantId = assistantResponse.Id;
Creating a Thread
To create a new thread, use the CreateThreadAsync method:
var threadResponse = await assistanceService.CreateThreadAsync();
string threadId = threadResponse.Id;
Adding a Message to a Thread
To add a message to a thread, use the AddMessageToThreadAsync method:
await assistanceService.AddMessageToThreadAsync(threadId, "user", "Hello, how are you?");
Running an Assistant
To run an assistant and get a response, use the RunAssistantAsync and GetAssistantResponseAsync methods:
var runResponse = await assistanceService.RunAssistantAsync(threadId, assistantId);
string runId = runResponse.Id;
string runStatus;
do
{
await Task.Delay(1000);
runStatus = await assistanceService.CheckRunStatusAsync(threadId, runId);
} while (runStatus == "queued" || runStatus == "in_progress");
if (runStatus == "completed")
{
var assistantResponse = await assistanceService.GetAssistantResponseAsync(threadId);
string response = assistantResponse.Data[0].Content.Last().Text.Value;
Console.WriteLine($"Assistant: {response}");
}
AudioService
The AudioService class provides methods for creating speech, transcribing audio, and translating audio using the OpenAI API.
Creating Speech
To create speech from text, use the CreateSpeechAsync method:
var audioService = new AudioService("YOUR_API_KEY", loggerMock.Object);
string text = "Hello, how are you?";
byte[] audioData = await audioService.CreateSpeechAsync(text);
Transcribing Audio
To transcribe audio, use the CreateTranscriptionAsync method:
byte[] audioData = File.ReadAllBytes("path/to/your/audio/file.wav");
string transcription = await audioService.CreateTranscriptionAsync(audioData);
Translating Audio
To translate audio, use the CreateTranslationAsync method:
byte[] audioData = File.ReadAllBytes("path/to/your/audio/file.wav");
string translation = await audioService.CreateTranslationAsync(audioData);
Examples
For more detailed examples and usage scenarios, please refer to the OpenAIToolkit documentation.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please create an issue or submit a pull request on the GitHub repository.
License
OpenAIToolkit is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.