Class AssistantController
- Namespace
- Glitch9.AIDevKit.OpenAI.Assistants
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.
public sealed class AssistantController
- Inheritance
-
objectAssistantController
Remarks
AssistantTool now uses Assistants APIv2. Assistants APIv1 will no longer be used. (Updated on 2024-05-23 by Munchkin)
Constructors
AssistantController(AssistantSettings, RunRequest)
public AssistantController(AssistantSettings settings, RunRequest defaultRunRequest = null)
Parameters
settingsAssistantSettingsdefaultRunRequestRunRequest
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
SavedThreadMessages
public static PrefsDictionary<string, ThreadMessage> SavedThreadMessages
Field Value
- PrefsDictionary<string, ThreadMessage>
Properties
AssistantId
public string AssistantId { get; }
Property Value
- string
AssistantName
Gets or sets the name of this assistant.
public string AssistantName { get; set; }
Property Value
- string
AssistantStatus
Gets the current stage of the Assistants API.
public AssistantStatus AssistantStatus { get; }
Property Value
AutoCancelOnRequiredAction
public bool AutoCancelOnRequiredAction { get; set; }
Property Value
- bool
Client
Gets the OpenAiClient instance used by this tool.
public OpenAI Client { get; }
Property Value
CurrentAssistant
The current assistant instance.
public Assistant CurrentAssistant { get; }
Property Value
CurrentRun
The current run instance.
public Run CurrentRun { get; set; }
Property Value
CurrentRunId
The current run ID.
public string CurrentRunId { get; }
Property Value
- string
CurrentRunStep
The current run step instance.
public RunStep CurrentRunStep { get; set; }
Property Value
CurrentThread
The current thread instance.
public Thread CurrentThread { get; set; }
Property Value
CurrentThreadId
The current thread ID.
public string CurrentThreadId { get; }
Property Value
- string
DefaultRunRequest
Gets or sets the default run request options for this tool.
public RunRequest DefaultRunRequest { get; }
Property Value
Description
Gets or sets the description of this assistant.
public string Description { get; set; }
Property Value
- string
ForcedTool
If not null, it forces this AssistantsAPI to use a specific tool on every request.
public ToolChoice ForcedTool { get; set; }
Property Value
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
The last assistant message received from the AssistantsAPI.
public ThreadMessage LastAssistantMessage { get; }
Property Value
LastMessageRequest
The last ThreadMessageRequest sent to the AssistantsAPI.
public ThreadMessageRequest LastMessageRequest { get; }
Property Value
LastToolMessage
Last tool message received from the AssistantsAPI.
public ThreadMessage LastToolMessage { get; }
Property Value
LastUserMessage
The last user message sent to the AssistantsAPI.
public ThreadMessage LastUserMessage { get; }
Property Value
MaxRequestLength
Gets or sets the maximum request length.
public int MaxRequestLength { get; set; }
Property Value
- int
Messages
public List<ThreadMessage> Messages { get; }
Property Value
- List<ThreadMessage>
Metadata
Gets or sets the metadata associated with this assistant.
public Dictionary<string, string> Metadata { get; set; }
Property Value
- Dictionary<string, string>
Model
Gets or sets the GPT model used by this assistant.
public Model Model { get; set; }
Property Value
OneTimeRunRequest
public RunRequest OneTimeRunRequest { get; }
Property Value
RequiredActionTimeoutSeconds
public int RequiredActionTimeoutSeconds { get; set; }
Property Value
- int
RequiredActions
public List<string> RequiredActions { get; }
Property Value
- List<string>
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
RunStatus
Gets the current run status of the Assistants API.
public RunStatus RunStatus { get; }
Property Value
SaveMessagesToPrefs
Indicates whether to save thread messages.
public bool SaveMessagesToPrefs { get; set; }
Property Value
- bool
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
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.
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.
public UniTask<Thread> CreateThreadAsync(bool deleteCurrent = false)
Parameters
deleteCurrentbool
Returns
- UniTask<Thread>
DeleteThreadAsync(string)
Delete the thread with the threadId.
public UniTask<bool> DeleteThreadAsync(string threadId)
Parameters
threadIdstring
Returns
- UniTask<bool>
InitializeAsync(Action)
Initializes the AssistantsAPI instance asynchronously.
public UniTask InitializeAsync(Action onInitialized = null)
Parameters
onInitializedAction
Returns
- UniTask
A UniTask representing the asynchronous operation.
LoadThreadAsync(string)
Switch to the existing thread with threadId. The thread with the threadId must exist.
public UniTask<Thread> LoadThreadAsync(string threadId)
Parameters
threadIdstring
Returns
- UniTask<Thread>
RequestAsync(AudioClip, RunRequest)
public UniTask<ThreadMessage> RequestAsync(AudioClip audioPrompt, RunRequest runRequest = null)
Parameters
audioPromptAudioCliprunRequestRunRequest
Returns
- UniTask<ThreadMessage>
RequestAsync(ThreadMessageRequest, RunRequest)
public UniTask<ThreadMessage> RequestAsync(ThreadMessageRequest messageRequest, RunRequest runRequest = null)
Parameters
messageRequestThreadMessageRequestrunRequestRunRequest
Returns
- UniTask<ThreadMessage>
RequestAsync(TranscriptionRequest, RunRequest)
public UniTask<ThreadMessage> RequestAsync(TranscriptionRequest transcriptionRequest, RunRequest runRequest = null)
Parameters
transcriptionRequestTranscriptionRequestrunRequestRunRequest
Returns
- UniTask<ThreadMessage>
RequestAsync(File<AudioClip>, RunRequest)
public UniTask<ThreadMessage> RequestAsync(File<AudioClip> audioPrompt, RunRequest runRequest = null)
Parameters
audioPromptFile<AudioClip>runRequestRunRequest
Returns
- UniTask<ThreadMessage>
RequestAsync(string, RunRequest)
Requests a response from the assistant asynchronously.
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest = null)
Parameters
textPromptstringThe text prompt to send to the assistant.
runRequestRunRequestOptional custom run request options.
Returns
- UniTask<ThreadMessage>
A task representing the result of the request.
RequestAsync(string, RunRequest, params File<Texture2D>[])
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest, params File<Texture2D>[] imageFiles)
Parameters
textPromptstringrunRequestRunRequestimageFilesFile<Texture2D>[]
Returns
- UniTask<ThreadMessage>
RequestAsync(string, RunRequest, params string[])
public UniTask<ThreadMessage> RequestAsync(string textPrompt, RunRequest runRequest, params string[] imageUrls)
Parameters
textPromptstringrunRequestRunRequestimageUrlsstring[]
Returns
- UniTask<ThreadMessage>
SubmitToolOutputAsync(string, string)
public UniTask<ThreadMessage> SubmitToolOutputAsync(string toolCallId, string outputToSubmit)
Parameters
toolCallIdstringoutputToSubmitstring
Returns
- UniTask<ThreadMessage>
UpdateAssistantAsync()
Update(modify) the assistant with the AssistantRequest.
public UniTask<Assistant> UpdateAssistantAsync()
Returns
- UniTask<Assistant>