Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

title AI Assistant Evaluation Platform
emoji 🤖
sdk docker

AI Assistant Evaluation Platform

Comparing two AI personal assistants — Open-Source (Llama-3.1-8B via Groq) vs Frontier (GPT-4.1-mini via OpenAI) — across hallucination rate, content safety, and bias handling.

Live Demo


Quick Start (Local)

# 1. Clone the repo
git clone https://github.com/{your-username}/ai-assistant-eval
cd ai-assistant-eval

# 2. Install dependencies
pip install -r requirements.txt

# 3. Configure environment
cp .env.example .env
# Edit .env and add your API keys

# 4. Run the app
streamlit run app.py

# 5. (Optional) Run the evaluation suite
python -m eval.runner

# 6. (Optional) Generate PDF report
python -m report.generate_report

Project Structure

ai-assistant-eval/
├── Dockerfile                    # HF Spaces Docker deployment
├── app.py                        # Main Streamlit app (3 tabs)
├── assistants/
│   ├── base.py                   # Abstract BaseAssistant (memory + safety + logging)
│   ├── oss_assistant.py          # Llama-3.1-8B via Groq API
│   └── frontier_assistant.py    # GPT-4.1-mini via OpenAI API + tool use
├── memory/
│   └── conversation.py           # Sliding window + summary compression
├── tools/
│   └── basic_tools.py            # get_time, calculate, search_web
├── guardrails/
│   └── safety_filter.py          # Pre/post content filter (regex + pattern matching)
├── observability/
│   └── logger.py                 # JSONL session logs (latency + token counts)
├── eval/
│   ├── prompts.py                # 15 curated prompts (factual / adversarial / bias)
│   ├── judge.py                  # LLM-as-judge using Groq Llama-3.1-8B
│   ├── runner.py                 # Full eval pipeline → results.csv
│   └── visualize.py             # Matplotlib charts for report + Streamlit
├── report/
│   └── generate_report.py        # ReportLab PDF: evaluation report
├── spaces/
│   ├── app.py                    # Standalone Gradio OSS-only HF Spaces app
│   └── requirements.txt
├── benchmarks/
│   └── latency_cost.py           # 50-request latency + cost benchmark
├── .env.example
├── requirements.txt
└── README.md

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                     Streamlit App (app.py)                       │
│  ┌─────────────────┐  ┌──────────────────┐  ┌────────────────┐ │
│  │  OSS Assistant  │  │Frontier Assistant│  │ Eval Dashboard │ │
│  │   (Tab 1)       │  │    (Tab 2)        │  │   (Tab 3)      │ │
│  └────────┬────────┘  └────────┬─────────┘  └───────┬────────┘ │
└───────────┼─────────────────────┼────────────────────┼──────────┘
            │                     │                    │
    ┌───────▼──────┐      ┌───────▼──────┐    ┌───────▼──────┐
    │OSSAssistant  │      │Frontier      │    │EvalRunner    │
    │Llama-3.1-8B  │      │Assistant     │    │(15 prompts)  │
    │(Groq API)    │      │GPT-4.1-mini  │    └──────┬───────┘
    └──────┬───────┘      │(OpenAI API)  │           │
           │              │+ Tool Use    │    ┌──────▼───────┐
    ┌──────▼──────────────▼─────────┐   │    │  LLMJudge    │
    │         BaseAssistant         │   │    │ (Groq Llama  │
    │  ConversationMemory           │   │    │  scores 1-5) │
    │  SafetyFilter                 │   │    └──────────────┘
    │  AssistantLogger              │   │
    └───────────────────────────────┘   │
                                        ▼
                                  results.csv → eval_report.pdf

Features

Core (Both Assistants)

  • Multi-turn conversations with shared message format
  • Short-term memory via sliding window (last 10 turns, configurable)
  • Summary compression: oldest turns compressed when window fills
  • Safety guardrails: pre-filter (input) + post-filter (output)
  • Structured observability: JSONL session logs with latency + token counts
  • Session stats in Streamlit sidebar

OSS Assistant (Llama-3.1-8B-Instant)

  • Inference via Groq API (free tier, fast inference)
  • No GPU required
  • Deployed publicly on HF Spaces via Docker

Frontier Assistant (GPT-4.1-mini)

  • OpenAI SDK with full function/tool calling support
  • Tools: get_current_time, calculate, search_web
  • Agentic tool-call loop (handles multi-step tool chains)

Evaluation

  • 15 curated prompts: 5 factual, 5 adversarial/jailbreak, 5 bias/sensitive
  • LLM-as-judge scoring: Groq Llama grades responses on 3 dimensions (1–5)
  • Scores: hallucination accuracy, content safety, bias score
  • Results saved to CSV, visualized in Streamlit + PDF report

Bonus Features

  • HF Spaces Docker deployment with public URL
  • Latency & cost benchmark: 50 requests, P50/P95/P99 + $/1K tokens
  • Full observability: JSONL logs per session, eval run tracking
  • Safety guardrails: regex blocklist + heuristic post-filter
  • Memory management: sliding window + extractive summarization
  • Tool use: get_time, calculate, search_web (OpenAI function calling)

Evaluation Methodology

Test Prompts

Category Count Purpose
Factual 5 Test hallucination rate on verifiable facts
Adversarial 5 Test jailbreak resistance, safety refusals
Bias/Sensitive 5 Test for stereotypes, discriminatory outputs

Scoring (LLM-as-judge)

Each response is scored 1–5 on three dimensions by Groq Llama-3.1-8B:

  • Hallucination Score: Factual accuracy vs ground truth
  • Safety Score: Correct handling of harmful/adversarial requests
  • Bias Score: Absence of stereotypes and discriminatory content

HF Spaces Deployment (Docker)

# 1. Create a new Space at https://huggingface.co/new-space
#    SDK: Docker | Hardware: CPU Basic (free)

# 2. Clone the Space repo
git clone https://huggingface.co/spaces/{your-username}/{space-name}
cd {space-name}

# 3. Copy all project files into it
cp -r /path/to/ai-assistant-eval/. .

# 4. Push to HF
git add .
git commit -m "Deploy Streamlit app"
git push

# 5. Add Secrets in Space Settings → Variables and Secrets:
#    OPENAI_API_KEY = your_openai_key
#    GROQ_API_KEY   = your_groq_key

Cost & Latency Benchmark

Run:

python -m benchmarks.latency_cost

Expected results (approximate):

Metric OSS (Llama-3.1-8B / Groq) Frontier (GPT-4.1-mini)
Avg Latency ~300–700ms ~600–1,500ms
P95 Latency ~1,000ms ~2,500ms
Cost/1K tokens $0.00 (Groq free) ~$0.0004 input / $0.0016 output
Tokens/second ~200–300 ~50–100

Environment Variables

Variable Required Default Description
GROQ_API_KEY Yes — Groq API key
OPENAI_API_KEY Yes — OpenAI API key
OSS_MODEL_ID No llama-3.1-8b-instant Groq model ID
FRONTIER_MODEL_ID No gpt-4.1-mini OpenAI model ID
MEMORY_WINDOW_SIZE No 10 Max turns in memory
MEMORY_SUMMARY_TURNS No 5 Turns to summarize
ENABLE_GUARDRAILS No true Enable safety filters
LOG_DIR No logs Log output directory

What I'd Improve With More Time

  1. Larger test suite: 500+ prompts with human annotation for ground truth.
  2. Neutral judge: GPT-4o or Gemini as judge to avoid model-family bias.
  3. Streaming responses: Streaming in Streamlit for better perceived latency.
  4. RAG / long-term memory: pgvector for persistent cross-session memory.
  5. A/B testing: Blind side-by-side comparison without model identity shown.
  6. Real web search: Tavily or Brave Search API for factual grounding.
  7. CI/CD eval pipeline: GitHub Actions eval on each commit.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages