Skip to content

Commit 6524dd9

Browse files
committed
Merge branch 'develop'
2 parents b5e4122 + 2a4d445 commit 6524dd9

6 files changed

Lines changed: 1458 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
unit ToolSetCEP;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.JSON,
8+
System.Generics.Collections,
9+
TMS.MCP.CustomComponent,
10+
TMS.MCP.CloudAI,
11+
TMS.MCP.CloudBase;
12+
13+
type
14+
TToolSetCEP = class(TTMSMCPCloudAIToolSet)
15+
private
16+
procedure ToolSetCepExecute(Sender: TObject; Args: TJSONObject; var Result: string);
17+
function GetEndereco(const ACEP: string): string;
18+
protected
19+
procedure DefineTools; override;
20+
end;
21+
22+
implementation
23+
24+
procedure TToolSetCEP.DefineTools;
25+
var
26+
LTool: TTMSMCPCloudAITool;
27+
LParam: TTMSMCPCloudAIParameter;
28+
begin
29+
BeginUpdate;
30+
31+
LTool := Tools.Add;
32+
LTool.Name := 'RetornaEndereco';
33+
LTool.Description := 'Retorna o endereço do CEP informado';
34+
LTool.OnExecute := Self.ToolSetCepExecute;
35+
36+
LParam := LTool.Parameters.Add;
37+
LParam.Name := 'CEP';
38+
LParam.Description := 'CEP a ser utilizado para buscar endereço';
39+
40+
EndUpdate;
41+
end;
42+
43+
procedure TToolSetCEP.ToolSetCepExecute(Sender: TObject; Args: TJSONObject; var Result: string);
44+
var
45+
LCep: string;
46+
begin
47+
LCep := Args.GetValue<string>('CEP', '');
48+
Result := Self.GetEndereco(LCep);
49+
end;
50+
51+
function TToolSetCEP.GetEndereco(const ACEP: string): string;
52+
var
53+
LRequest: TTMSMCPCloudBase;
54+
LResult: string;
55+
begin
56+
LRequest := TTMSMCPCloudBase.Create;
57+
try
58+
LRequest.Request.Host := 'https://viacep.com.br/ws/';
59+
LRequest.Request.Path := Format('%s/json', [ACEP.Replace('-', '', [])]);
60+
61+
LRequest.ExecuteRequest(
62+
procedure(const ARequestResult:TTMSMCPCloudBaseRequestResult)
63+
begin
64+
LResult := ARequestResult.ResultString;
65+
end, nil, False);
66+
67+
Result := LResult;
68+
finally
69+
LRequest.Free;
70+
end;
71+
end;
72+
73+
end.
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
object ToolsetsPOOMainView: TToolsetsPOOMainView
2+
Left = 0
3+
Top = 0
4+
Caption = 'IA na pr'#225'tica: Toolsets Customizada POO'
5+
ClientHeight = 609
6+
ClientWidth = 1001
7+
Color = clBtnFace
8+
Font.Charset = DEFAULT_CHARSET
9+
Font.Color = clWindowText
10+
Font.Height = -12
11+
Font.Name = 'Segoe UI'
12+
Font.Style = []
13+
KeyPreview = True
14+
Position = poScreenCenter
15+
OnCreate = FormCreate
16+
TextHeight = 15
17+
object Splitter1: TSplitter
18+
Left = 0
19+
Top = 321
20+
Width = 1001
21+
Height = 5
22+
Cursor = crVSplit
23+
Align = alTop
24+
ExplicitLeft = -108
25+
ExplicitWidth = 931
26+
end
27+
object pnTop: TPanel
28+
Left = 0
29+
Top = 0
30+
Width = 1001
31+
Height = 65
32+
Align = alTop
33+
TabOrder = 0
34+
object Label1: TLabel
35+
Left = 18
36+
Top = 11
37+
Width = 50
38+
Height = 15
39+
Caption = 'IA service'
40+
end
41+
object cBoxIAService: TComboBox
42+
Left = 18
43+
Top = 28
44+
Width = 201
45+
Height = 23
46+
Style = csDropDownList
47+
TabOrder = 0
48+
end
49+
end
50+
object pnBoth: TPanel
51+
Left = 0
52+
Top = 65
53+
Width = 1001
54+
Height = 256
55+
Align = alTop
56+
TabOrder = 1
57+
object gBoxQuestion: TGroupBox
58+
Left = 1
59+
Top = 1
60+
Width = 999
61+
Height = 222
62+
Align = alClient
63+
Caption = ' Prompt / question '
64+
Padding.Left = 1
65+
Padding.Right = 1
66+
Padding.Bottom = 1
67+
TabOrder = 0
68+
object mmQuestion: TMemo
69+
Left = 3
70+
Top = 17
71+
Width = 993
72+
Height = 202
73+
Align = alClient
74+
BorderStyle = bsNone
75+
Lines.Strings = (
76+
'Qual o endere'#231'o do CEP 01310-100')
77+
TabOrder = 0
78+
ExplicitLeft = 2
79+
end
80+
end
81+
object Panel1: TPanel
82+
Left = 1
83+
Top = 223
84+
Width = 999
85+
Height = 32
86+
Align = alBottom
87+
Padding.Top = 2
88+
Padding.Right = 2
89+
Padding.Bottom = 2
90+
TabOrder = 1
91+
object btnExecute: TBitBtn
92+
Left = 1
93+
Top = 3
94+
Width = 102
95+
Height = 26
96+
Cursor = crHandPoint
97+
Align = alLeft
98+
Caption = 'Execute'
99+
TabOrder = 0
100+
OnClick = btnExecuteClick
101+
end
102+
object ProgressBar1: TProgressBar
103+
AlignWithMargins = True
104+
Left = 109
105+
Top = 7
106+
Width = 200
107+
Height = 18
108+
Margins.Left = 6
109+
Margins.Top = 4
110+
Margins.Right = 6
111+
Margins.Bottom = 4
112+
Align = alLeft
113+
Smooth = True
114+
Style = pbstMarquee
115+
SmoothReverse = True
116+
State = pbsPaused
117+
TabOrder = 1
118+
end
119+
end
120+
end
121+
object gBoxResponse: TGroupBox
122+
Left = 0
123+
Top = 326
124+
Width = 1001
125+
Height = 283
126+
Align = alClient
127+
Caption = ' Response '
128+
Padding.Left = 1
129+
Padding.Right = 1
130+
Padding.Bottom = 1
131+
TabOrder = 2
132+
object mmResponse: TMemo
133+
Left = 3
134+
Top = 17
135+
Width = 995
136+
Height = 263
137+
Align = alClient
138+
BorderStyle = bsNone
139+
ScrollBars = ssVertical
140+
TabOrder = 0
141+
end
142+
end
143+
end
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
unit ToolsetsPOO.Main.View;
2+
3+
interface
4+
5+
uses
6+
Winapi.Windows,
7+
Winapi.Messages,
8+
System.SysUtils,
9+
System.Variants,
10+
System.Classes,
11+
System.JSON,
12+
System.Generics.Collections,
13+
Vcl.Graphics,
14+
Vcl.Controls,
15+
Vcl.Forms,
16+
Vcl.Dialogs,
17+
Vcl.ComCtrls,
18+
Vcl.Buttons,
19+
Vcl.StdCtrls,
20+
Vcl.ExtCtrls,
21+
TMS.MCP.CustomComponent,
22+
TMS.MCP.Server,
23+
TMS.MCP.CloudAI,
24+
TMS.MCP.CloudBase,
25+
ToolSetCEP;
26+
27+
type
28+
TToolsetsPOOMainView = class(TForm)
29+
pnTop: TPanel;
30+
Label1: TLabel;
31+
cBoxIAService: TComboBox;
32+
pnBoth: TPanel;
33+
gBoxQuestion: TGroupBox;
34+
mmQuestion: TMemo;
35+
Panel1: TPanel;
36+
btnExecute: TBitBtn;
37+
ProgressBar1: TProgressBar;
38+
Splitter1: TSplitter;
39+
gBoxResponse: TGroupBox;
40+
mmResponse: TMemo;
41+
procedure FormCreate(Sender: TObject);
42+
procedure btnExecuteClick(Sender: TObject);
43+
private
44+
FCloudAI: TTMSMCPCloudAI;
45+
FToolSetCEP: TToolSetCEP;
46+
procedure OnCloudAIExecuted(Sender: TObject; AResponse: TTMSMCPCloudAIResponse;
47+
AHttpStatusCode: Integer; AHttpResult: string);
48+
public
49+
50+
end;
51+
52+
var
53+
ToolsetsPOOMainView: TToolsetsPOOMainView;
54+
55+
implementation
56+
57+
{$R *.dfm}
58+
59+
procedure TToolsetsPOOMainView.FormCreate(Sender: TObject);
60+
begin
61+
ReportMemoryLeaksOnShutdown := True;
62+
63+
FCloudAI := TTMSMCPCloudAI.Create(Self);
64+
FCloudAI.OnExecuted := Self.OnCloudAIExecuted;
65+
FCloudAI.APIKeys.LoadFromFile('..\..\Files\aikeys.cfg', 'PasswordTest');
66+
67+
FToolSetCEP := TToolSetCEP.Create(FCloudAI);
68+
FToolSetCEP.AI := FCloudAI;
69+
70+
cBoxIAService.Items.Assign(FCloudAI.GetServices(True));
71+
cBoxIAService.ItemIndex := 0;
72+
end;
73+
74+
procedure TToolsetsPOOMainView.OnCloudAIExecuted(Sender: TObject; AResponse: TTMSMCPCloudAIResponse;
75+
AHttpStatusCode: Integer; AHttpResult: string);
76+
begin
77+
ProgressBar1.State := pbsPaused;
78+
79+
if AHttpStatusCode <> 200 then
80+
begin
81+
mmResponse.Lines.Text := 'HTTP error code: ' + AHttpStatusCode.ToString + sLineBreak + AHttpResult;
82+
Exit;
83+
end;
84+
85+
mmResponse.Lines := AResponse.Content;
86+
end;
87+
88+
procedure TToolsetsPOOMainView.btnExecuteClick(Sender: TObject);
89+
begin
90+
mmResponse.Text := 'Processando...';
91+
92+
FCloudAI.Service := TTMSMCPCloudAIService(cBoxIAService.Items.Objects[cBoxIAService.ItemIndex]);
93+
FCloudAI.Context := mmQuestion.Lines;
94+
FCloudAI.Execute();
95+
96+
ProgressBar1.State := pbsNormal;
97+
end;
98+
99+
end.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
program ToolsetsPOO;
2+
3+
uses
4+
Vcl.Forms,
5+
ToolsetsPOO.Main.View in 'Src\ToolsetsPOO.Main.View.pas' {ToolsetsPOOMainView},
6+
ToolSetCEP in 'Src\ToolSetCEP.pas';
7+
8+
{$R *.res}
9+
10+
begin
11+
Application.Initialize;
12+
Application.MainFormOnTaskbar := True;
13+
Application.CreateForm(TToolsetsPOOMainView, ToolsetsPOOMainView);
14+
Application.Run;
15+
end.

0 commit comments

Comments
 (0)