feat(ai): Add proper thinking support for Gemini 2.5 models

- Added thinkingConfig with includeThoughts and thinkingBudget support
- Use part.thought boolean flag to detect thinking content per API docs
- Capture and preserve thought signatures for multi-turn function calling
- Added supportsThinking() check for Gemini 2.5 series models
- Updated example to demonstrate thinking configuration
- Handle SDK type limitations with proper type assertions
This commit is contained in:
Mario Zechner 2025-08-25 10:26:23 +02:00
parent a8ba19f0b4
commit 3e1422d3d7
2 changed files with 56 additions and 13 deletions

View file

@ -23,10 +23,15 @@ const tools: Tool[] = [
const options: GeminiLLMOptions = {
onText: (t, complete) => process.stdout.write(t + (complete ? "\n" : "")),
onThinking: (t, complete) => process.stdout.write(chalk.dim(t + (complete ? "\n" : ""))),
toolChoice: "auto"
toolChoice: "auto",
// Enable thinking for Gemini 2.5 models
thinking: {
enabled: true,
budgetTokens: -1 // Dynamic thinking
}
};
const ai = new GeminiLLM("gemini-2.0-flash-exp", process.env.GEMINI_API_KEY || "fake-api-key-for-testing");
const ai = new GeminiLLM("gemini-2.5-flash", process.env.GEMINI_API_KEY || "fake-api-key-for-testing");
const context: Context = {
systemPrompt: "You are a helpful assistant that can use tools to answer questions.",
messages: [