@braintrust/langchain-js
v0.2.5
Published
SDK for integrating Braintrust with LangChain.js
Readme
@braintrust/langchain-js
[!WARNING] This package and all of its exports are deprecated and will stop being published after the next release. Use the LangChain integration in
braintrustinstead.
Installation
npm install braintrust
# or
yarn add braintrust
# or
pnpm add braintrustAutomatic instrumentation
For application-wide instrumentation, use the Braintrust runtime hook:
node --import braintrust/hook.mjs app.jsBraintrust also supports Vite, Webpack, esbuild, and Rollup. See the Braintrust SDK documentation for bundler setup.
Manual instrumentation
For scoped instrumentation, pass BraintrustLangChainCallbackHandler from
braintrust through LangChain's callbacks option:
import { ChatOpenAI } from "@langchain/openai";
import { BraintrustLangChainCallbackHandler } from "braintrust";
const handler = new BraintrustLangChainCallbackHandler();
const model = new ChatOpenAI({
callbacks: [handler],
});
const response = await model.invoke("Tell me a joke about bears", {
callbacks: [handler],
});setGlobalHandler does not have a direct replacement in braintrust. Use
automatic instrumentation for application-wide coverage, or pass the handler
explicitly for scoped instrumentation.
Documentation
- Braintrust docs: https://www.braintrust.dev/docs
- LangChain callback docs: https://js.langchain.com/docs/how_to/#callbacks
