Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

IA-GEMINI-DELPHI

Uso da IA Gemini no Delphi

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

IA Gemini Delphi

Uso da IA Gemini no Delphi

image

delphi
procedure TfrmPrincipal.btnPerguntaClick(Sender: TObject);
begin
 {$Region 'POST'}
  RESTClient1.BaseURL := lURLBase + lKey;

  Prompt      := TStringList.Create;
  JSONBody := TJSONObject.Create;
  try
    Prompt.Add(edtPergunta.Text);

    ContentsArray := TJSONArray.Create;
    PartsArray := TJSONArray.Create;
    PartsArray.AddElement(TJSONObject.Create.AddPair('text', Prompt.Text));
    ContentsArray.AddElement(TJSONObject.Create.AddPair('parts', PartsArray));
    JSONBody.AddPair('contents', ContentsArray);

    RESTRequest1.Params.ParameterByName('body4E6B89C7FD1E4198BD64C5BE65C5188E').Value := JSONBody.ToString;
  finally
    JSONBody.Free;
    Prompt.Free;
  end;

  RESTRequest1.Execute;
 {$EndRegion 'POST'}
end;
delphi
procedure TfrmPrincipal.btnPerguntaClick(Sender: TObject);
begin
 {$Region 'Retorno'}
  Retorno := RESTRequest1.Response.JSONValue as TJSONObject;

  Candidates := Retorno.GetValue<TJSONArray>('candidates');
  if Candidates.Count > 0 then
  begin
    Content := Candidates.Items[0].GetValue<TJSONObject>('content');
    Parts := Content.GetValue<TJSONArray>('parts');
    if Parts.Count > 0 then
    begin
      Text := Parts.Items[0].GetValue<string>('text');
      memResposta.Text := Text;
    end;
  end;
 {$EndRegion 'Retorno'}
end;