Skip to content

add vercel ai sdk telemetry #21

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dashboard/ai-analytics/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const compat = new FlatCompat({

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
{
rules: {
"@typescript-eslint/no-unused-vars": ["error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}]
}
}
];

export default eslintConfig;
42 changes: 42 additions & 0 deletions dashboard/ai-analytics/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dashboard/ai-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@ai-sdk/openai": "^1.2.5",
"@auth0/nextjs-auth0": "^4.1.0",
"@clerk/nextjs": "^6.12.5",
"@opentelemetry/resources": "^2.0.0",
"@opentelemetry/semantic-conventions": "^1.30.0",
"@radix-ui/react-label": "^2.1.2",
"@radix-ui/react-popover": "^1.1.6",
"@radix-ui/react-select": "^2.1.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createOpenAI } from '@ai-sdk/openai';
import { generateObject } from 'ai';
import { z } from 'zod';
import { NextResponse } from 'next/server';
import { getTracerProvider } from '@/lib/telemetry';

// Define the schema for cost parameters
const costParametersSchema = z.object({
Expand Down Expand Up @@ -186,12 +187,22 @@ export async function POST(req: Request) {
`;

const openai = createOpenAI({ apiKey: apiKey })

const tracerProvider = getTracerProvider();

const result = await generateObject({
model: openai('gpt-3.5-turbo'),
schema: costParametersSchema,
prompt: query,
systemPrompt: systemPromptText,
experimental_telemetry: {
isEnabled: true,
functionId: 'extract-cost-parameters',
tracer: tracerProvider.getTracer('ai'),
metadata: {
endpoint: '/api/extract-cost-parameters',
userQuery: query
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);

Expand Down
14 changes: 14 additions & 0 deletions dashboard/ai-analytics/src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createOpenAI } from '@ai-sdk/openai';
import { generateObject } from 'ai';
import { z } from 'zod';
import { getTracerProvider } from '@/lib/telemetry';

const DIMENSIONS = {
model: ['gpt-4', 'gpt-3.5-turbo', 'claude-2'],
Expand Down Expand Up @@ -40,11 +41,24 @@ export async function POST(req: Request) {
Return only valid values from the provided dimensions.`;

const openai = createOpenAI({ apiKey: apiKey })

// Create a Tinybird tracer provider
const tracerProvider = getTracerProvider();

const result = await generateObject({
model: openai('gpt-3.5-turbo'),
schema: filterSchema,
prompt,
systemPrompt: systemPromptText,
experimental_telemetry: {
isEnabled: true,
functionId: 'search',
tracer: tracerProvider.getTracer('ai'),
metadata: {
endpoint: '/api/search',
userQuery: prompt
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);

Expand Down
Loading