Class AssistantsAPIv2
- Namespace
- Glitch9.AIDevKit.OpenAI.Assistants
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.
public sealed class AssistantsAPIv2
- Inheritance
-
objectAssistantsAPIv2
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)
public AssistantsAPIv2(AssistantOptions options, RunRequest defaultRunOptions = null, string overrideThreadId = null, string overrideAssistantId = null)
Parameters
optionsAssistantOptionsdefaultRunOptionsRunRequestoverrideThreadIdstringoverrideAssistantIdstring
Fields
MIN_INTERNAL_OPERATION_MILLIS
The minimum interval between operations in milliseconds.
public const int MIN_INTERNAL_OPERATION_MILLIS = 1000
Field Value
- int
MIN_INTERVAL_REQUEST_MILLIS
The minimum interval between requests in milliseconds.
public const int MIN_INTERVAL_REQUEST_MILLIS = 2000
Field Value
- int
Properties
Assistant
Current assistant object used by this tool.
public Assistant Assistant { get; set; }
Property Value
AssistantFetchCount
Gets or sets the assistant fetch count.
public int AssistantFetchCount { get; set; }
Property Value
- int
AssistantId
Gets or sets the current assistant ID.
public string AssistantId { get; set; }
Property Value
- string
AssistantStatus
Gets the current stage of the Assistants API.
public AssistantStatus AssistantStatus { get; }
Property Value
Client
Gets the OpenAiClient instance used by this tool.
public OpenAI Client { get; }
Property Value
DefaultRunRequest
Gets or sets the default run request options for this tool.
public RunRequest DefaultRunRequest { get; set; }
Property Value
Description
Gets or sets the description of this assistant.
public string Description { get; set; }
Property Value
- string
EventHandler
Gets or sets the event handler for assistant-related events.
public AssistantEventHandler EventHandler { get; set; }
Property Value
EventStreamHandler
Gets or sets the event stream handler for assistant-related events.
public IAssistantEventStreamHandler EventStreamHandler { get; set; }
Property Value
ForcedTool
If not null, it forces this AssistantsAPI to use a specific tool on every request.
public ToolChoice ForcedTool { get; set; }
Property Value
Id
Local unique identifier for this AssistantsAPI. This has nothing to do with OpenAI api.
public string Id { get; set; }
Property Value
- string
Instructions
Gets or sets the instructions for this assistant.
public string Instructions { get; set; }
Property Value
- string
IsBusy
Indicates whether the AssistantsAPI is busy.
public bool IsBusy { get; }
Property Value
- bool
IsInitialized
Indicates whether the AssistantsAPI instance is initialized.
public bool IsInitialized { get; }
Property Value
- bool
LastAssistantMessage
Last assistant message received from the AssistantsAPI.
public ThreadMessage LastAssistantMessage { get; }
Property Value
LastRequest
Last request object sent to the AssistantsAPI.
public ThreadMessageRequest LastRequest { get; }
Property Value
LastToolMessage
Last tool message received from the AssistantsAPI.
public ThreadMessage LastToolMessage { get; }
Property Value
LastUserMessage
Last user message sent to the AssistantsAPI.
public ThreadMessage LastUserMessage { get; }
Property Value
LogRunStatusChange
Indicates whether to log run status changes.
public bool LogRunStatusChange { get; set; }
Property Value
- bool
MaxRequestLength
Gets or sets the maximum request length.
public int MaxRequestLength { get; set; }
Property Value
- int
Metadata
Gets or sets the metadata associated with this assistant.
public Dictionary<string, string> Metadata { get; set; }
Property Value
- Dictionary<string, string>
MinTokenRequirementPerRequest
Gets or sets the minimum token requirement per request.
public int MinTokenRequirementPerRequest { get; set; }
Property Value
- int
Model
Gets or sets the GPT model used by this assistant.
public Model Model { get; set; }
Property Value
Name
Gets or sets the name of this assistant.
public string Name { get; set; }
Property Value
- string
RequiredActions
Gets the required actions.
public Dictionary<string, RequiredActionStack> RequiredActions { get; }
Property Value
- Dictionary<string, RequiredActionStack>
RequiresAction
Indicates whether the AssistantsAPI requires action.
public bool RequiresAction { get; }
Property Value
- bool
ResponseFormat
Gets or sets the response format for this assistant.
public TextFormat? ResponseFormat { get; set; }
Property Value
Run
Current run object used by this tool.
public Run Run { get; set; }
Property Value
RunId
Gets the current run ID.
public string RunId { get; }
Property Value
- string
RunStatus
Gets the current run status of the Assistants API.
public RunStatus RunStatus { get; }
Property Value
RunStep
Current run step object used by this tool.
public RunStep RunStep { get; set; }
Property Value
SaveThreadMessages
Indicates whether to save thread messages.
public bool SaveThreadMessages { get; set; }
Property Value
- bool
SavedMessages
Gets the saved messages.
public PrefsDictionary<string, ThreadMessage> SavedMessages { get; }
Property Value
- PrefsDictionary<string, ThreadMessage>
Sender
Gets or sets the sender name.
public string Sender { get; set; }
Property Value
- string
Stream
Indicates if the tool is set to stream (not supported yet).
public bool Stream { get; set; }
Property Value
- bool
Temperature
Gets or sets the temperature setting for this assistant's responses.
public float Temperature { get; set; }
Property Value
- float
Thread
Current thread object used by this tool.
public Thread Thread { get; set; }
Property Value
ThreadId
Gets or sets the current thread ID.
public string ThreadId { get; set; }
Property Value
- 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.
public ToolResources ToolResources { get; set; }
Property Value
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.
public List<ToolCall> Tools { get; set; }
Property Value
- List<ToolCall>
TopP
Gets or sets the top-p setting for this assistant's responses.
public float TopP { get; set; }
Property Value
- float
Methods
CancelRunAsync()
Cancels the current run operation.
public UniTask CancelRunAsync()
Returns
- UniTask
A UniTask representing the asynchronous operation.
DeleteThreadAsync(string)
Delete the thread with the threadId.
public UniTask<bool> DeleteThreadAsync(string threadId)
Parameters
threadIdstring
Returns
- UniTask<bool>
GetThreadIds()
Get all thread ids from the OpenAI API server.
public List<string> GetThreadIds()
Returns
- List<string>
InitializeAsync(Action)
Initializes the AssistantsAPI instance asynchronously.
public UniTask InitializeAsync(Action onInitialized = null)
Parameters
onInitializedAction
Returns
- UniTask
A UniTask representing the asynchronous operation.
RequestAsync(AudioClip, RunRequest)
public UniTask<AssistantResult> RequestAsync(AudioClip audioPrompt, RunRequest customRunRequest = null)
Parameters
audioPromptAudioClipcustomRunRequestRunRequest
Returns
- UniTask<AssistantResult>
RequestAsync(ThreadMessageRequest, RunRequest)
public UniTask<AssistantResult> RequestAsync(ThreadMessageRequest messageRequest, RunRequest customRunRequest = null)
Parameters
messageRequestThreadMessageRequestcustomRunRequestRunRequest
Returns
- UniTask<AssistantResult>
RequestAsync(TranscriptionRequest, RunRequest)
public UniTask<AssistantResult> RequestAsync(TranscriptionRequest transcriptionRequest, RunRequest customRunRequest = null)
Parameters
transcriptionRequestTranscriptionRequestcustomRunRequestRunRequest
Returns
- UniTask<AssistantResult>
RequestAsync(UniAudioFile, RunRequest)
public UniTask<AssistantResult> RequestAsync(UniAudioFile audioPrompt, RunRequest customRunRequest = null)
Parameters
audioPromptUniAudioFilecustomRunRequestRunRequest
Returns
- UniTask<AssistantResult>
RequestAsync(string, RunRequest)
Requests a response from the assistant asynchronously.
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest = null)
Parameters
textPromptstringThe text prompt to send to the assistant.
customRunRequestRunRequestOptional custom run request options.
Returns
- UniTask<AssistantResult>
A task representing the result of the request.
RequestAsync(string, RunRequest, params UniImageFile[])
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params UniImageFile[] imageFiles)
Parameters
textPromptstringcustomRunRequestRunRequestimageFilesUniImageFile[]
Returns
- UniTask<AssistantResult>
RequestAsync(string, RunRequest, params string[])
public UniTask<AssistantResult> RequestAsync(string textPrompt, RunRequest customRunRequest, params string[] imageUrls)
Parameters
textPromptstringcustomRunRequestRunRequestimageUrlsstring[]
Returns
- UniTask<AssistantResult>
SetCodeInterpreterEnabledAsync(bool)
Enable or disable the CodeInterpreterCall.
public UniTask<bool> SetCodeInterpreterEnabledAsync(bool enabled)
Parameters
enabledbool
Returns
- 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.
public UniTask<Thread> SetCurrentThreadAsync(string threadId)
Parameters
threadIdstring
Returns
- UniTask<Thread>
SetFileSearchEnabledAsync(bool)
Enable or disable the FileSearchCall.
public UniTask<bool> SetFileSearchEnabledAsync(bool enabled)
Parameters
enabledbool
Returns
- 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.
public UniTask StartNewThreadAsync(bool deleteCurrent = false)
Parameters
deleteCurrentbool
Returns
- UniTask
SubmitToolOutput(string, string)
public UniTask<AssistantResult> SubmitToolOutput(string toolCallId, string outputToSubmit)
Parameters
toolCallIdstringoutputToSubmitstring
Returns
- UniTask<AssistantResult>
UpdateAssistantAsync(AssistantRequest)
Update(modify) the assistant with the AssistantRequest.
public UniTask<Assistant> UpdateAssistantAsync(AssistantRequest request)
Parameters
requestAssistantRequest
Returns
- UniTask<Assistant>