Lua Requires Chilkat v11.2.0+
Lua
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local ai = chilkat.Ai.new()
ai.verbose_logging = true
ai.provider = "google"
ai.api_key = "MY_API_KEY"
ai.model = "gemini-3.6-flash"
-- Note: Not all models support all params.
-- Set Ask params.
local askParams = chilkat.JsonObject.new()
askParams:update_number("temperature", "1.2")
askParams:update_string("effort", "low")
askParams:update_int("max_output_tokens", 1024)
askParams.emit_compact = false
print(askParams:emit())
ai:set_ask_params(askParams)
-- Add a text input.
ai:input_add_text("Say Hello.")
-- Ask the AI for text output.
local success = ai:ask("text")
if not success then
print(ai.last_error_text)
return
end
-- Get the text response.
local sbResponse = chilkat.StringBuilder.new()
ai:get_output_text_sb(sbResponse)
print(sbResponse:get_as_string())
-- Sample output:
-- Hello! How can I assist you today?
-- -------------------------------------------------------------
-- The response is in markdown format.
-- Also see Markdown to HTML Conversion Examples.
-- -------------------------------------------------------------