Skip to content

[OPIK-933] [Typescript SDK] Add integration for Vercel AI SDK #1253

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

Merged
merged 10 commits into from
Feb 11, 2025

Conversation

ferc
Copy link
Contributor

@ferc ferc commented Feb 11, 2025

Details

  • Created OpikExporter to create with the OpenTelemetry Node SDK the telemetry instrument for attaching to the Vercel AI SDK
  • Improve bundling system (opik and opik/vercel)

Documentation

  • Added more examples + improved README file

.env:

OPIK_API_KEY="your-api-key"
OPIK_HOST="https://www.comet.com/opik/api"
OPIK_PROJECT_NAME="your-project-name"
OPIK_WORKSPACE_NAME="your-workspace-name"
OPENAI_API_KEY="your-openai-key"

Install:

npm install opik ai @ai-sdk/openai @opentelemetry/sdk-node @opentelemetry/auto-instrumentations-node

Code snippet:

import { openai } from "@ai-sdk/openai";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { generateText } from "ai";
import { OpikExporter } from "opik/vercel";

const sdk = new NodeSDK({
  traceExporter: new OpikExporter(),
  instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();

const { text } = await generateText({
  model: openai("gpt-4o-mini"),
  prompt: "What is love? Describe it in 10 words or less.",
  experimental_telemetry: OpikExporter.getSettings({
    name: "ai-sdk-integration",
  }),
});

await sdk.shutdown();

@ferc ferc requested review from a team as code owners February 11, 2025 09:42
Copy link
Collaborator

@aadereiko aadereiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@ferc ferc merged commit a87918d into main Feb 11, 2025
3 checks passed
@ferc ferc deleted the fernando/OPIK-933-typescript-sdk-support-ai-sdk branch February 11, 2025 11:25
@ferc ferc mentioned this pull request Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants