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 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


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:

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.2.tar.gz (8.2 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.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contextifyai-0.1.2.tar.gz
  • Upload date:
  • Size: 8.2 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.2.tar.gz
Algorithm Hash digest
SHA256 ee0d6fc04296890baff1de9470dd2b1e8f76a53634eefce37dfc609444ffcd35
MD5 6d789b1ab91b47390bafdc503dbcc8fc
BLAKE2b-256 e96a387cd95013810defb2afcf9d840995591fbd5632d67c6f91a476f44df5d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: contextifyai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c803c6abb0d00cab247d87c316b79b813cc6ede83138403de84f329e754e654
MD5 346ae0c542df5d21b72c08ec1585f69e
BLAKE2b-256 fb0a2ca2308b210a4716544f1d305aad68d8ea5818e9330fa876d08152089bb7

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