Lazarus Pascal Requires Chilkat v11.2.0+
Lazarus Pascal
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.StringBuilder,
Chilkat.Ai,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ai: TAi;
askParams: TJsonObject;
sbResponse: TStringBuilder;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ai := TAi.Create;
ai.VerboseLogging := True;
ai.Provider := 'google';
ai.ApiKey := 'MY_API_KEY';
ai.Model := 'gemini-3.6-flash';
// Note: Not all models support all params.
// Set Ask params.
askParams := TJsonObject.Create;
askParams.UpdateNumber('temperature','1.2');
askParams.UpdateString('effort','low');
askParams.UpdateInt('max_output_tokens',1024);
askParams.EmitCompact := False;
WriteLn(askParams.Emit());
ai.SetAskParams(askParams);
// Add a text input.
ai.InputAddText('Say Hello.');
// Ask the AI for text output.
success := ai.Ask('text');
if (success = False) then
begin
WriteLn(ai.LastErrorText);
Exit;
end;
// Get the text response.
sbResponse := TStringBuilder.Create;
ai.GetOutputTextSb(sbResponse);
WriteLn(sbResponse.GetAsString());
// Sample output:
// Hello! How can I assist you today?
// -------------------------------------------------------------
// The response is in markdown format.
// Also see Markdown to HTML Conversion Examples.
// -------------------------------------------------------------
ai.Free;
askParams.Free;
sbResponse.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.