OpenAi_Assistant 1.0.4

dotnet add package OpenAi_Assistant --version 1.0.4                
NuGet\Install-Package OpenAi_Assistant -Version 1.0.4                
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="OpenAi_Assistant" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAi_Assistant --version 1.0.4                
#r "nuget: OpenAi_Assistant, 1.0.4"                
#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.
// Install OpenAi_Assistant as a Cake Addin
#addin nuget:?package=OpenAi_Assistant&version=1.0.4

// Install OpenAi_Assistant as a Cake Tool
#tool nuget:?package=OpenAi_Assistant&version=1.0.4                

OpenAi Assistant .NET API Wrapper

Dotnet SDK for OpenAI Assistants API (Currently Beta) Unofficial. OpenAI doesn't have any official .Net SDK.

Link to the OpenAI Assistant page: https://platform.openai.com/docs/assistants/overview

Visit the github page for documentation: https://github.com/samuelgjekic/OpenAI-Assistants-API-Wrapper-for-.NET

Install package:

dotnet add package OpenAi_Assistant --version 1.0.4
NuGet\Install-Package OpenAi_Assistant -Version 1.0.4

Information

Last week the new OpenAI Assistant API became available, i started testing it out and this is the SDK i created for it. Keep in mind the API is still in beta, and this wrapper is far from finished.

  • Accepting Contributions: I welcome contributions from the community to enhance and expand the functionality of this wrapper. Whether you want to add new features, improve existing code, or fix bugs, your contributions are highly appreciated!

Changelogs


### Changelog 1.0.4

- You can now fetch existing assistant using the assistant id. 



### Changelog 1.0.3

- Added methods to modify or delete existing assistant
- Fixed some code issues



### Changelog 1.0.2


- Added AssistantService to handle interactions with the OpenAI Assistants API.
- Introduced AssistantModel object to represent the properties of an assistant.
- Implemented IRunService interface to define the necessary functionalities for running the assistant.
- Updated the Assistant object to include relevant properties obtained when creating the assistant through the OpenAI Assistants API, such as ID and Name.

These changes enhance the professionalism and functionality of the codebase, providing a more robust and efficient system for managing and running assistants.

How to use

First you create the assistant, then you create the thread, when you have a thread you can add messages to it, when you want a response you need to run the thread and wait for the run operation to be completed, when the run operation completes we can read the response from the ai. Example:

// Best approach would be to load the api key from env vars
var aiService = new OpenAiAssistantService("YOUR-API-KEY"); 

// Create the assistant by passing the parameters, use models from OpenAiModel.<SelectedModel>
// You can pass instructions to the assistant, for example "You are a math tutor".
var assistant = await aiService.CreateAssistant(OpenAiModel.Gpt_3_5_Turbo,"Math tutor", ToolsModel.Code_Interpreter,"You are a math tutor");

// If you want to get existing assistant from the api, you can do so by using the assistant id as parameter.
var assistant = await aiServices.GetAssistantById("asst_MON1TnRldQ3JaDCae08QFx20");

// Create the thread that the assistant will run on
await aiService.CreateThread();


// Send a new message to the thread with the user role.
// You can send multiple messages to the thread.
await aiService.SendMsgToThread("msg","user");

// Start the run operation
await aiService.RunAssistant();

// Finally get the response from the assistant
var response = await aiService.GetResponseFromAssistant();

Console.WriteLine(response);

// You should dispose of the aiService when you are no longer using it.
aiService.Dispose();


// You can now retrieve assistant properties because the CreateAssistant method now returns the assistant object.
// Example:
var assistant_id = assistant.id;


// To modify existing assistant, change the values of the assistant object
assistant.name = "new name";
assistant.instructions = "new instructions";

// After changing the assistant object you will have to confirm the changes by calling the API to modify the assistant.
// This will send the modified assistant object and update the assistant in the thread.
assistant = aiService.assistant.ModifyAssistant(assistant);

// Delete existing assistant
assistant = aiService.assistant.DeleteAssistant(assistant);

For now you can access chatGPT3 turbo and chatGPT4 in the OpenAiModel class:

public class OpenAiModel
{


    /// <summary>
    ///     Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our
    ///     latest model iteration.
    /// </summary>
    public static string Gpt_3_5_Turbo => "gpt-3.5-turbo";

    /// <summary>
    ///     Same capabilities as the standard gpt-3.5-turbo model but with 4 times the context.
    /// </summary>
    public static string Gpt_3_5_Turbo_16k => "gpt-3.5-turbo-16k";


    /// <summary>
    ///     More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with
    ///     our latest model iteration.
    /// </summary>
    public static string Gpt_4 => "gpt-4";

}

ToDo

  • Need to make use of IHttpClientFactory
  • Need to add file support
  • Clean up code
  • Run Steps
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
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.

Version Downloads Last updated
1.0.4 1,129 11/12/2023
1.0.3 137 11/11/2023
1.0.2 130 11/11/2023
1.0.1 142 11/9/2023
1.0.0 149 11/8/2023 1.0.0 is deprecated because it has critical bugs.

Added method to fetch existing assistant from the api.