Add Gemini 2.0 Flas Lite, Fix tools error with LLM Agent (#1712)

This commit is contained in:
Alexander Tigselema
2025-03-06 23:15:51 -05:00
committed by GitHub
parent 4bac71d6a2
commit 58b3ee52e0
3 changed files with 26 additions and 17 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/google": minor
---
google vertex ai don't support empty functionDeclarations array. You must pass an empty array to LLMAgent if you don't have tools so Gemini was no able to use it in agent mode. Also Gemini 2.0 flash lite was added to model list.
+20 -17
View File
@@ -56,6 +56,7 @@ export const GEMINI_MODEL_INFO_MAP: Record<GEMINI_MODEL, GeminiModelInfo> = {
[GEMINI_MODEL.GEMINI_2_0_FLASH_EXPERIMENTAL]: { contextWindow: 10 ** 6 },
[GEMINI_MODEL.GEMINI_2_0_FLASH]: { contextWindow: 10 ** 6 },
[GEMINI_MODEL.GEMINI_2_0_FLASH_LITE_PREVIEW]: { contextWindow: 10 ** 6 },
[GEMINI_MODEL.GEMINI_2_0_FLASH_LITE]: { contextWindow: 10 ** 6 },
[GEMINI_MODEL.GEMINI_2_0_FLASH_THINKING_EXP]: { contextWindow: 32768 },
[GEMINI_MODEL.GEMINI_2_0_PRO_EXPERIMENTAL]: { contextWindow: 2 * 10 ** 6 },
};
@@ -278,24 +279,26 @@ export class Gemini extends ToolCallLLM<GeminiAdditionalChatOptions> {
): GeminiChatStreamResponse {
const context = getChatContext(params);
const client = this.session.getGenerativeModel(this.metadata);
const chat = client.startChat(
params.tools
? {
history: context.history,
tools: [
{
functionDeclarations: params.tools.map(
mapBaseToolToGeminiFunctionDeclaration,
),
},
],
safetySettings: DEFAULT_SAFETY_SETTINGS,
}
: {
history: context.history,
safetySettings: DEFAULT_SAFETY_SETTINGS,
const tools = params.tools?.length
? [
{
functionDeclarations: params.tools.map(
mapBaseToolToGeminiFunctionDeclaration,
),
},
);
]
: [];
const startChatParams = params.tools
? {
history: context.history,
tools,
safetySettings: DEFAULT_SAFETY_SETTINGS,
}
: {
history: context.history,
safetySettings: DEFAULT_SAFETY_SETTINGS,
};
const chat = client.startChat(startChatParams);
const result = await chat.sendMessageStream(context.message);
yield* this.session.getChatStream(result);
}
+1
View File
@@ -66,6 +66,7 @@ export enum GEMINI_MODEL {
GEMINI_PRO_1_5_FLASH_LATEST = "gemini-1.5-flash-002",
GEMINI_2_0_FLASH_EXPERIMENTAL = "gemini-2.0-flash-exp",
GEMINI_2_0_FLASH = "gemini-2.0-flash-001",
GEMINI_2_0_FLASH_LITE = "gemini-2.0-flash-lite-001",
GEMINI_2_0_FLASH_LITE_PREVIEW = "gemini-2.0-flash-lite-preview-02-05",
GEMINI_2_0_FLASH_THINKING_EXP = "gemini-2.0-flash-thinking-exp-01-21",
GEMINI_2_0_PRO_EXPERIMENTAL = "gemini-2.0-pro-exp-02-05",