Sample code for 30+ languages & platforms
Perl Requires Chilkat v11.2.0+

AI: Set Ask Params

See more AI Examples

Demonstrates how to set the following Ask parameters: temperature, effort, and max_output_tokens.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

my $ai = Chilkat2::Ai->new;

$ai->VerboseLogging(1);

$ai->Provider('google');
$ai->ApiKey('MY_API_KEY');
$ai->Model('gemini-3.6-flash');

# Note: Not all models support all params.

# Set Ask params.
my $askParams = Chilkat2::JsonObject->new;
$askParams->UpdateNumber('temperature', '1.2');
$askParams->UpdateString('effort', 'low');
$askParams->UpdateInt('max_output_tokens', 1024);

$askParams->EmitCompact(0);
print $askParams->Emit(), "\n";

$ai->SetAskParams($askParams);

# Add a text input.
$ai->InputAddText('Say Hello.');

# Ask the AI for text output.
my $success = $ai->Ask('text');
if (!$success) {
    print $ai->LastErrorText, "\n";
    exit;
}

# Get the text response.
my $sbResponse = Chilkat2::StringBuilder->new;
$ai->GetOutputTextSb($sbResponse);
print $sbResponse->GetAsString(), "\n";

# Sample output:
# Hello! How can I assist you today?

# -------------------------------------------------------------
# The response is in markdown format.
# Also see Markdown to HTML Conversion Examples.
# -------------------------------------------------------------