EchoTrio
 
Loading...
Searching...
No Matches
GeneratedDiscussion.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
5namespace EchoTrio {
6 /// GeneratedDiscussions allow the designer to request the actors to generate N responses based on a prompt.
7 [CreateAssetMenu(fileName = "GeneratedDiscussion", menuName = "EchoTrio/GeneratedDiscussion")]
9 [Header("Generated Discussion Settings")]
10 [SerializeField, Range(1, 10)] private int minTurns = 1;
11 [SerializeField, Range(1, 10)] private int maxTurns = 3;
12 [SerializeField] private List<Persona> speakers = new List<Persona>();
13 [SerializeField,
14 TextArea(minLines: 4, maxLines: 16),
15 Tooltip("The prompt to give to the model to generate a discussion. If left blank, it will default to the trigger topic.")]
16 private string discussionPrompt = string.Empty;
17
18 public List<Persona> GenerateRandomSpeakerOrder() {
19 if (speakers.Count == 0) { return new List<Persona>(); }
20
21 int numTurns = UnityEngine.Random.Range(minTurns, maxTurns + 1);
22 if (speakers.Count == 1) { return Enumerable.Repeat(speakers[0], numTurns).ToList(); }
23
24 List<Persona> order = new List<Persona>();
25 int prevIndex = -1;
26 int currIndex = -1;
27 for (int i = 0; i < numTurns; ++i) {
28 currIndex = UnityEngine.Random.Range(0, speakers.Count);
29 // If the current speaker is same as the previous, get the next speaker in line instead.
30 currIndex = (currIndex == prevIndex) ? (currIndex + 1) % speakers.Count : currIndex;
31 prevIndex = currIndex;
32 order.Add(speakers[currIndex]);
33 }
34 return order;
35 }
36
37 public string GetDiscussionPrompt() {
38 return discussionPrompt == string.Empty ? $"Talk about the topic {triggerTopic} in your next response." : discussionPrompt;
39 }
40
41 private void OnValidate() {
42 maxTurns = Mathf.Max(maxTurns, minTurns);
43 }
44 }
45}
Discussions are a way for the designers to create a way for the actors to interact beyond the standar...
Definition: Discussion.cs:5
GeneratedDiscussions allow the designer to request the actors to generate N responses based on a prom...
List< Persona > GenerateRandomSpeakerOrder()