
Classes | |
| class | Response |
| class | StatusMutex |
| Helper class to act as a mutex for the status value, as it may be read by multiple threads. More... | |
Public Types | |
| enum | Status { Waiting , Listening , TextInput , VoiceInput } |
| Current status of the director. More... | |
Public Member Functions | |
| Director () | |
| void | Initialise (UnityAction< Director.Response > onDirectorResponse, CancellationToken cancellationToken) |
| bool | IsStatus (Status value) |
| async void | ListenForNextUserInput (DirectorConfig config, List< string > speakers, List< string > topics, CancellationToken cancellationToken) |
| bool | CancelListen () |
| async Awaitable< bool > | SubmitUserTextInput (string message, CancellationToken cancellationToken) |
Properties | |
| bool | EnableDebug = false [get, set] |
| bool | IsMicMuted = false [get, set] |
| bool | IsConnected = false [get, private set] |
Private Member Functions | |
| OpenAI.Realtime.SessionConfiguration | GetSessionConfiguration () |
| async void | RecordInputAudio (OpenAI.Realtime.RealtimeSession session, CancellationToken cancellationToken) |
| void | InvokeOnDirectorResponse () |
| void | OnServerEvent (IServerEvent @event) |
| void | SetStatus (Status value) |
| bool | TestAndSetStatus (Status condition, Status value) |
| OpenAI.Function | BuildTriggerResponseTool (List< string > speakers) |
| OpenAI.Function | BuildTriggerDiscussionTool (List< string > topics) |
| List< string > | ParseSpeakerOrder (string args) |
| string | ParseDiscussionTopic (string args) |
Private Attributes | |
| DirectorConfig | config = null |
| OpenAIClient | api = null |
| RealtimeSession | session = null |
| Director.Response | response = null |
| UnityAction< Director.Response > | onDirectorResponse = null |
| List< OpenAI.Tool > | tools = new List<OpenAI.Tool>() |
| StatusMutex | statusMutex = new StatusMutex() |
| string | latestItemId = string.Empty |
The director is the OpenAI Realtime model whose main function is to listen to the user's speech and decides the order in which the actors reply. For example, Athena can speak first, or Poseidon can speak first, or only one of them replies. The director has a secondary function of triggering a Discussion if the user mentions certain topics.
Definition at line 22 of file Director.cs.
Current status of the director.
| Enumerator | |
|---|---|
| Waiting | Idling and waiting for VoiceChat system. |
| Listening | Listening for user input. |
| TextInput | Replying to text input. |
| VoiceInput | Replying to voice input. |
Definition at line 24 of file Director.cs.
|
inline |
Definition at line 66 of file Director.cs.
|
inlineprivate |
Create a function following OpenAI's JSON Schema for the director to trigger a discussion based on a topic. OpenAI API on function calling: https://platform.openai.com/docs/guides/function-calling
| topics | The possible topics to trigger a discussion for. |
If there is no topic given, the AI tends to hallucinate a topic. To prevent that, add a couple of placeholder discussions with the most obscure, niche topic that the user is unlikely to ever trigger.
Definition at line 399 of file Director.cs.
|
inlineprivate |
Create a function following OpenAI's JSON Schema for the director to decide upon the speaker order. OpenAI API on function calling: https://platform.openai.com/docs/guides/function-calling
| speakers | The names of the speakers. |
Definition at line 372 of file Director.cs.
|
inline |
Definition at line 132 of file Director.cs.
|
inlineprivate |
Definition at line 161 of file Director.cs.
|
inline |
Initialise the director and connect to OpenAI's server.
| onDirectorResponse | The callback to invoke when the director has a response ready. |
| cancellationToken | Cancellation token used to cancel any async actions when the program shuts down. |
Definition at line 74 of file Director.cs.
|
inlineprivate |
If the director's response is ready, invoke the response callback.
Note that user transcript can come before or after the Response event!Note that user transcript can come before or after the Response event! OpenAI API Link: https://platform.openai.com/docs/api-reference/realtime-server-events/conversation/item/input_audio_transcription?utm_source=chatgpt.com
Definition at line 246 of file Director.cs.
|
inline |
Definition at line 104 of file Director.cs.
|
inline |
Listens for the next user input. This needs to be invoked at the start of every round, in order to let the director prepare for user input. Before invoking, you need to check that the status is Waiting.
| config | The director configuration. |
| speakers | The list of actors that are possibly speaking. The speaker order will be determined by choosing actors from this list. |
| topics | Possible discussion topics to be triggered by the user input. |
| cancellationToken | Cancellation token used to cancel any async actions when the program shuts down. |
Definition at line 112 of file Director.cs.
|
inlineprivate |
Callback function to receive server events from OpenAI.
| event | The event received from OpenAI. |
Definition at line 256 of file Director.cs.
|
inlineprivate |
Definition at line 423 of file Director.cs.
|
inlineprivate |
Definition at line 415 of file Director.cs.
|
inlineprivate |
Definition at line 172 of file Director.cs.
|
inlineprivate |
Definition at line 355 of file Director.cs.
|
inline |
Submit the user text input. Used as an alternative to speaking into the microphone, usually for development & debugging purposes.
| message | The user text input. |
| cancellationToken | Cancellation token used to cancel any async actions when the program shuts down. |
Definition at line 145 of file Director.cs.
Definition at line 357 of file Director.cs.
|
private |
Definition at line 55 of file Director.cs.
|
private |
Definition at line 54 of file Director.cs.
|
private |
Definition at line 63 of file Director.cs.
|
private |
Definition at line 58 of file Director.cs.
|
private |
Definition at line 57 of file Director.cs.
|
private |
Definition at line 56 of file Director.cs.
|
private |
Definition at line 62 of file Director.cs.
|
private |
Definition at line 59 of file Director.cs.
|
getset |
Definition at line 49 of file Director.cs.
|
getprivate set |
Definition at line 51 of file Director.cs.
|
getset |
Definition at line 50 of file Director.cs.