import fallom from "@fallom/trace";import { GoogleGenerativeAI } from "@google/generative-ai";// Initialize Fallom once at app startupawait fallom.init({ apiKey: process.env.FALLOM_API_KEY });// Create a session for this conversation/requestconst session = fallom.session({ configKey: "my-app", sessionId: "session-123", customerId: "user-456",});// Create and wrap the modelconst genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);const model = session.wrapGoogleAI( genAI.getGenerativeModel({ model: "gemini-1.5-pro" }));// Use as normal - automatically traced!const result = await model.generateContent("Hello!");console.log(result.response.text());
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);const model = session.wrapGoogleAI( genAI.getGenerativeModel({ model: "gemini-1.5-pro", systemInstruction: "You are a helpful assistant.", }));const result = await model.generateContent("Tell me about TypeScript.");
const result = await model.generateContentStream("Write a poem about coding.");for await (const chunk of result.stream) { process.stdout.write(chunk.text());}