Swift
Swift
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let ai = CkoAi()!
ai.verboseLogging = true
ai.provider = "google"
ai.apiKey = "MY_API_KEY"
ai.model = "gemini-3-flash-preview"
// Note: Not all models support all params.
// Set Ask params.
let askParams = CkoJsonObject()!
askParams.updateNumber(jsonPath: "temperature", numericStr: "1.2")
askParams.updateString(jsonPath: "effort", value: "low")
askParams.updateInt(jsonPath: "max_output_tokens", value: 1024)
askParams.emitCompact = false
print("\(askParams.emit()!)")
ai.setAskParams(json: askParams)
// Add a text input.
ai.inputAddText(text: "Say Hello.")
// Ask the AI for text output.
success = ai.ask(outputType: "text")
if success == false {
print("\(ai.lastErrorText!)")
return
}
// Get the text response.
let sbResponse = CkoStringBuilder()!
ai.getOutputTextSb(sb: 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.
// -------------------------------------------------------------
}