braintrust-langchain

0.3.0 · deprecated · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart demonstrates how to use Braintrust's LangChain integration with the main `braintrust` package. It initializes the Braintrust logger, enables automatic LangChain instrumentation, and then executes a simple LangChain example. All interactions will be automatically logged to your Braintrust project.

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.

view raw JSON →