OpenAIToolkit 1.0.3

dotnet add package OpenAIToolkit --version 1.0.3
                    
NuGet\Install-Package OpenAIToolkit -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenAIToolkit" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenAIToolkit" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="OpenAIToolkit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenAIToolkit --version 1.0.3
                    
#r "nuget: OpenAIToolkit, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenAIToolkit@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenAIToolkit&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=OpenAIToolkit&version=1.0.3
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.