How to implement ground search? #6537
-
|
Hi 👋, I'm currently using const { toolCalls } = await generateText({
model: this.model,
messages,
temperature: 0,
seed: 420,
tools: functions,
});This works great for triggering tool calls, but I'm trying to figure out how to integrate the I see in their example they use: const response = await ai.models.generateContent({
model: "gemini-2.0-flash",
contents: [
"Who individually won the most bronze medals during the Paris Olympics in 2024?",
],
config: {
tools: [{ googleSearch: {} }],
},
});But it's not clear to me how to combine this with If anyone has managed to get grounded search working alongside tool calls, or knows the correct config/setup, I’d really appreciate any pointers! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai#search-grounding This is the example with streamText. import { convertToCoreMessages, streamText, UIMessage } from "ai";
import { google, GoogleGenerativeAIProviderOptions } from "@ai-sdk/google";
export async function POST(request: Request) {
const { messages }: { messages: UIMessage[] } = await request.json();
const result = streamText({
model: google("gemini-2.5-flash-preview-05-20", {
useSearchGrounding: true,
dynamicRetrievalConfig: {
mode: "MODE_DYNAMIC",
dynamicThreshold: 0.3,
},
}),
system: `You are a helpful assistant.
Additional information:
- Today's date is ${new Date().toISOString()}
`,
messages: convertToCoreMessages(messages),
providerOptions: {
google: {
thinkingConfig: {
thinkingBudget: 8000,
includeThoughts: true,
},
} satisfies GoogleGenerativeAIProviderOptions,
},
});
return result.toDataStreamResponse({
sendReasoning: true,
sendSources: true,
});
} |
Beta Was this translation helpful? Give feedback.
For me it is working