Skip to content

Commit 8607e41

Browse files
committed
feature/add-produto-funciton-calling
1 parent 25b9e89 commit 8607e41

5 files changed

Lines changed: 156 additions & 56 deletions

File tree

Samples/BD/dados.db

0 Bytes
Binary file not shown.

Samples/FunctionCalling/Src/Main.View.dfm

Lines changed: 65 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ object MainView: TMainView
4646
Height = 23
4747
Style = csDropDownList
4848
TabOrder = 0
49-
OnChange = cBoxIAServiceChange
5049
end
5150
object TMSFNCCloudAI1: TTMSFNCCloudAI
5251
Left = 480
@@ -67,30 +66,30 @@ object MainView: TMainView
6766
Settings.MistralModel = 'mistral-large-latest'
6867
Tools = <
6968
item
70-
Name = 'IdCliente'
71-
Description = 'Retorne os dados do cliente pelo ID informado'
69+
Name = 'GetEstoqueProduto'
70+
Description = 'Retorne o estoque do produto informado'
7271
Parameters = <
7372
item
7473
ArrayProperties = <>
75-
Name = 'IdCliente'
74+
Name = 'IdProduto'
7675
Type = ptNumber
77-
Description = 'Id do cliente'
76+
Description = 'Id do produto'
7877
Properties = <>
7978
end>
80-
OnExecute = TMSFNCCloudAI1Tools3Execute
79+
OnExecute = TMSFNCCloudAI1Tools0Execute
8180
end
8281
item
83-
Name = 'GetEstoqueProduto'
84-
Description = 'Retorne o estoque do produto informado'
82+
Name = 'IdCliente'
83+
Description = 'Retorne os dados do cliente pelo ID informado'
8584
Parameters = <
8685
item
8786
ArrayProperties = <>
88-
Name = 'IdProduto'
87+
Name = 'IdCliente'
8988
Type = ptNumber
90-
Description = 'Id do produto'
89+
Description = 'Id do cliente'
9190
Properties = <>
9291
end>
93-
OnExecute = TMSFNCCloudAI1Tools0Execute
92+
OnExecute = TMSFNCCloudAI1Tools3Execute
9493
end
9594
item
9695
Name = 'GetEndereco'
@@ -150,73 +149,101 @@ object MainView: TMainView
150149
Left = 3
151150
Top = 17
152151
Width = 734
153-
Height = 143
152+
Height = 127
154153
Align = alClient
155154
BorderStyle = bsNone
156155
Lines.Strings = (
157156
'Retorne os dados das vendas do periodo 01/06/2025 a 24/06/2025')
158157
TabOrder = 0
159158
ExplicitLeft = 2
160159
ExplicitTop = 11
160+
ExplicitHeight = 143
161161
end
162162
object gBoxDefaultsPrompts: TGroupBox
163163
Left = 3
164-
Top = 160
164+
Top = 144
165165
Width = 734
166-
Height = 59
166+
Height = 75
167167
Align = alBottom
168168
Caption = ' Defaults Prompts '
169169
TabOrder = 1
170170
object pnDefaultsPrompts01: TPanel
171171
Left = 2
172172
Top = 17
173173
Width = 730
174-
Height = 24
174+
Height = 27
175175
Align = alTop
176176
BevelOuter = bvNone
177+
Padding.Bottom = 3
177178
TabOrder = 0
178-
ExplicitLeft = 1
179-
ExplicitTop = 1
180-
ExplicitWidth = 732
181-
object Button1: TButton
182-
Left = 198
179+
ExplicitTop = 11
180+
object Button3: TButton
181+
Left = 182
183182
Top = 0
184-
Width = 99
183+
Width = 182
185184
Height = 24
186185
Align = alLeft
187-
Caption = 'Vendas per'#237'odo'
186+
Caption = 'Dados cliente'
188187
TabOrder = 0
189-
OnClick = Button1Click
188+
OnClick = Button3Click
189+
ExplicitLeft = -6
190+
ExplicitTop = -3
190191
end
191-
object Button2: TButton
192-
Left = 297
192+
object Button4: TButton
193+
Left = 364
193194
Top = 0
194195
Width = 182
195196
Height = 24
196197
Align = alLeft
197-
Caption = 'Vendas per'#237'odo (detalhando)'
198+
Caption = 'Email cliente'
198199
TabOrder = 1
199-
OnClick = Button2Click
200+
OnClick = Button4Click
201+
ExplicitLeft = 182
200202
end
201-
object Button3: TButton
203+
object Button5: TButton
202204
Left = 0
203205
Top = 0
204-
Width = 99
206+
Width = 182
205207
Height = 24
206208
Align = alLeft
207-
Caption = 'Dados cliente'
209+
Caption = 'Dados produto'
208210
TabOrder = 2
209-
OnClick = Button3Click
211+
OnClick = Button5Click
212+
ExplicitLeft = -6
213+
ExplicitTop = -3
210214
end
211-
object Button4: TButton
212-
Left = 99
215+
end
216+
object pnDefaultsPrompts02: TPanel
217+
Left = 2
218+
Top = 44
219+
Width = 730
220+
Height = 24
221+
Align = alTop
222+
BevelOuter = bvNone
223+
Padding.Bottom = 3
224+
TabOrder = 1
225+
ExplicitTop = 41
226+
object Button1: TButton
227+
Left = 0
213228
Top = 0
214-
Width = 99
215-
Height = 24
229+
Width = 182
230+
Height = 21
216231
Align = alLeft
217-
Caption = 'Email cliente'
218-
TabOrder = 3
219-
OnClick = Button4Click
232+
Caption = 'Vendas per'#237'odo'
233+
TabOrder = 0
234+
OnClick = Button1Click
235+
end
236+
object Button2: TButton
237+
Left = 182
238+
Top = 0
239+
Width = 182
240+
Height = 21
241+
Align = alLeft
242+
Caption = 'Vendas per'#237'odo (detalhando)'
243+
TabOrder = 1
244+
OnClick = Button2Click
245+
ExplicitLeft = 107
246+
ExplicitTop = 3
220247
end
221248
end
222249
end

Samples/FunctionCalling/Src/Main.View.pas

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ TMainView = class(TForm)
4040
TMSFNCCloudAI1: TTMSFNCCloudAI;
4141
gBoxDefaultsPrompts: TGroupBox;
4242
pnDefaultsPrompts01: TPanel;
43-
Button1: TButton;
44-
Button2: TButton;
4543
Button3: TButton;
4644
Button4: TButton;
45+
pnDefaultsPrompts02: TPanel;
46+
Button1: TButton;
47+
Button2: TButton;
48+
Button5: TButton;
4749
procedure FormCreate(Sender: TObject);
48-
procedure cBoxIAServiceChange(Sender: TObject);
4950
procedure btnExecuteClick(Sender: TObject);
5051
procedure TMSFNCCloudAI1Executed(Sender: TObject; AResponse: TTMSFNCCloudAIResponse; AHttpStatusCode: Integer;
5152
AHttpResult: string);
@@ -57,6 +58,7 @@ TMainView = class(TForm)
5758
procedure TMSFNCCloudAI1Tools3Execute(Sender: TObject; Args: TJSONObject; var Result: string);
5859
procedure Button3Click(Sender: TObject);
5960
procedure Button4Click(Sender: TObject);
61+
procedure Button5Click(Sender: TObject);
6062
private
6163
function GetEndereco(const ACEP: string): string;
6264
public
@@ -78,14 +80,12 @@ procedure TMainView.FormCreate(Sender: TObject);
7880
TMSFNCCloudAI1.Settings.WebSearch := True;
7981

8082
cBoxIAService.Items.Assign(TMSFNCCloudAI1.GetServices(True));
81-
cBoxIAService.ItemIndex := 2; //6
82-
cBoxIAServiceChange(cBoxIAService);
83+
cBoxIAService.ItemIndex := 0;
8384
end;
8485

85-
procedure TMainView.cBoxIAServiceChange(Sender: TObject);
86+
procedure TMainView.Button5Click(Sender: TObject);
8687
begin
87-
var i := Integer(cBoxIAService.Items.Objects[cBoxIAService.ItemIndex]);
88-
TMSFNCCloudAI1.Service := TTMSFNCCloudAIService(i);
88+
mmQuestion.Text := 'Retorne o estoque do produto informado id 10';
8989
end;
9090

9191
procedure TMainView.Button3Click(Sender: TObject);
@@ -107,12 +107,15 @@ procedure TMainView.Button1Click(Sender: TObject);
107107

108108
procedure TMainView.Button2Click(Sender: TObject);
109109
begin
110-
mmQuestion.Text := 'Retorne os dados das vendas do periodo 01/06/2025 a 24/06/2025' + sLineBreak +
110+
cBoxIAService.ItemIndex := 0;
111+
mmQuestion.Text := 'Retorne os dados das vendas do periodo 01/06/2025 a 25/06/2025' + sLineBreak +
111112
'Mostre as 5 primeiras vendas';
112113
end;
113114

114115
procedure TMainView.btnExecuteClick(Sender: TObject);
115116
begin
117+
TMSFNCCloudAI1.Service := TTMSFNCCloudAIService(cBoxIAService.Items.Objects[cBoxIAService.ItemIndex]);
118+
116119
TMSFNCCloudAI1.Context := mmQuestion.Lines;
117120
TMSFNCCloudAI1.Execute();
118121
ProgressBar1.State := pbsNormal;
@@ -131,6 +134,30 @@ procedure TMainView.TMSFNCCloudAI1Executed(Sender: TObject; AResponse: TTMSFNCCl
131134
mmResponse.Lines.Text := AResponse.Content.Text;
132135
end;
133136

137+
procedure TMainView.TMSFNCCloudAI1Tools0Execute(Sender: TObject; Args: TJSONObject; var Result: string);
138+
var
139+
LIdProduto: Integer;
140+
begin
141+
LIdProduto := Args.GetValue<Integer>('IdProduto', 0);
142+
if LIdProduto <= 0 then
143+
begin
144+
Result := 'Código do produto não pode ser recuperado';
145+
Exit;
146+
end;
147+
148+
DM.ProdutosGet(LIdProduto);
149+
if dm.TBProdutos.IsEmpty then
150+
begin
151+
Result := 'Nenhum produto foi encontrado com o código: ' + LIdProduto.ToString;
152+
Exit;
153+
end;
154+
155+
Result := DM.TBProdutosid.AsString + sLineBreak +
156+
'Nome: ' + DM.TBProdutosnome.AsString + sLineBreak +
157+
'Estoque: ' + DM.TBProdutosestoque.AsString + sLineBreak +
158+
'Preço: ' + DM.TBProdutospreco.AsString;
159+
end;
160+
134161
procedure TMainView.TMSFNCCloudAI1Tools3Execute(Sender: TObject; Args: TJSONObject; var Result: string);
135162
var
136163
LIdCLiente: Integer;
@@ -152,11 +179,6 @@ procedure TMainView.TMSFNCCloudAI1Tools3Execute(Sender: TObject; Args: TJSONObje
152179
Result := DM.TBClientesId.AsString + ' - ' + DM.TBClientesnome.AsString;
153180
end;
154181

155-
procedure TMainView.TMSFNCCloudAI1Tools0Execute(Sender: TObject; Args: TJSONObject; var Result: string);
156-
begin
157-
Result := FloatToStr(Args.GetValue<Integer>('IdProduto') * 10);
158-
end;
159-
160182
procedure TMainView.TMSFNCCloudAI1Tools1Execute(Sender: TObject; Args: TJSONObject; var Result: string);
161183
begin
162184
Result := Self.GetEndereco(Args.GetValue<string>('CEP'));

Samples/FunctionCalling/Src/uDM.dfm

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ object DM: TDM
2525
'from vendas'
2626
'left join clientes on clientes.id = vendas.id_cliente'
2727
'')
28-
Left = 128
29-
Top = 216
28+
Left = 120
29+
Top = 280
3030
object TBVendasId: TFDAutoIncField
3131
FieldName = 'Id'
3232
Origin = 'Id'
@@ -65,7 +65,7 @@ object DM: TDM
6565
'where id = :IdCliente '
6666
'limit 1')
6767
Left = 120
68-
Top = 152
68+
Top = 216
6969
ParamData = <
7070
item
7171
Name = 'IDCLIENTE'
@@ -86,4 +86,37 @@ object DM: TDM
8686
Size = 50
8787
end
8888
end
89+
object TBProdutos: TFDQuery
90+
Connection = FDConnection1
91+
SQL.Strings = (
92+
'select *'
93+
'from produtos')
94+
Left = 120
95+
Top = 152
96+
object TBProdutosid: TFDAutoIncField
97+
FieldName = 'id'
98+
Origin = 'id'
99+
ProviderFlags = [pfInWhere, pfInKey]
100+
ReadOnly = False
101+
end
102+
object TBProdutosnome: TWideStringField
103+
FieldName = 'nome'
104+
Origin = 'nome'
105+
Size = 40
106+
end
107+
object TBProdutosestoque: TFloatField
108+
FieldName = 'estoque'
109+
Origin = 'estoque'
110+
DisplayFormat = ',,0.00'
111+
end
112+
object TBProdutospreco: TFloatField
113+
FieldName = 'preco'
114+
Origin = 'preco'
115+
DisplayFormat = ',,0.00'
116+
end
117+
object TBProdutosregistro: TIntegerField
118+
FieldName = 'registro'
119+
Origin = 'registro'
120+
end
121+
end
89122
end

Samples/FunctionCalling/Src/uDM.pas

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ TDM = class(TDataModule)
3939
TBClientes: TFDQuery;
4040
TBClientesId: TFDAutoIncField;
4141
TBClientesnome: TWideStringField;
42+
TBProdutos: TFDQuery;
43+
TBProdutosid: TFDAutoIncField;
44+
TBProdutosnome: TWideStringField;
45+
TBProdutosestoque: TFloatField;
46+
TBProdutospreco: TFloatField;
47+
TBProdutosregistro: TIntegerField;
4248
procedure DataModuleCreate(Sender: TObject);
4349
private
50+
FSqlTBProdutos: string;
4451
FSqlTBVendas: string;
4552
public
53+
procedure ProdutosGet(const AId: Integer);
4654
procedure ClienteGet(const AId: Integer);
4755
procedure VendasListar(ADataIni, ADataFim: TDate);
4856
end;
@@ -58,13 +66,23 @@ implementation
5866

5967
procedure TDM.DataModuleCreate(Sender: TObject);
6068
begin
69+
FSqlTBProdutos := TBProdutos.SQL.Text;
6170
FSqlTBVendas := TBVendas.SQL.Text;
6271
end;
6372

73+
procedure TDM.ProdutosGet(const AId: Integer);
74+
begin
75+
TBProdutos.Close;
76+
TBProdutos.SQL.Text := FSqlTBProdutos;
77+
TBProdutos.SQL.Add('where id = :IdProduto');
78+
TBProdutos.ParamByName('IdProduto').AsInteger := AId;
79+
TBProdutos.Open;
80+
end;
81+
6482
procedure TDM.ClienteGet(const AId: Integer);
6583
begin
6684
TBClientes.Close;
67-
TBClientes.ParamByName('IdCLiente').AsInteger := AId;
85+
TBClientes.ParamByName('IdCliente').AsInteger := AId;
6886
TBClientes.Open;
6987
end;
7088

0 commit comments

Comments
 (0)