Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💄 style: Enable Grounding with Google Search for Gemini 2.0 #5778

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
29 changes: 28 additions & 1 deletion src/libs/agent-runtime/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,34 @@ export class LobeGoogleAI implements LobeRuntimeAI {
.generateContentStream({
contents,
systemInstruction: payload.system as string,
tools: this.buildGoogleTools(payload.tools),
tools: (() => {
const tools = this.buildGoogleTools(payload.tools);

if (tools) {
return tools; // 目前 Tools (例如 googleSearch) 无法与 FunctionCall 同时使用
}

if (
process.env.GEMINI_SEARCH_ENABLED !== '1' ||
!(
model.startsWith('gemini-2.0') &&
!model.includes('thinking') &&
!model.includes('lite')
)
) {
return tools;
}

const grounding = {
googleSearch: {},
} as GoogleFunctionCallTool;

if (!tools) {
return [grounding];
} else {
return [...tools, grounding];
}
})(),
});

const googleStream = convertIterableToStream(geminiStreamResult.stream);
Expand Down