Skip to main content

Why QWEDLocal?

No backend server needed

  • Run verification directly in your application
  • No infrastructure to manage
  • Suitable for prototyping, scripts, and small projects

Local execution

  • Your API keys stay on your machine
  • Your data does not touch QWED servers
  • Useful for HIPAA, GDPR, and sensitive-data workloads

Model agnostic

  • Works with any supported LLM — OpenAI, Anthropic, Gemini
  • Works with local models via Ollama
  • Works with any OpenAI-compatible API

Deterministic caching

  • Cached results return without an LLM round-trip
  • Repeated queries skip the LLM call
  • Cache hits avoid network latency

Installation

pip install qwed
Dependencies:
# For different LLM providers
pip install openai         # OpenAI + Ollama
pip install anthropic      # Anthropic Claude
pip install google-generativeai  # Google Gemini

# For verification engines
pip install sympy          # Math verification
pip install z3-solver      # Logic verification

# For caching and CLI
pip install colorama click

Quick start

Option 1: Ollama (no per-call cost)

# 1. Install Ollama
# Visit: https://ollama.com

# 2. Pull a model
ollama pull llama3

# 3. Start Ollama
ollama serve
from qwed_sdk import QWEDLocal

client = QWEDLocal(
    base_url="http://localhost:11434/v1",
    model="llama3"
)

result = client.verify_math("What is 2+2?")
print(result.verified)  # True
print(result.value)  # 4

Option 2: OpenAI

from qwed_sdk import QWEDLocal

client = QWEDLocal(
    provider="openai",
    api_key="sk-proj-...",
    model="gpt-4o-mini"  # Budget-friendly!
)

result = client.verify_math("What is the derivative of x^2?")
print(result.verified)  # True
print(result.value)  # 2*x

Option 3: Anthropic Claude

from qwed_sdk import QWEDLocal

client = QWEDLocal(
    provider="anthropic",
    api_key="sk-ant-...",
    model="claude-3-haiku-20240307"
)

result = client.verify("What is 5 factorial?")

Verification engines

1. Math verification (SymPy)

result = client.verify_math("What is the integral of 2x?")
print(result.value)  # x**2
print(result.evidence)  # {"method": "sympy_eval", ...}

2. Logic verification (Z3)

result = client.verify_logic("Is (p AND NOT p) satisfiable?")
print(result.value)  # FALSE (contradiction!)
print(result.evidence)  # {"method": "z3_sat", ...}

3. Code security (AST)

code = """
def safe_function():
    return 42
"""

result = client.verify_code(code)
print(result.value)  # "SAFE"
Dangerous code detection:
dangerous_code = """
import os
eval(user_input)
"""

result = client.verify_code(dangerous_code)
print(result.value)  # "UNSAFE"
print(result.evidence["dangerous_patterns"])
# ["Dangerous function: eval"]

Deterministic caching

Caching avoids redundant LLM calls.
# First call - hits LLM ($$$)
result = client.verify_math("2+2")
# -> 🔬 QWED Verification | Math Engine
# -> 📝 LLM Response: 4
# -> ✅ VERIFIED → 4

# Second call - from cache (FREE!)
result = client.verify_math("2+2")
# -> ⚡ Cache HIT (saved API call!)
# -> Returns instantly!
Cache stats:
stats = client.cache_stats
print(f"Hit rate: {stats.hit_rate:.1%}")
print(f"Hits: {stats.hits}, Misses: {stats.misses}")
Disable caching:
client = QWEDLocal(
    provider="openai",
    api_key="...",
    cache=False  # Always fresh
)

CLI tool

One-shot verification

# Basic usage
qwed verify "What is 2+2?"

# With specific provider
qwed verify "derivative of x^2" --provider openai --model gpt-4o-mini

# With Ollama
qwed verify "5!" --base-url http://localhost:11434/v1 --model llama3

# Quiet mode (for scripts)
qwed verify "2+2" --quiet

Interactive mode

qwed interactive

# Output:
🔬 QWED Interactive Mode
Type 'exit' or 'quit' to quit

> What is 2+2?
🔬 QWED Verification | Math Engine
📝 LLM Response: 4
 VERIFIED 4

> exit

Cache management

# View cache stats
qwed cache stats

# Clear cache
qwed cache clear

Help

qwed --help
qwed verify --help
qwed interactive --help

Cost comparison

TierMonthly costLLM optionsUse cases
Local$0Ollama (Llama 3, Mistral, Phi)students, privacy, development
Budget~$5-10GPT-4o-mini, Gemini Flashstartups, prototypes
Premium~$50-100GPT-4, Claude Opusenterprises, production
Caching reduces repeated-query cost by skipping the LLM call.

Privacy and security

Local-only data flow

QWEDLocal architecture:
┌─────────────────────────────────────┐
│ Your Machine                        │
│                                     │
│  ┌──────────────┐                  │
│  │ QWEDLocal    │                  │
│  │ (Your Code)  │                  │
│  └──────┬───────┘                  │
│         │                           │
│         ├─→ LLM API (Direct)       │
│         │   (OpenAI/Anthropic/     │
│         │    Ollama)                │
│         │                           │
│         └─→ Verifiers (Local)      │
│             SymPy, Z3, AST          │
│                                     │
│  ❌ NO data sent to QWED!          │
└─────────────────────────────────────┘
Use cases:
  • Healthcare (HIPAA compliance)
  • Finance (PCI-DSS compliance)
  • Government (classified data)
  • Privacy-focused applications

Advanced configuration

Custom cache settings

client = QWEDLocal(
    provider="openai",
    api_key="...",
    cache=True,
    cache_ttl=3600  # 1 hour TTL (default: 24 hours)
)

Environment variables

export QWED_API_KEY="sk-..."
export QWED_QUIET=1  # Disable colorful output

Quiet mode (no branding)

import os
os.environ["QWED_QUIET"] = "1"

client = QWEDLocal(...)
result = client.verify("2+2")
# No colored output, just results

Examples

Example 1: fact-checking pipeline

from qwed_sdk import QWEDLocal

client = QWEDLocal(base_url="http://localhost:11434/v1", model="llama3")

facts_to_check = [
    "2+2=4",
    "The derivative of x^2 is 2x",
    "Paris is the capital of France"
]

for fact in facts_to_check:
    result = client.verify(fact)
    print(f"{fact}: {'✅' if result.verified else '❌'}")

Example 2: code review automation

import os
from qwed_sdk import QWEDLocal

client = QWEDLocal(provider="openai", api_key=os.getenv("OPENAI_API_KEY"))

code_snippets = [
    "def add(a, b): return a + b",
    "exec(user_input)",  # Dangerous!
    "import os; os.system('rm -rf /')"  # Very dangerous!
]

for code in code_snippets:
    result = client.verify_code(code)
    status = "🟢 SAFE" if result.verified else "🔴 UNSAFE"
    print(f"{status}: {code[:30]}...")
    if not result.verified:
        print(f"  Issues: {result.evidence['dangerous_patterns']}")

Example 3: batch processing with cache

from qwed_sdk import QWEDLocal

client = QWEDLocal(provider="openai", api_key="...")

# Process 1000 math queries
queries = ["What is 2+2?"] * 500 + ["What is 3+3?"] * 500

for q in queries:
    result = client.verify_math(q)
    # First 2 calls hit LLM, rest cached!

print(client.cache_stats)
# Hit rate: 99.8%! (Saved $$$)

Troubleshooting

LLM not available

# Check if Ollama is running
curl http://localhost:11434/v1/models

# Start Ollama
ollama serve

Missing dependencies

# Install verification engines
pip install sympy z3-solver

# Install LLM clients
pip install openai anthropic google-generativeai

Cache issues

# Clear cache
qwed cache clear

# Or in Python
client._cache.clear()

Learn more


Contributing

Contributions welcome. See the contributing guide.

License

Apache 2.0 — see LICENSE.

Support

If QWEDLocal saved you time or money, give us a star! ⭐ Made with 💜 by the QWED team