Vizpy

Quickstart

Get your first optimized prompt in under 5 minutes

Quickstart

Get better prompts in one API call. This guide will have you optimizing prompts in under 5 minutes.

Installation

pip install vizpy

Set Your API Keys

export LICENSE_KEY=your_vizpy_license_key
export KEYGEN_ACCOUNT_ID=your_account_id
export OPENAI_API_KEY=your_openai_key

Your First Optimization

import vizpy
import dspy
 
# Configure your LLM
dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))
 
# Define a simple task
class QA(dspy.Signature):
    """Answer questions accurately and concisely."""
    question: str = dspy.InputField()
    answer: str = dspy.OutputField()
 
module = dspy.Predict(QA)
 
# Your training examples
examples = [
    {"question": "What is the capital of France?", "answer": "Paris"},
    {"question": "Who wrote Romeo and Juliet?", "answer": "William Shakespeare"},
    {"question": "What is 2 + 2?", "answer": "4"},
]
 
# Define how to score predictions
def metric(example, prediction):
    expected = example["answer"].lower().strip()
    actual = prediction.answer.lower().strip()
    is_correct = expected in actual or actual in expected
    return vizpy.Score(
        value=1.0 if is_correct else 0.0,
        is_success=is_correct,
        feedback="" if is_correct else f"Expected '{expected}', got '{actual}'"
    )
 
# Optimize!
optimizer = vizpy.ContraPromptOptimizer(metric=metric)
optimized_module = optimizer.optimize(module, examples)
 
# Use your optimized module
result = optimized_module(question="What is the largest planet?")
print(result.answer)

That's it! Your module now has optimized instructions based on patterns learned from your examples.

Next Steps

On this page