Skip to main content

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 git+https://github.com/sanjevvishnu/contextifyAI.git

Or install from the package directory:

git clone https://github.com/sanjevvishnu/contextifyAI.git
cd contextifyAI
pip install -e contextifyai/

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


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 git+https://github.com/sanjevvishnu/contextifyAI.git

Then change your import and you're done! ๐ŸŽ‰

Try the live demo: Dashboard

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

contextifyai-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextifyai-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file contextifyai-0.1.0.tar.gz.

File metadata

  • Download URL: contextifyai-0.1.0.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

Hashes for contextifyai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c495440346623d1780cdad329932bee620c36dc566c1e8751ae96cec065e7043
MD5 445ba58a33ce08c77df7afea4d6272d1
BLAKE2b-256 359e1a326f017fcb6594c48693eac5db8a74e58d78082f6992c680c1cb789d67

See more details on using hashes here.

File details

Details for the file contextifyai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: contextifyai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for contextifyai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2b01696c5c6ab0b439344de93352001df062cdc6f2285b17b1581792aa69c13
MD5 fe1e75c74e7bb526e621233b88aae671
BLAKE2b-256 6e79dc79cb91d6a6e61bc57fd12f07f225ae04755d3781c68987a2e315df2c61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page