Compare commits

..

2 Commits

Author SHA1 Message Date
github-actions[bot] d883fe7351 Release @llamaindex/google@0.3.7 (#1994)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-05-31 14:04:14 +07:00
Parham Saidi 2bc6914784 fix: ignore empty parts for gemini which confuses agent (#1993) 2025-05-30 22:47:21 +07:00
3 changed files with 39 additions and 21 deletions
+6
View File
@@ -1,5 +1,11 @@
# @llamaindex/google
## 0.3.7
### Patch Changes
- 2bc6914: fix: ignore empty parts for gemini which confuses agent
## 0.3.6
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@llamaindex/google",
"description": "Google Adapter for LlamaIndex",
"version": "0.3.6",
"version": "0.3.7",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
+32 -20
View File
@@ -25,6 +25,7 @@ import { streamConverter } from "@llamaindex/core/utils";
import { wrapLLMEvent } from "@llamaindex/core/decorator";
import type { JSONObject } from "@llamaindex/core/global";
import { randomUUID } from "@llamaindex/env";
import { DEFAULT_GEMINI_PARAMS, SUPPORT_TOOL_CALL_MODELS } from "../base";
import type { GEMINI_MODEL } from "../types";
import {
@@ -117,7 +118,7 @@ export class GoogleStudio extends ToolCallLLM<GoogleAdditionalChatOptions> {
getToolCallsFromResponse(response: GenerateContentResponse): ToolCall[] {
if (!response.functionCalls) return [];
return response.functionCalls.map((call) => ({
id: call.id ?? "",
id: call.id ?? randomUUID(),
name: call.name ?? "",
input: call.args as JSONObject,
}));
@@ -170,6 +171,35 @@ export class GoogleStudio extends ToolCallLLM<GoogleAdditionalChatOptions> {
};
}
async *reduceStream(
stream: AsyncGenerator<GenerateContentResponse>,
): AsyncIterable<ChatResponseChunk> {
for await (const response of stream) {
if (response.functionCalls?.length) {
const toolCalls = this.getToolCallsFromResponse(response) as ToolCall[];
yield {
delta: "",
raw: response,
options: { toolCall: toolCalls },
} as ChatResponseChunk;
}
const text = response.candidates
?.flatMap((candidate) => candidate.content?.parts)
.map((part) => part?.text ?? "")
.filter((text) => text)
.join("");
if (!text) continue;
yield {
delta: text,
raw: response,
options: {
inlineData: getGoogleStudioInlineData(response),
},
} as ChatResponseChunk;
}
}
protected async *streamChat(
params: GoogleChatParamsStreaming,
): GoogleChatStreamResponse {
@@ -190,25 +220,7 @@ export class GoogleStudio extends ToolCallLLM<GoogleAdditionalChatOptions> {
contents: mapChatMessagesToGoogleMessages(params.messages),
config,
});
yield* streamConverter(response, (response) => {
if (response.functionCalls?.length) {
return {
delta: "",
raw: response,
options: {
toolCall: this.getToolCallsFromResponse(response),
},
};
}
return {
delta: response.text ?? "",
raw: response,
options: {
inlineData: getGoogleStudioInlineData(response),
},
};
});
yield* this.reduceStream(response);
}
chat(params: GoogleChatParamsStreaming): Promise<GoogleChatStreamResponse>;