Integrating Google Search with Gemini
https://ai.google.dev/gemini-api/docs/grounding?hl=en&lang=javascript
https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/grounding-search-suggestions
code:
import { GoogleGenAI } from "@google/genai";
const googleSearch = ai.defineTool({
name: 'googleSearch',
description: 'Searches the web for information',
inputSchema: z.object({
query: z.string().describe('the query to search the web for'),
}),
outputSchema: z.string(),
},
async (input) => {
const google = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
const response = await google.models.generateContent({
model: 'gemini-2.0-flash',
contents: [input.query],
config: {
tools: [{ googleSearch: {} }],
},
});
console.log("Search tool was used: ", response.text);
console.log("Search tool Grounding Chunks: ", response.candidates?.[0]?.groundingMetadata?.groundingChunks);
if (response.text === undefined) return 'No response from google';
return response.text;
}
);# 📢 Genkit JS and Dev UI 1.27.0 have been released! 🚀 This update introduces REALTIME TELEMETRY! ⚡️ You can now watch traces stream live in the Dev UI as you run your flows. Other key improvements: ✨ OpenAI API Plugin: - Pass API keys at runtime (instead of at config time) - Support for PDF and base64 file inputs 🛠️ Dev UI: - Stream telemetry in realtime for both JS and Go!!! - Collapsible code blocks for cleaner views Check out the full release notes here: https://github.com/firebase/genkit/releases/tag/v1.27.0
efficient-indigo · 4w ago
📢 **Genkit JS 1.26.0 is out!** 🚀 This release brings major improvements to security and reliability: 🛡️ **Model Armor Support** Protect your LLM applications with the new `modelArmor` middleware in `@genkit-ai/google-cloud`. It integrates Google Cloud Model Armor to sanitize user prompts and model responses, filtering out PII, jailbreaks, and more. [Learn more.](https://genkit.dev/docs/integrations/google-cloud/#model-armor) 🔄 **Durable Streaming (Experimental)** Build resilient flows that persist state across client disconnects! - **Reconnect support**: Clients can drop and rejoin the same stream. - **Persistence adapters**: Built-in support for Firestore and Realtime Database (via `@genkit-ai/firebase`). - **Framework integration**: Works with `expressHandler` and Next.js `appRoute`. We are looking for feedback on this experimental feature, so please try it out and let us know what you think! [Learn more](https://genkit.dev/docs/durable-streaming/). 🛠️ **Dev UI Improvements** - **Reasoning Tokens**: Now displaying token counts for reasoning models. - **Multipart Tool Support**: Better visualization for multipart tool responses. Check out the full changelog here: https://github.com/firebase/genkit/releases/tag/v1.26.0
efficient-indigo · 5w ago