move to newer braintrust version

This commit is contained in:
dal 2025-08-12 16:06:00 -06:00
parent 1d0d312ff3
commit a7ced93c6e
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
5 changed files with 326 additions and 264 deletions

View File

@ -1,5 +1,6 @@
import { createAnthropic } from '@ai-sdk/anthropic';
import { wrapAISDKModel } from 'braintrust';
import { wrapLanguageModel } from 'ai';
import { BraintrustMiddleware } from 'braintrust';
export const anthropicModel = (modelId: string) => {
const anthropic = createAnthropic({
@ -42,6 +43,9 @@ export const anthropicModel = (modelId: string) => {
}) as typeof fetch,
});
// Wrap the model with Braintrust tracing and return it
return wrapAISDKModel(anthropic(modelId));
// Wrap the model with Braintrust middleware
return wrapLanguageModel({
model: anthropic(modelId),
middleware: BraintrustMiddleware({ debug: true }),
});
};

View File

@ -1,11 +1,15 @@
import { createOpenAI } from '@ai-sdk/openai';
import { wrapAISDKModel } from 'braintrust';
import { wrapLanguageModel } from 'ai';
import { BraintrustMiddleware } from 'braintrust';
export const openaiModel = (modelId: string) => {
const openai = createOpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// Wrap the model with Braintrust tracing and return it
return wrapAISDKModel(openai(modelId));
// Wrap the model with Braintrust middleware
return wrapLanguageModel({
model: openai(modelId),
middleware: BraintrustMiddleware({ debug: true }),
});
};

View File

@ -1,6 +1,7 @@
import { createVertexAnthropic } from '@ai-sdk/google-vertex/anthropic';
import type { LanguageModelV2 } from '@ai-sdk/provider';
import { wrapAISDKModel } from 'braintrust';
import { wrapLanguageModel } from 'ai';
import { BraintrustMiddleware } from 'braintrust';
export const vertexModel = (modelId: string): LanguageModelV2 => {
// Create a proxy that validates credentials on first use
@ -70,8 +71,11 @@ export const vertexModel = (modelId: string): LanguageModelV2 => {
}) as typeof fetch,
});
// Wrap the model with Braintrust tracing
actualModel = wrapAISDKModel(vertex(modelId));
// Wrap the model with Braintrust middleware
actualModel = wrapLanguageModel({
model: vertex(modelId),
middleware: BraintrustMiddleware({ debug: true }),
});
}
return actualModel;
};

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ catalog:
"@platejs/toc": "^49.0.0"
"@platejs/toggle": "^49.0.0"
axios: "^1.10.0"
"braintrust": "^0.0.209"
"braintrust": "^0.2.4"
dotenv: "^17.2.0"
drizzle-orm: "^0.44.2"
hono: "^4.8.0"