|
| 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. |
0 commit comments