A React-based chat application that simulates Braintrust support, with full instrumentation to log all interactions to Braintrust for observability and evaluation.
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env and add your API keys
# Start the development server
npm startVisit http://localhost:3000 to start chatting!
- π€ AI-Powered Support: Chat interface powered by OpenAI GPT-4, configured to act as Braintrust support
- π Braintrust Integration: All responses are automatically logged to Braintrust using their OpenAI SDK wrapper
- π§ͺ Test Sessions: Run predefined test chat sessions to evaluate and log interactions
- π¨ Modern UI: Beautiful, responsive chat interface with smooth animations
- π Full Tracing: Complete observability of all API calls and responses
- π MCP Server Support: Configured to work with Braintrust's MCP server for enhanced integration
- Node.js (v16 or higher)
- npm or yarn
- OpenAI API key
- Braintrust API key
npm installxCreate a.env` file in the root directory:
cp .env.example .envEdit .env and add your API keys:
REACT_APP_OPENAI_API_KEY=sk-your-openai-api-key-here
REACT_APP_BRAINTRUST_API_KEY=your-braintrust-api-key-here
REACT_APP_BRAINTRUST_PROJECT=braintrust-support-chatImportant: The .env file is gitignored for security. Never commit your API keys!
- Visit OpenAI Platform
- Sign up or log in to your account
- Navigate to API Keys in your account settings
- Click Create new secret key
- Copy the key (it starts with
sk-) and add it to your.envfile
Note: You'll need a paid OpenAI account with access to GPT-4. Free tier accounts may not work.
- Visit Braintrust
- Sign up or log in to your account
- Navigate to Settings β API Keys
- Click Create API Key
- Copy the key and add it to your
.envfile
Note: If you don't have a Braintrust account, you can sign up for free at braintrust.dev
npm startThe app will automatically open in your browser at http://localhost:3000. If it doesn't, navigate to that URL manually.
- Type your message in the input field at the bottom
- Press Enter or click the Send button
- Wait for the AI response (you'll see a typing indicator)
- Continue the conversation naturally
All messages are automatically logged to Braintrust in real-time!
The app includes three predefined test sessions in the right panel:
-
Basic Questions - General questions about Braintrust
- "What is Braintrust?"
- "How do I get started with Braintrust?"
- "What are the main features?"
-
Technical Questions - Technical questions about logging and features
- "How do I log traces in Braintrust?"
- "What is the difference between experiments and datasets?"
- "How do I use the OpenAI SDK wrapper?"
-
Integration Questions - Questions about integrating Braintrust
- "How do I integrate Braintrust with my React app?"
- "What is the MCP server?"
- "How do I set up authentication?"
To run a test session:
- Click "Run Test Session" on any test card
- Watch as the session executes automatically
- View the results in the test results panel
- All interactions are logged to Braintrust for analysis
Click the "Clear Chat" button to start a new conversation.
The app uses Braintrust's wrapOpenAI function to automatically instrument all OpenAI API calls:
import { wrapOpenAI } from 'braintrust';
import OpenAI from 'openai';
const openai = wrapOpenAI(
new OpenAI({
apiKey: process.env.REACT_APP_OPENAI_API_KEY,
}),
{
project: 'braintrust-support-chat',
}
);This wrapper automatically:
- Logs all API requests and responses
- Tracks token usage
- Records metadata and timing information
- Creates traces for debugging and evaluation
This app is designed to work with Braintrust's MCP (Model Context Protocol) server. The MCP server provides:
- Access to Braintrust experiments and datasets
- Real-time logging and monitoring
- Integration with development tools
For more information about Braintrust's MCP server, see the Braintrust MCP Documentation.
eval_test/
βββ public/
β βββ index.html # HTML template
βββ src/
β βββ components/
β β βββ ChatApp.js # Main chat component with UI
β β βββ ChatApp.css # Chat component styles
β βββ services/
β β βββ braintrustService.js # Braintrust integration & OpenAI wrapper
β βββ App.js # Root React component
β βββ App.css # App-level styles
β βββ index.js # React entry point
β βββ index.css # Global CSS styles
βββ .cursor/
β βββ mcp.json # MCP server configuration reference
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ package.json # Dependencies and npm scripts
βββ README.md # This file
src/components/ChatApp.js: Main chat interface component with test session functionalitysrc/services/braintrustService.js: Core service that wraps OpenAI SDK with Braintrust logging.cursor/mcp.json: MCP server configuration for Braintrust integration
All chat interactions are automatically logged to your Braintrust project. Here's how to view them:
-
Open Braintrust Dashboard
- Go to https://www.braintrust.dev/
- Log in to your account
-
Navigate to Your Project
- Select the project:
braintrust-support-chat(or your custom project name) - You'll see all logged interactions
- Select the project:
-
Explore the Data
- Logs Tab: See all chat interactions with timestamps
- Traces Tab: View detailed request/response traces with full context
- Metrics Tab: Analyze token usage, latency, and performance metrics
- Experiments Tab: Compare different test sessions
-
Filter and Search
- Filter by test session name
- Search for specific messages or responses
- View metadata like message count, model used, etc.
- In Braintrust dashboard, go to your project
- Use the filter/search to find logs with metadata containing
testSession - View the complete conversation flow for each test session
Edit src/components/ChatApp.js and add to the TEST_SESSIONS array:
const TEST_SESSIONS = [
{
name: 'Your Custom Test',
messages: [
'First test message',
'Second test message',
'Third test message',
],
},
// ... existing test sessions
];Edit src/services/braintrustService.js and modify the SYSTEM_PROMPT constant:
const SYSTEM_PROMPT = `Your custom system prompt here...`;This changes how the AI behaves and responds to users.
Edit src/services/braintrustService.js and change the model in the sendMessage method:
const response = await this.openai.chat.completions.create({
model: 'gpt-3.5-turbo', // Change from 'gpt-4' to any supported model
messages: fullMessages,
temperature: 0.7,
});Supported models: gpt-4, gpt-4-turbo, gpt-3.5-turbo, etc.
Change the temperature parameter to control response randomness:
temperature: 0.7, // Lower = more deterministic, Higher = more creative- Colors: Edit
src/components/ChatApp.cssto change the color scheme - Layout: Modify component structure in
src/components/ChatApp.js - Styling: Update CSS classes in
ChatApp.css
Problem: App shows errors about missing API keys
Solutions:
- β
Ensure your
.envfile is in the root directory (same level aspackage.json) - β
Restart the development server after changing
.env(stop withCtrl+Cand runnpm startagain) - β Verify API keys are correct - no extra spaces or quotes
- β
Check that keys start with correct prefixes:
- OpenAI:
sk-... - Braintrust: Usually a long alphanumeric string
- OpenAI:
Problem: Interactions aren't appearing in Braintrust dashboard
Solutions:
- β Check that your Braintrust API key is valid and active
- β
Verify the project name in
.envmatches an existing project in Braintrust - β Check the browser console (F12) for error messages
- β Ensure you have internet connectivity
- β Try creating a new project in Braintrust and updating the project name
Problem: Chat responses fail or show errors
Solutions:
- β Verify your OpenAI API key is valid
- β Check your OpenAI account has sufficient credits/billing set up
- β Ensure you have access to GPT-4 model (some accounts only have GPT-3.5)
- β Check OpenAI status page: status.openai.com
- β
Try switching to
gpt-3.5-turboif GPT-4 isn't available
Problem: npm start fails with errors
Solutions:
- β
Delete
node_modulesandpackage-lock.json, then runnpm installagain - β
Ensure you're using Node.js v16 or higher:
node --version - β
Clear npm cache:
npm cache clean --force
Problem: Port 3000 is already in use
Solutions:
- β Kill the process using port 3000
- β
Or set a different port:
PORT=3001 npm start
| Command | Description |
|---|---|
npm start |
Start development server on http://localhost:3000 |
npm build |
Create optimized production build |
npm test |
Run test suite (if configured) |
npm eject |
Eject from Create React App (irreversible) |
npm run buildThis creates an optimized production build in the build directory. The build is minified and ready for deployment.
Deploy to:
- Vercel:
vercel --prod - Netlify: Drag and drop the
buildfolder - GitHub Pages: Use
gh-pagespackage - Any static host: Upload the
buildfolder contents
- Hot Reload: Changes to code automatically refresh the browser
- Console Logging: Check browser console (F12) for debug information
- React DevTools: Install React Developer Tools browser extension
- Environment Variables: Remember to restart the dev server after changing
.env
- Braintrust Documentation - Complete Braintrust platform docs
- Braintrust MCP Server - MCP server integration guide
- OpenAI API Documentation - OpenAI API reference
- React Documentation - React framework docs
- Braintrust GitHub - Braintrust SDK source code
- OpenAI Platform - OpenAI dashboard and API management
- Create React App Docs - CRA documentation
- Braintrust Support: support@braintrust.dev
- Braintrust Discord: Join their community Discord
- OpenAI Support: help.openai.com
This project is provided as-is for demonstration and educational purposes.
- Built with React
- Powered by OpenAI
- Instrumented with Braintrust
Made with β€οΈ for AI observability and evaluation