Java Requires Chilkat v11.2.0+
Chilkat2 Java
AI: Set Ask Params
See more AI Examples
Demonstrates how to set the followingAsk parameters: temperature, effort, and max_output_tokens.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.Ai;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Ai ai = new Ai();
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.
JsonObject askParams = new JsonObject();
askParams.updateNumber("temperature", "1.2");
askParams.updateString("effort", "low");
askParams.updateInt("max_output_tokens", 1024);
askParams.setEmitCompact(false);
System.out.println(askParams.emit());
ai.setAskParams(askParams);
// Add a text input.
ai.inputAddText("Say Hello.");
// Ask the AI for text output.
try {
ai.ask("text");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Get the text response.
StringBuilder sbResponse = new StringBuilder();
ai.getOutputTextSb(sbResponse);
System.out.println(sbResponse.getAsString());
// Sample output:
// Hello! How can I assist you today?
// -------------------------------------------------------------
// The response is in markdown format.
// Also see Markdown to HTML Conversion Examples.
// -------------------------------------------------------------
}
}