封装 Vercel AI SDK 模型,启用自动 LangSmith 追踪。封装模型后,您可以像往常一样将其与 Vercel AI SDK Core 方法一起使用。

import { anthropic } from "@ai-sdk/anthropic";
import { streamText } from "ai";
import { wrapAISDKModel } from "langsmith/wrappers/vercel";

const anthropicModel = anthropic("claude-3-haiku-20240307");

const modelWithTracing = wrapAISDKModel(anthropicModel);

const { textStream } = await streamText({
model: modelWithTracing,
prompt: "Write a vegetarian lasagna recipe for 4 people.",
});

for await (const chunk of textStream) {
console.log(chunk);
}