封装一个 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);
}
© . This site is unofficial and not affiliated with LangChain, Inc.
这些文档随着 LangChain v1.0 在 2025 年 10 月的发布而弃用,并且不再维护。 请访问 v1.0 文档