-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathMultipleCharacters.cs
More file actions
75 lines (63 loc) · 1.87 KB
/
MultipleCharacters.cs
File metadata and controls
75 lines (63 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using UnityEngine;
using UnityEngine.UI;
using LLMUnity;
namespace LLMUnitySamples
{
public class MultipleAgents : MonoBehaviour
{
[Header("Shared UI")]
public InputField playerText;
public Dropdown agentDropdown;
[Header("AI 1")]
public LLMAgent llmAgent1;
public Text AIText1;
[Header("AI 2")]
public LLMAgent llmAgent2;
public Text AIText2;
bool onValidateWarning = true;
void Start()
{
playerText.onSubmit.AddListener(OnInputFieldSubmit);
playerText.Select();
}
void OnInputFieldSubmit(string message)
{
playerText.interactable = false;
var agent = agentDropdown.value == 0 ? llmAgent1 : llmAgent2;
var aiText = agentDropdown.value == 0 ? AIText1 : AIText2;
aiText.text = "...";
_ = agent.Chat(message, (reply) => aiText.text = reply, AIReplyComplete);
}
void AIReplyComplete()
{
playerText.interactable = true;
playerText.text = "";
playerText.Select();
}
public void CancelRequests()
{
llmAgent1.CancelRequests();
llmAgent2.CancelRequests();
AIReplyComplete();
}
public void ExitGame()
{
Debug.Log("Exit button clicked");
Application.Quit();
}
void OnValidate()
{
if (onValidateWarning &&
llmAgent1 != null &&
!llmAgent1.remote &&
llmAgent1.llm != null &&
llmAgent1.llm.model == "")
{
Debug.LogWarning(
$"Please select a model in the {llmAgent1.llm.gameObject.name} GameObject!"
);
onValidateWarning = false;
}
}
}
}