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)

๐Ÿ“ 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.3.tar.gz (8.3 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.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contextifyai-0.1.3.tar.gz
  • Upload date:
  • Size: 8.3 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.3.tar.gz
Algorithm Hash digest
SHA256 5c3b9ce30b22e0228eb5f3d9fb2be3bab4af11888e7bd30700df07e6e08eab14
MD5 5c7f952e2e83d8ed5a2aad1f708e8b06
BLAKE2b-256 88b0acd1f7ead5e0eb18e485dcdc439fda7fae64b51b2461b8be3492c489771b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: contextifyai-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 be905feb006de440788e3792ec3bf2d834c8e77e204fc55df7801fc2e70e1375
MD5 5495ba3dbdeef111522d14044db4f175
BLAKE2b-256 00a68e05a3949b10764720ba9d78fc75f6ffcae98c8c29414912543fdcbc4665

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