-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFMX.WVPythia.Services.pas
More file actions
291 lines (228 loc) · 8.15 KB
/
FMX.WVPythia.Services.pas
File metadata and controls
291 lines (228 loc) · 8.15 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
unit FMX.WVPythia.Services;
interface
uses
Fmx.Dialogs,
System.SysUtils,
WVPythia.Adapter, WVPythia.Chat.ManagedFlow, WVPythia.ManagedItemService;
type
TFMXChatManagedItemDialogService = class(TCustomChatManagedItemDialogService)
protected
function DoSelectFunctionItem(
out AItem: TChatManagedItemRef): Boolean; override;
function DoSelectMCPItem(
out AItem: TChatManagedItemRef): Boolean; override;
function DoSelectSkillItem(
out AItem: TChatManagedItemRef): Boolean; override;
function DoSelectAgentItem(
out AItem: TChatManagedItemRef): Boolean; override;
function DoSelectCustomItem(
out AItem: TChatManagedItemRef): Boolean; override;
function DoActivateSystemSettings: Boolean; override;
function DoActivateModelSelection: Boolean; override;
function DoActivateInputState(
const AState: TInputPromptState;
const AOnFinalize: TManagedItemFinalizeProc): Boolean; override;
function DoActivateCopyItemEvent(
const APairId, AKind, AContent: string): Boolean; override;
function DoActivateCodeCopyItemEvent(
const ALang, AText: string): Boolean; override;
function DoActivateNewChatEvent: Boolean; override;
function DoActivateCardSettingsEvent: Boolean; override;
function DoActivateAudioInputEvent: Boolean; override;
end;
TToolContainer = record
class function SelectFunctionItem(out AItem: TChatManagedItemRef): Boolean; static;
class function SelectMCPItem(out AItem: TChatManagedItemRef): Boolean; static;
class function SelectSkillItem(out AItem: TChatManagedItemRef): Boolean; static;
class function SelectAgentItem(out AItem: TChatManagedItemRef): Boolean; static;
class function SelectCustomItem(out AItem: TChatManagedItemRef): Boolean; static;
class function ActivateSystemPrompt: Boolean; static;
class function ActivateModelSelection: Boolean; static;
class function ActivateInputState(
const AState: TInputPromptState;
const AOnFinalize: TManagedItemFinalizeProc): Boolean; static;
class function ActivateCopyItemEvent(
const APairId, AKind, AContent: string): Boolean; static;
class function ActivateCodeCopyItemEvent(
const ALang, AText: string): Boolean; static;
class function ActivateNewChatEvent: Boolean; static;
class function ActivateCardSettingsEvent: Boolean; static;
class function ActivateAudioInputEvent: Boolean; static;
end;
implementation
uses
Main; // This unit can be removed; here it simply allows the use of lPythia:TVCLBrowser; declared in TForm1
{ TFMXChatManagedItemDialogService }
function TFMXChatManagedItemDialogService.DoActivateCodeCopyItemEvent(
const ALang, AText: string): Boolean;
begin
Result := TToolContainer.ActivateCodeCopyItemEvent(ALang, AText);
end;
function TFMXChatManagedItemDialogService.DoActivateCopyItemEvent(const APairId,
AKind, AContent: string): Boolean;
begin
Result := TToolContainer.ActivateCopyItemEvent(APairId, AKind, AContent);
end;
function TFMXChatManagedItemDialogService.DoActivateInputState(
const AState: TInputPromptState;
const AOnFinalize: TManagedItemFinalizeProc): Boolean;
begin
Result := TToolContainer.ActivateInputState(AState, AOnFinalize);
end;
function TFMXChatManagedItemDialogService.DoActivateModelSelection: Boolean;
begin
Result := TToolContainer.ActivateModelSelection;
end;
function TFMXChatManagedItemDialogService.DoActivateSystemSettings: Boolean;
begin
Result := TToolContainer.ActivateSystemPrompt;
end;
function TFMXChatManagedItemDialogService.DoActivateAudioInputEvent: Boolean;
begin
Result := TToolContainer.ActivateAudioInputEvent;
end;
function TFMXChatManagedItemDialogService.DoActivateCardSettingsEvent: Boolean;
begin
Result := TToolContainer.ActivateCardSettingsEvent;
end;
function TFMXChatManagedItemDialogService.DoActivateNewChatEvent: Boolean;
begin
Result := TToolContainer.ActivateNewChatEvent;
end;
function TFMXChatManagedItemDialogService.DoSelectAgentItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := TToolContainer.SelectAgentItem(AItem);
end;
function TFMXChatManagedItemDialogService.DoSelectCustomItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := TToolContainer.SelectCustomItem(AItem);
end;
function TFMXChatManagedItemDialogService.DoSelectFunctionItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := TToolContainer.SelectFunctionItem(AItem);
end;
function TFMXChatManagedItemDialogService.DoSelectMCPItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := TToolContainer.SelectMCPItem(AItem);
end;
function TFMXChatManagedItemDialogService.DoSelectSkillItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := TToolContainer.SelectSkillItem(AItem);
end;
{ TToolContainer }
class function TToolContainer.ActivateCodeCopyItemEvent(const ALang,
AText: string): Boolean;
begin
Result := True;
// ShowMessage(
// 'Code copy intercepted' + sLineBreak +
// 'Lang = ' + ALang
// );
end;
class function TToolContainer.ActivateCopyItemEvent(const APairId, AKind,
AContent: string): Boolean;
begin
Result := True;
// ShowMessage(
// 'Copy intercepted' + sLineBreak +
// 'PairId = ' + APairId + sLineBreak +
// 'Kind = ' + AKind + sLineBreak +
// 'Content = ' + AContent
// );
end;
class function TToolContainer.ActivateInputState(
const AState: TInputPromptState;
const AOnFinalize: TManagedItemFinalizeProc): Boolean;
begin
(*
NOTE:
----
- In this method, we recommend asynchronous processing to avoid UI blockage.
- This asynchronous processing must include the `var Returns...` section
shown below at the end of the process.
*)
Result := True;
Form1.Pythia.Display('test...');
var Returns := TManagedItemLLMResult.Create;
try
Returns
.UsedModel('my_model')
.Response('test...')
.Error(False);
if Assigned(AOnFinalize) then
AOnFinalize(Returns);
finally
Returns.Free;
end;
end;
class function TToolContainer.ActivateModelSelection: Boolean;
begin
Result := True;
ShowMessage('Todo Model selection');
end;
class function TToolContainer.ActivateSystemPrompt: Boolean;
begin
Result := True;
ShowMessage('Todo custom settings');
end;
class function TToolContainer.ActivateAudioInputEvent: Boolean;
begin
Result := True;
ShowMessage('Todo audio input');
end;
class function TToolContainer.ActivateCardSettingsEvent: Boolean;
begin
Result := True;
ShowMessage('Todo settings card');
end;
class function TToolContainer.ActivateNewChatEvent: Boolean;
begin
Result := True;
// ShowMessage('New chat');
end;
class function TToolContainer.SelectAgentItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := True;
ShowMessage('Todo custom selection: Agent Item');
{--- Simulated return value here to maintain UI consistency }
AItem := TChatManagedItemRef.Create(Trunc(Random(20000) + 1).ToString, 'Agent name');
end;
class function TToolContainer.SelectCustomItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := True;
ShowMessage('Todo custom selection: custom Item');
{--- Simulated return value here to maintain UI consistency }
AItem := TChatManagedItemRef.Create(Trunc(Random(20000) + 1).ToString, 'custom service');
end;
class function TToolContainer.SelectFunctionItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := True;
ShowMessage('Todo custom selection: function Item');
{--- Simulated return value here to maintain UI consistency }
AItem := TChatManagedItemRef.Create(Trunc(Random(20000) + 1).ToString, 'Function name');
end;
class function TToolContainer.SelectMCPItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := True;
ShowMessage('Todo custom selection: MCP Item');
{--- Simulated return value here to maintain UI consistency }
AItem := TChatManagedItemRef.Create(Trunc(Random(20000) + 1).ToString, 'MCP-Title');
end;
class function TToolContainer.SelectSkillItem(
out AItem: TChatManagedItemRef): Boolean;
begin
Result := True;
ShowMessage('Todo custom selection: skill Item');
{--- Simulated return value here to maintain UI consistency }
AItem := TChatManagedItemRef.Create(Trunc(Random(20000) + 1).ToString, 'custom-skill');
end;
end.