-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
107 lines (94 loc) · 3.34 KB
/
MainWindow.xaml.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System.Dynamic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SQLMultiAgent
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public const string DefaultQuestion = "What was my best selling product?";
private SQLMultiAgentRunner multiAgent;
public MainWindow()
{
InitializeComponent();
multiAgent = new SQLMultiAgentRunner();
this.DataContext = multiAgent;
multiAgent.AgentResponded += SQLMultiAgent_AgentResponded;
}
private async void AskButton_Click(object sender, RoutedEventArgs e)
{
await AskQuestion();
}
private void SQLMultiAgent_AgentResponded(object? sender, EventArgs e)
{
if (e is AgentRespondedEventArgs args)
{
Color color = Colors.Black;
if (args.AgentName.Contains("Query"))
{
color = Colors.DarkGray;
} else if (args.AgentName.Contains("Assistant"))
{
color = Colors.DarkOliveGreen;
}
UpdateResponseBox(args.AgentName, args.Response, color);
}
}
private void QuestionBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//AskButton_Click(sender, e);
}
}
public async Task AskQuestion()
{
//Clear out the response box
ClearResponseBox();
multiAgent.question = QueryBox.Text;
//Store the name of the selected item on AgentType into a variable
string selectedAgentType = ((ComboBoxItem)AgentType.SelectedItem).Name;
switch (selectedAgentType)
{
case "SingleAgent":
await multiAgent.AskSingletonAgent();
break;
case "SingleAgentWithFunctions":
await multiAgent.AskSingletonAgentWithFunctions();
break;
case "Multi_Agent":
await multiAgent.AskMultiAgent();
break;
default:
break;
}
}
public void ClearResponseBox()
{
//Clear out the response box
ResponseBox.Document.Blocks.Clear();
}
public void UpdateResponseBox(string sender, string response, Color color)
{
//Update mainWindow.ResponseBox to add the sender in bold, a colon, a space, and the response in normal text
Paragraph paragraph = new Paragraph();
Bold bold = new Bold(new Run(sender + ": "));
bold.Foreground = new SolidColorBrush(color);
paragraph.Inlines.Add(bold);
Run run = new Run(response);
paragraph.Inlines.Add(run);
ResponseBox.Document.Blocks.Add(paragraph);
Console.WriteLine(sender + ": " + response);
}
}
}