Zig Requires Chilkat v11.2.0+
Zig
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const ai = try chilkat.Ai.init();
defer ai.deinit();
ai.setVerboseLogging(true);
ai.setProvider("google");
ai.setApiKey("MY_API_KEY");
ai.setModel("gemini-3.6-flash");
// Note: Not all models support all params.
// Set Ask params.
const ask_params = try chilkat.JsonObject.init();
defer ask_params.deinit();
ask_params.updateNumber("temperature", "1.2") catch {};
ask_params.updateString("effort", "low") catch {};
ask_params.updateInt("max_output_tokens", 1024) catch {};
ask_params.setEmitCompact(false);
std.debug.print("{s}\n", .{try ask_params.emit(alloc)});
ai.setAskParams(ask_params) catch {};
// Add a text input.
ai.inputAddText("Say Hello.") catch {};
// Ask the AI for text output.
ai.ask("text") catch {
std.debug.print("{s}\n", .{try ai.getLastErrorText(alloc)});
return;
};
// Get the text response.
const sb_response = try chilkat.StringBuilder.init();
defer sb_response.deinit();
ai.getOutputTextSb(sb_response) catch {};
std.debug.print("{s}\n", .{try sb_response.getAsString(alloc)});
// Sample output:
// Hello! How can I assist you today?
// -------------------------------------------------------------
// The response is in markdown format.
// Also see Markdown to HTML Conversion Examples.
// -------------------------------------------------------------
}