AI Dev Kit
Search Results for

    Show / Hide Table of Contents

    Class AssistantsAPIv2

    The Assistants API allows you to build AI assistants within your own applications. An Assistant has instructions and can leverage models, tools, and files to respond to user queries. The Assistants API currently supports three types of tools: Code Interpreter, File Search, and Function calling.

    Inheritance
    object
    AssistantsAPIv2
    Namespace: Glitch9.AIDevKit.OpenAI.Assistants
    Assembly: .dll
    Syntax
    public sealed class AssistantsAPIv2
    Remarks

    AssistantTool now uses Assistants APIv2. Assistants APIv1 will no longer be used. (Updated on 2024-05-23 by Munchkin)

    Constructors

    AssistantsAPIv2(AssistantOptions, RunRequest, string, string)

    Declaration
    public AssistantsAPIv2(AssistantOptions options, RunRequest defaultRunOptions = null, string overrideThreadId = null, string overrideAssistantId = null)
    Parameters
    Type Name Description
    AssistantOptions options
    RunRequest defaultRunOptions
    string overrideThreadId
    string overrideAssistantId

    Fields

    MIN_INTERNAL_OPERATION_MILLIS

    The minimum interval between operations in milliseconds.

    Declaration
    public const int MIN_INTERNAL_OPERATION_MILLIS = 1000
    Field Value
    Type Description
    int

    MIN_INTERVAL_REQUEST_MILLIS

    The minimum interval between requests in milliseconds.

    Declaration
    public const int MIN_INTERVAL_REQUEST_MILLIS = 2000
    Field Value
    Type Description
    int

    Properties

    Assistant

    Current assistant object used by this tool.

    Declaration
    public Assistant Assistant { get; set; }
    Property Value
    Type Description
    Assistant

    AssistantFetchCount

    Gets or sets the assistant fetch count.

    Declaration
    public int AssistantFetchCount { get; set; }
    Property Value
    Type Description
    int

    AssistantId

    Gets or sets the current assistant ID.

    Declaration
    public string AssistantId { get; set; }
    Property Value
    Type Description
    string

    AssistantStatus

    Gets the current stage of the Assistants API.

    Declaration
    public AssistantStatus AssistantStatus { get; }
    Property Value
    Type Description
    AssistantStatus

    Client

    Gets the OpenAiClient instance used by this tool.

    Declaration
    public OpenAI Client { get; }
    Property Value
    Type Description
    OpenAI

    DefaultRunRequest

    Gets or sets the default run request options for this tool.

    Declaration
    public RunRequest DefaultRunRequest { get; set; }
    Property Value
    Type Description
    RunRequest

    Description

    Gets or sets the description of this assistant.

    Declaration
    public string Description { get; set; }
    Property Value
    Type Description
    string

    EventHandler

    Gets or sets the event handler for assistant-related events.

    Declaration
    public AssistantEventHandler EventHandler { get; set; }
    Property Value
    Type Description
    AssistantEventHandler

    EventStreamHandler

    Gets or sets the event stream handler for assistant-related events.

    Declaration
    public IAssistantEventStreamHandler EventStreamHandler { get; set; }
    Property Value
    Type Description
    IAssistantEventStreamHandler

    ForcedTool

    If not null, it forces this AssistantsAPI to use a specific tool on every request.

    Declaration
    public ToolChoice ForcedTool { get; set; }
    Property Value
    Type Description
    ToolChoice

    Id

    Local unique identifier for this AssistantsAPI. This has nothing to do with OpenAI api.

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    Instructions

    Gets or sets the instructions for this assistant.

    Declaration
    public string Instructions { get; set; }
    Property Value
    Type Description
    string

    IsBusy

    Indicates whether the AssistantsAPI is busy.

    Declaration
    public bool IsBusy { get; }
    Property Value
    Type Description
    bool

    IsInitialized

    Indicates whether the AssistantsAPI instance is initialized.

    Declaration
    public bool IsInitialized { get; }
    Property Value
    Type Description
    bool

    LastAssistantMessage

    Last assistant message received from the AssistantsAPI.

    Declaration
    public ThreadMessage LastAssistantMessage { get; }
    Property Value
    Type Description
    ThreadMessage

    LastRequest

    Last request object sent to the AssistantsAPI.

    Declaration
    public ThreadMessageRequest LastRequest { get; }
    Property Value
    Type Description
    ThreadMessageRequest

    LastToolMessage

    Last tool message received from the AssistantsAPI.

    Declaration
    public ThreadMessage LastToolMessage { get; }
    Property Value
    Type Description
    ThreadMessage

    LastUserMessage

    Last user message sent to the AssistantsAPI.

    Declaration
    public ThreadMessage LastUserMessage { get; }
    Property Value
    Type Description
    ThreadMessage

    LogRunStatusChange

    Indicates whether to log run status changes.

    Declaration
    public bool LogRunStatusChange { get; set; }
    Property Value
    Type Description
    bool

    MaxRequestLength

    Gets or sets the maximum request length.

    Declaration
    public int MaxRequestLength { get; set; }
    Property Value
    Type Description
    int

    Metadata

    Gets or sets the metadata associated with this assistant.

    Declaration
    public Dictionary<string, string> Metadata { get; set; }
    Property Value
    Type Description
    Dictionary<string, string>

    MinTokenRequirementPerRequest

    Gets or sets the minimum token requirement per request.

    Declaration
    public int MinTokenRequirementPerRequest { get; set; }
    Property Value
    Type Description
    int

    Model

    Gets or sets the GPT model used by this assistant.

    Declaration
    public Model Model { get; set; }
    Property Value
    Type Description
    Model

    Name

    Gets or sets the name of this assistant.

    Declaration
    public string Name { get; set; }
    Property Value
    Type Description
    string

    RequiredActions

    Gets the required actions.

    Declaration
    public Dictionary<string, RequiredActionStack> RequiredActions { get; }
    Property Value
    Type Description
    Dictionary<string, RequiredActionStack>

    RequiresAction

    Indicates whether the AssistantsAPI requires action.

    Declaration
    public bool RequiresAction { get; }
    Property Value
    Type Description
    bool

    ResponseFormat

    Gets or sets the response format for this assistant.

    Declaration
    public TextFormat? ResponseFormat { get; set; }
    Property Value
    Type Description
    TextFormat?

    Run

    Current run object used by this tool.

    Declaration
    public Run Run { get; set; }
    Property Value
    Type Description
    Run

    RunId

    Gets the current run ID.

    Declaration
    public string RunId { get; }
    Property Value
    Type Description
    string

    RunStatus

    Gets the current run status of the Assistants API.

    Declaration
    public RunStatus RunStatus { get; }
    Property Value
    Type Description
    RunStatus

    RunStep

    Current run step object used by this tool.

    Declaration
    public RunStep RunStep { get; set; }
    Property Value
    Type Description
    RunStep

    SaveThreadMessages

    Indicates whether to save thread messages.

    Declaration
    public bool SaveThreadMessages { get; set; }
    Property Value
    Type Description
    bool

    SavedMessages

    Gets the saved messages.

    Declaration
    public PrefsDictionary<string, ThreadMessage> SavedMessages { get; }
    Property Value
    Type Description
    PrefsDictionary<string, ThreadMessage>

    Sender

    Gets or sets the sender name.

    Declaration
    public string Sender { get; set; }
    Property Value
    Type Description
    string

    Stream

    Indicates if the tool is set to stream (not supported yet).

    Declaration
    public bool Stream { get; set; }
    Property Value
    Type Description
    bool

    Temperature

    Gets or sets the temperature setting for this assistant's responses.

    Declaration
    public float Temperature { get; set; }
    Property Value
    Type Description
    float

    Thread

    Current thread object used by this tool.

    Declaration
    public Thread Thread { get; set; }
    Property Value
    Type Description
    Thread

    ThreadId

    Gets or sets the current thread ID.

    Declaration
    public string ThreadId { get; set; }
    Property Value
    Type Description
    string

    ToolResources

    Give the tools like code_interpreter and file_search access to files. Files are uploaded using the File upload endpoint and must have the purpose set to assistants to be used with this API.

    Declaration
    public ToolResources ToolResources { get; set; }
    Property Value
    Type Description
    ToolResources

    Tools

    Give the Assistant access to up to 128 tools. You can give it access to OpenAI-hosted tools like code_interpreter and file_search, or call a third-party tools via a function calling.

    Declaration
    public List<ToolCall> Tools { get; set; }
    Property Value
    Type Description
    List<ToolCall>

    TopP

    Gets or sets the top-p setting for this assistant's responses.

    Declaration
    public float TopP { get; set; }
    Property Value
    Type Description
    float

    Methods

    CancelRunAsync()

    Cancels the current run operation.

    Declaration
    public UniTask CancelRunAsync()
    Returns
    Type Description
    UniTask

    A UniTask representing the asynchronous operation.

    DeleteThreadAsync(string)

    Delete the thread with the threadId.

    Declaration
    public UniTask<bool> DeleteThreadAsync(string threadId)
    Parameters
    Type Name Description
    string threadId
    Returns
    Type Description
    UniTask<bool>

    GetThreadIds()

    Get all thread ids from the OpenAI API server.

    Declaration
    public List<string> GetThreadIds()
    Returns
    Type Description
    List<string>

    InitializeAsync(Action)

    Initializes the AssistantsAPI instance asynchronously.

    Declaration
    public UniTask InitializeAsync(Action onInitialized = null)
    Parameters
    Type Name Description
    Action onInitialized
    Returns
    Type Description
    UniTask

    A UniTask representing the asynchronous operation.

    RequestAsync(AudioClip, RunRequest)

    Declaration
    public UniTask<AssistantResult> RequestAsync(AudioClip audioPrompt, RunRequest customRunRequest = null)
    Parameters
    Type Name Description
    AudioClip audioPrompt
    RunRequest customRunRequest
    Returns
    Type Description
    UniTask<AssistantResult>

    RequestAsync(ThreadMessageRequest, RunRequest)

    Declaration
    public UniTask<AssistantResult> RequestAsync(ThreadMessageRequest messageRequest, RunRequest customRunRequest = null)
    Parameters
    Type Name Description
    ThreadMessageRequest messageRequest
    RunRequest customRunRequest
    Returns
    Type Description
    UniTask<AssistantResult>

    RequestAsync(TranscriptionRequest, RunRequest)

    Declaration
    public UniTask<AssistantResult> RequestAsync(TranscriptionRequest transcriptionRequest, RunRequest customRunRequest = null)
    Parameters
    Type Name Description
    TranscriptionRequest transcriptionRequest
    RunRequest customRunRequest
    Returns
    Type Description
    UniTask<AssistantResult>

    RequestAsync(UniAudioFile, RunRequest)

    Declaration
    public UniTask<AssistantResult> RequestAsync(UniAudioFile audioPrompt, RunRequest customRunRequest = null)
    Parameters
    Type Name Description
    UniAudioFile audioPrompt
    RunRequest customRunRequest
    Returns
    Type Description
    UniTask<AssistantResult>

    RequestAsync(string, RunRequest)

    Requests a response from the assistant asynchronously.

    Declaration
    public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest = null)
    Parameters
    Type Name Description
    string textPrompt

    The text prompt to send to the assistant.

    RunRequest customRunRequest

    Optional custom run request options.

    Returns
    Type Description
    UniTask<AssistantResult>

    A task representing the result of the request.

    RequestAsync(string, RunRequest, params UniImageFile[])

    Declaration
    public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params UniImageFile[] imageFiles)
    Parameters
    Type Name Description
    string textPrompt
    RunRequest customRunRequest
    UniImageFile[] imageFiles
    Returns
    Type Description
    UniTask<AssistantResult>

    RequestAsync(string, RunRequest, params string[])

    Declaration
    public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params string[] imageUrls)
    Parameters
    Type Name Description
    string textPrompt
    RunRequest customRunRequest
    string[] imageUrls
    Returns
    Type Description
    UniTask<AssistantResult>

    SetCodeInterpreterEnabledAsync(bool)

    Enable or disable the CodeInterpreterCall.

    Declaration
    public UniTask<bool> SetCodeInterpreterEnabledAsync(bool enabled)
    Parameters
    Type Name Description
    bool enabled
    Returns
    Type Description
    UniTask<bool>

    Returns true if the tool is enabled successfully.

    SetCurrentThreadAsync(string)

    Switch to the existing thread with threadId. The thread with the threadId must exist.

    Declaration
    public UniTask<Thread> SetCurrentThreadAsync(string threadId)
    Parameters
    Type Name Description
    string threadId
    Returns
    Type Description
    UniTask<Thread>

    SetFileSearchEnabledAsync(bool)

    Enable or disable the FileSearchCall.

    Declaration
    public UniTask<bool> SetFileSearchEnabledAsync(bool enabled)
    Parameters
    Type Name Description
    bool enabled
    Returns
    Type Description
    UniTask<bool>

    Returns true if the tool is enabled successfully.

    StartNewThreadAsync(bool)

    Create a new thread and set it as the current thread. If deleteCurrent is true, the current thread will be deleted before creating a new one.

    Declaration
    public UniTask StartNewThreadAsync(bool deleteCurrent = false)
    Parameters
    Type Name Description
    bool deleteCurrent
    Returns
    Type Description
    UniTask

    SubmitToolOutput(string, string)

    Declaration
    public UniTask<AssistantResult> SubmitToolOutput(string toolCallId, string outputToSubmit)
    Parameters
    Type Name Description
    string toolCallId
    string outputToSubmit
    Returns
    Type Description
    UniTask<AssistantResult>

    UpdateAssistantAsync(AssistantRequest)

    Update(modify) the assistant with the AssistantRequest.

    Declaration
    public UniTask<Assistant> UpdateAssistantAsync(AssistantRequest request)
    Parameters
    Type Name Description
    AssistantRequest request
    Returns
    Type Description
    UniTask<Assistant>
    In this article
    Back to top Generated by DocFX