The simplest way to build AI agents - Built on Vercel AI SDK with PromptFlow tracking
Project description
ContextifyAI
Drop-in replacement for Vercel AI SDK with automatic tracking + editable prompts.
Change one line โ Get tracking. Change one more โ Get editable prompts.
๐ Live Demo: Dashboard | API
The Problem
You're using Vercel AI SDK and want to:
- Track your LLM calls (latency, costs, responses)
- Edit prompts without code changes
- Let non-technical team members improve prompts
The Solution
ContextifyAI is a drop-in replacement for ai-sdk-python with 3 stages:
Stage 1: Vercel AI SDK (Your Current Code)
from ai_sdk import generate_text, anthropic
model = anthropic("claude-3-5-sonnet-20241022", api_key=api_key)
result = generate_text(model=model, prompt="What is AI?")
โ No tracking | โ Hardcoded prompts
Stage 2: ContextifyAI Drop-in (1 Line Change)
from contextifyai import generate_text, anthropic # <-- ONLY CHANGE
model = anthropic("claude-3-5-sonnet-20241022", api_key=api_key)
result = generate_text(model=model, prompt="What is AI?")
โ Automatic tracking | โ Still hardcoded prompts
Stage 3: Editable Prompts (2 Line Changes Total)
from contextifyai import generate_text, anthropic # <-- Change 1
model = anthropic("claude-3-5-sonnet-20241022", api_key=api_key)
result = generate_text(model=model, prompt_template="ai_explanation") # <-- Change 2
โ Automatic tracking | โ Edit prompts from dashboard without code changes!
Installation
pip install contextifyai
Or install from GitHub:
pip install git+https://github.com/sanjevvishnu/contextifyAI.git
What You Get
| Feature | Vercel AI SDK | ContextifyAI |
|---|---|---|
| Works | โ | โ |
| Same API | โ | โ |
| Code changes | - | 1 line (import) |
| Tracking | โ | โ Automatic |
| Dashboard | โ | โ localhost:3001 |
| Latency | โ | โ Measured |
| Cost | โ | โ Calculated |
| Prompt versioning | โ | โ Built-in |
Migration Guide
Step 1: Install
pip install contextifyai
Step 2: Change Import
- from ai_sdk import generate_text, anthropic
+ from contextifyai import generate_text, anthropic
Step 3: Done!
That's it. Everything else stays exactly the same.
Example
from contextifyai import generate_text, anthropic
import os
# Setup (same as Vercel AI SDK)
api_key = os.getenv("ANTHROPIC_API_KEY")
model = anthropic("claude-3-5-sonnet-20241022", api_key=api_key)
# All your existing code works:
# Simple
result = generate_text(model=model, prompt="Hello")
# With temperature
result = generate_text(
model=model,
prompt="Write a poem",
temperature=0.9
)
# With system instruction
result = generate_text(
model=model,
system="You are a helpful teacher",
prompt="Explain AI"
)
# Every call is automatically tracked!
# View at: http://localhost:3001
Run the Demos
๐ Complete Production Demo (RECOMMENDED)
# Comprehensive demo explaining the entire flow
python examples/complete_demo.py
This demo:
- Makes 5 different LLM calls (customer support, code review, creative writing, data analysis, translation)
- Explains what happens in the backend server for each call
- Shows how the dashboard UI gets updated
- Verifies all calls were tracked successfully
- Includes detailed code comments explaining the entire architecture
Demo 1: Before vs After (Tracking)
# Before - no tracking
python examples/before_vercel_only.py
# After - automatic tracking (1 line changed)
python examples/after_contextifyai.py
# Open dashboard to see tracked calls
open https://promptflow-ez9ndjop6-sanjevvishnus-projects.vercel.app
Demo 2: Editable Prompts
# Run with templates
python examples/with_templates.py
# Edit template in dashboard
# Click "Prompt Templates" tab โ Edit template
# Run again - see updated prompt (NO CODE CHANGES!)
python examples/with_templates.py
Features
๐ฏ Drop-in Replacement (Stage 2)
- Same API as
ai-sdk-python - 1 line change (import)
- Automatic tracking
- Dashboard at http://localhost:3001
๐ Editable Prompts (Stage 3)
- Edit prompts from dashboard
- No code deploys needed
- Non-technical users can improve prompts
- A/B testing without code changes
- Template versioning
๐ Analytics Dashboard
- View all LLM calls
- Track latency, tokens, costs
- Search and filter calls
- Edit prompt templates
Configuration
Environment Variables (Recommended)
# Required
ANTHROPIC_API_KEY=sk-ant-...
# or
OPENAI_API_KEY=sk-...
# Optional (use production backend)
PROMPTFLOW_URL=https://backend-black-six-59.vercel.app
PROMPTFLOW_API_KEY=pk_test_123456
# Or run locally
# PROMPTFLOW_URL=http://localhost:8000
# PROMPTFLOW_API_KEY=pk_test_123456
Programmatic (Optional)
from contextifyai import configure
# Use production backend
configure(
promptflow_url="https://backend-black-six-59.vercel.app",
promptflow_api_key="pk_test_123456"
)
# Or local backend
# configure(
# promptflow_url="http://localhost:8000",
# promptflow_api_key="pk_test_123456"
# )
Architecture
Your Code
โ
ContextifyAI (thin wrapper)
โ
Vercel AI SDK (ai-sdk-python)
โ
LLM Provider (OpenAI, Anthropic)
Tracking (parallel) โ PromptFlow Backend โ Dashboard
FAQ
Q: Will this break my existing code?
A: No. ContextifyAI wraps Vercel AI SDK, so if your code works now, it will keep working.
Q: What if PromptFlow backend is down?
A: Tracking fails silently. Your code continues to work normally.
Q: Does this slow down my app?
A: ~5ms overhead per call for tracking. Negligible.
Q: Can I turn off tracking?
A: Yes, just switch back to from ai_sdk import ...
Q: Do I need to change my code besides the import?
A: No. Everything else stays exactly the same.
Q: What Vercel AI SDK features are supported?
A: Currently generate_text(), anthropic(), openai(). Streaming and tool calling coming soon.
Roadmap
- โ
v0.1.0: Drop-in replacement for
generate_text() - ๐ v0.2.0: Streaming support
- ๐ v0.3.0: Tool calling support
- ๐ v0.4.0: More providers (Cohere, Google, etc.)
Documentation
- DEMO_COMPARISON.md - Before/After comparison demo
- MIGRATION_GUIDE.md - Complete migration from Vercel AI SDK
- TEMPLATE_DEMO.md - Editable prompts demonstration
- CODE_COMPARISON.md - Exact code differences side-by-side
Repository Structure
contextifyAI/
โโโ contextifyai/ # Python package (pip install)
โ โโโ config.py # Configuration management
โ โโโ vercel_compatible.py # Wrapped Vercel AI SDK functions
โโโ dashboard/ # Next.js frontend (Vercel)
โ โโโ app/ # Dashboard with dark mode
โโโ backend/ # FastAPI backend (Vercel)
โ โโโ app/ # Tracking API
โโโ examples/ # Usage examples
โโโ before_vercel_only.py
โโโ after_contextifyai.py
โโโ with_templates.py
Running Locally
Backend
cd backend
pip install -r requirements.txt
python server.py
# Runs on http://localhost:8000
Dashboard
cd dashboard
npm install
npm run dev
# Runs on http://localhost:3000
License
MIT
Summary
โ One line change โ Full tracking
- from ai_sdk import generate_text, anthropic
+ from contextifyai import generate_text, anthropic
โ Same API โ No code changes
โ Same results โ Works exactly the same
โ Plus tracking โ Dashboard, analytics, versioning
Get started now:
pip install contextifyai
Then change your import and you're done! ๐
Live Resources:
- ๐ฆ PyPI Package
- ๐ Dashboard Demo
- ๐ง API Backend
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contextifyai-0.1.1.tar.gz.
File metadata
- Download URL: contextifyai-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0420527426970456553a9241cb66b2541345b12aefbeca5992192f5d0965a7b
|
|
| MD5 |
4e74b40d178824380504829b8eeaf3c1
|
|
| BLAKE2b-256 |
46d8e34cf8103e3c11df322259c35524ebc5e434d4158f54db9232e7da1be482
|
File details
Details for the file contextifyai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: contextifyai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a56fca496e6224ae5326abb8a7435e668ffd4e3a0215d1ee26aa8ec30948eb75
|
|
| MD5 |
b59277c72b1ec15e20d155cde93cc24b
|
|
| BLAKE2b-256 |
a0a961c90e949c6dfaa398e9e8f29fe102c6e3eee6ff310cac7d3d3db63cf9e4
|