Rust Requires Chilkat v11.2.0+
Rust
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let ai = chilkat::Ai::new();
ai.set_verbose_logging(true);
ai.set_provider("google");
ai.set_api_key("MY_API_KEY");
ai.set_model("gemini-3.6-flash");
// Note: Not all models support all params.
// Set Ask params.
let ask_params = chilkat::JsonObject::new();
let _ = ask_params.update_number("temperature", "1.2");
let _ = ask_params.update_string("effort", "low");
let _ = ask_params.update_int("max_output_tokens", 1024);
ask_params.set_emit_compact(false);
println!("{}", ask_params.emit().unwrap_or_default());
let _ = ai.set_ask_params(&ask_params);
// Add a text input.
let _ = ai.input_add_text("Say Hello.");
// Ask the AI for text output.
if ai.ask("text").is_err() {
println!("{}", ai.last_error_text());
return;
}
// Get the text response.
let sb_response = chilkat::StringBuilder::new();
let _ = ai.get_output_text_sb(&sb_response);
println!("{}", sb_response.get_as_string().unwrap_or_default());
// Sample output:
// Hello! How can I assist you today?
// -------------------------------------------------------------
// The response is in markdown format.
// Also see Markdown to HTML Conversion Examples.
// -------------------------------------------------------------