Class AssistantController
Formarly AssistantsAPIv2, this class is now called AssistantController.
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
AssistantController
Assembly: .dll
Syntax
public sealed class AssistantController
Constructors
AssistantController(AssistantSettings, RunRequest)
Declaration
public AssistantController(AssistantSettings settings, RunRequest defaultRunRequest = null)
Parameters
Fields
MIN_INTERNAL_OPERATION_MILLIS
The minimum interval between operations in milliseconds.
Declaration
public const int MIN_INTERNAL_OPERATION_MILLIS = 1000
Field Value
MIN_INTERVAL_REQUEST_MILLIS
The minimum interval between requests in milliseconds.
Declaration
public const int MIN_INTERVAL_REQUEST_MILLIS = 2000
Field Value
SavedThreadMessages
Declaration
public static PrefsDictionary<string, ThreadMessage> SavedThreadMessages
Field Value
Properties
AssistantId
Declaration
public string AssistantId { get; }
Property Value
AssistantName
Gets or sets the name of this assistant.
Declaration
public string AssistantName { get; set; }
Property Value
AssistantStatus
Gets the current stage of the Assistants API.
Declaration
public AssistantStatus AssistantStatus { get; }
Property Value
AutoCancelOnRequiredAction
Declaration
public bool AutoCancelOnRequiredAction { get; set; }
Property Value
Client
Gets the OpenAiClient instance used by this tool.
Declaration
public OpenAI Client { get; }
Property Value
CurrentAssistant
The current assistant instance.
Declaration
public Assistant CurrentAssistant { get; }
Property Value
CurrentRun
The current run instance.
Declaration
public Run CurrentRun { get; set; }
Property Value
CurrentRunId
Declaration
public string CurrentRunId { get; }
Property Value
CurrentRunStep
The current run step instance.
Declaration
public RunStep CurrentRunStep { get; set; }
Property Value
CurrentThread
The current thread instance.
Declaration
public Thread CurrentThread { get; set; }
Property Value
CurrentThreadId
Declaration
public string CurrentThreadId { get; }
Property Value
DefaultRunRequest
Gets or sets the default run request options for this tool.
Declaration
public RunRequest DefaultRunRequest { get; }
Property Value
Description
Gets or sets the description of this assistant.
Declaration
public string Description { get; set; }
Property Value
If not null, it forces this AssistantsAPI to use a specific tool on every request.
Declaration
public ToolChoice ForcedTool { get; set; }
Property Value
Instructions
Gets or sets the instructions for this assistant.
Declaration
public string Instructions { get; set; }
Property Value
IsBusy
Indicates whether the AssistantsAPI is busy.
Declaration
public bool IsBusy { get; }
Property Value
IsInitialized
Indicates whether the AssistantsAPI instance is initialized.
Declaration
public bool IsInitialized { get; }
Property Value
LastAssistantMessage
The last assistant message received from the AssistantsAPI.
Declaration
public ThreadMessage LastAssistantMessage { get; }
Property Value
LastMessageRequest
The last ThreadMessageRequest sent to the AssistantsAPI.
Declaration
public ThreadMessageRequest LastMessageRequest { get; }
Property Value
Last tool message received from the AssistantsAPI.
Declaration
public ThreadMessage LastToolMessage { get; }
Property Value
LastUserMessage
The last user message sent to the AssistantsAPI.
Declaration
public ThreadMessage LastUserMessage { get; }
Property Value
MaxRequestLength
Gets or sets the maximum request length.
Declaration
public int MaxRequestLength { get; set; }
Property Value
Messages
Declaration
public List<ThreadMessage> Messages { get; }
Property Value
Gets or sets the metadata associated with this assistant.
Declaration
public Dictionary<string, string> Metadata { get; set; }
Property Value
Type |
Description |
Dictionary<string, string> |
|
Model
Gets or sets the GPT model used by this assistant.
Declaration
public Model Model { get; set; }
Property Value
OneTimeRunRequest
Declaration
public RunRequest OneTimeRunRequest { get; }
Property Value
RequiredActionTimeoutSeconds
Declaration
public int RequiredActionTimeoutSeconds { get; set; }
Property Value
RequiredActions
Declaration
public List<string> RequiredActions { get; }
Property Value
Type |
Description |
List<string> |
|
RequiresAction
Indicates whether the AssistantsAPI requires action.
Declaration
public bool RequiresAction { get; }
Property Value
Gets or sets the response format for this assistant.
Declaration
public TextFormat? ResponseFormat { get; set; }
Property Value
RunStatus
Gets the current run status of the Assistants API.
Declaration
public RunStatus RunStatus { get; }
Property Value
SaveMessagesToPrefs
Indicates whether to save thread messages.
Declaration
public bool SaveMessagesToPrefs { get; set; }
Property Value
Stream
Indicates if the tool is set to stream (not supported yet).
Declaration
public bool Stream { get; set; }
Property Value
Temperature
Gets or sets the temperature setting for this assistant's responses.
Declaration
public float Temperature { get; set; }
Property Value
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
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
TopP
Gets or sets the top-p setting for this assistant's responses.
Declaration
public float TopP { get; set; }
Property Value
Methods
CancelRunAsync()
Cancels the current run operation.
Declaration
public UniTask CancelRunAsync()
Returns
Type |
Description |
UniTask |
A UniTask representing the asynchronous operation.
|
CreateThreadAsync(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<Thread> CreateThreadAsync(bool deleteCurrent = false)
Parameters
Type |
Name |
Description |
bool |
deleteCurrent |
|
Returns
Type |
Description |
UniTask<Thread> |
|
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> |
|
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.
|
LoadThreadAsync(string)
Switch to the existing thread with threadId.
The thread with the threadId must exist.
Declaration
public UniTask<Thread> LoadThreadAsync(string threadId)
Parameters
Type |
Name |
Description |
string |
threadId |
|
Returns
Type |
Description |
UniTask<Thread> |
|
RequestAsync(AudioClip, RunRequest)
Declaration
public UniTask<ThreadMessage> RequestAsync(AudioClip audioPrompt, RunRequest runRequest = null)
Parameters
Type |
Name |
Description |
AudioClip |
audioPrompt |
|
RunRequest |
runRequest |
|
Returns
RequestAsync(ThreadMessageRequest, RunRequest)
Declaration
public UniTask<ThreadMessage> RequestAsync(ThreadMessageRequest messageRequest, RunRequest runRequest = null)
Parameters
Returns
RequestAsync(TranscriptionRequest, RunRequest)
Declaration
public UniTask<ThreadMessage> RequestAsync(TranscriptionRequest transcriptionRequest, RunRequest runRequest = null)
Parameters
Returns
RequestAsync(File<AudioClip>, RunRequest)
Declaration
public UniTask<ThreadMessage> RequestAsync(File<AudioClip> audioPrompt, RunRequest runRequest = null)
Parameters
Type |
Name |
Description |
File<AudioClip> |
audioPrompt |
|
RunRequest |
runRequest |
|
Returns
RequestAsync(string, RunRequest)
Requests a response from the assistant asynchronously.
Declaration
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest = null)
Parameters
Type |
Name |
Description |
string |
textPrompt |
The text prompt to send to the assistant.
|
RunRequest |
runRequest |
Optional custom run request options.
|
Returns
Type |
Description |
UniTask<ThreadMessage> |
A task representing the result of the request.
|
RequestAsync(string, RunRequest, params File<Texture2D>[])
Declaration
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest, params File<Texture2D>[] imageFiles)
Parameters
Type |
Name |
Description |
string |
textPrompt |
|
RunRequest |
runRequest |
|
File<Texture2D>[] |
imageFiles |
|
Returns
RequestAsync(string, RunRequest, params string[])
Declaration
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest, params string[] imageUrls)
Parameters
Type |
Name |
Description |
string |
textPrompt |
|
RunRequest |
runRequest |
|
string[] |
imageUrls |
|
Returns
Declaration
public UniTask<ThreadMessage> SubmitToolOutputAsync(string toolCallId, string outputToSubmit)
Parameters
Type |
Name |
Description |
string |
toolCallId |
|
string |
outputToSubmit |
|
Returns
UpdateAssistantAsync()
Update(modify) the assistant with the AssistantRequest.
Declaration
public UniTask<Assistant> UpdateAssistantAsync()
Returns