Created
June 13, 2025 15:41
-
-
Save theo-m/361031f6925a79e0963118c3812c057f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { randomUUID } from "crypto"; | |
import { createGoogleGenerativeAI } from "@ai-sdk/google"; | |
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node"; | |
import { NodeSDK } from "@opentelemetry/sdk-node"; | |
import { generateObject } from "ai"; | |
import { Langfuse } from "langfuse"; | |
import { LangfuseExporter } from "langfuse-vercel"; | |
const prompt = `...`; | |
const langfuse = new Langfuse({ | |
secretKey: process.env.LANGFUSE_SECRET_KEY, | |
publicKey: process.env.LANGFUSE_PUBLIC_KEY, | |
baseUrl: "https://cloud.langfuse.com", | |
}); | |
const lfTrace = langfuse.trace({ | |
id: randomUUID(), | |
name: "my new trace", | |
}); | |
const lfExporter = new LangfuseExporter({ | |
secretKey: process.env.LANGFUSE_SECRET_KEY, | |
publicKey: process.env.LANGFUSE_PUBLIC_KEY, | |
baseUrl: "https://cloud.langfuse.com", | |
}); | |
const sdk = new NodeSDK({ | |
traceExporter: lfExporter, | |
instrumentations: [getNodeAutoInstrumentations()], | |
}); | |
sdk.start(); | |
// https://langfuse.com/docs/integrations/vercel-ai-sdk | |
async function main() { | |
console.log(lfTrace.getTraceUrl()); | |
const google = createGoogleGenerativeAI({ apiKey: process.env.GEMINI_API_KEY }); | |
const output = await generateObject({ | |
model: google("gemini-2.5-pro-preview-06-05"), | |
schema: mySchema, | |
messages: [ | |
{ role: "system", content: prompt }, | |
{ role: "user", content: [{ type: "file", mimeType: "application/pdf", data: uri }] }, | |
], | |
experimental_telemetry: { | |
isEnabled: true, | |
functionId: "my-awesome-function", | |
metadata: { | |
something: "custom", | |
someOtherThing: "other-value", | |
langfuseTraceId: lfTrace.traceId, | |
langfuseUpdateParent: false, // Do not update the parent trace with execution results | |
}, | |
}, | |
}); | |
// const output = await ai.parseFile(content, automatedAuditInsertionSchema, prompt); | |
console.log(output); | |
// await lfExporter.forceFlush(); | |
// await lfExporter.shutdown(); | |
await sdk.shutdown(); | |
await langfuse.flushAsync(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment