Sample code for 30+ languages & platforms
Dart 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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final ai = CkAi();

  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.
  final askParams = CkJsonObject();
  askParams.updateNumber('temperature', '1.2');
  askParams.updateString('effort', 'low');
  askParams.updateInt('max_output_tokens', 1024);

  askParams.emitCompact = false;
  print(askParams.emit());

  ai.setAskParams(askParams);

  // Add a text input.
  ai.inputAddText('Say Hello.');

  // Ask the AI for text output.
  try {
    ai.ask('text');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Get the text response.
  final sbResponse = CkStringBuilder();
  ai.getOutputTextSb(sbResponse);
  print(sbResponse.getAsString());

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

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