braintrust-langchain
This library provided LangChain integration for Braintrust, a platform for evaluating and managing LLMs. It is now deprecated as of version 0.3.0. The LangChain integration has been moved into the main `braintrust` package. Users should install and use `braintrust` instead, which is actively developed with frequent releases.
Warnings
- breaking This `braintrust-langchain` package is deprecated. Its functionality has been migrated to the main `braintrust` SDK.
- breaking LangChain integration imports have changed. Direct imports from `braintrust_langchain` are no longer valid.
- gotcha Braintrust requires an API key for authentication. If not provided, tracing and logging will not function.
Install
-
pip install braintrust -
pip uninstall braintrust-langchain
Imports
- auto_instrument
from braintrust import auto_instrument
- BraintrustCallbackHandler
from braintrust.langchain import BraintrustCallbackHandler
Quickstart
import os
from braintrust import init_logger, auto_instrument
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
# Ensure your Braintrust API key is set
os.environ['BRAINTRUST_API_KEY'] = os.environ.get('BRAINTRUST_API_KEY', 'YOUR_BRAINTRUST_API_KEY')
# Initialize the logger with your project name (required)
# and auto-instrument LangChain
init_logger(project="My LangChain Project")
auto_instrument()
prompt = ChatPromptTemplate.from_template("What is 1 + {number}?")
model = ChatOpenAI(model="gpt-3.5-turbo")
chain = prompt | model
response = chain.invoke({"number": "2"})
print(response.content)
# The LangChain interaction will be automatically traced and logged to Braintrust.