Skip to main content

Prompt evaluation and mock LLM for testing

Project description

LLM Quick Tools ⚡

PyPI Python License

A lightweight dual-purpose library for:

  1. Prompt Evaluation - Score and improve LLM inputs
  2. Mock LLM - Simulate API responses during development

Installation

pip install llm-quick-tools

1. Prompt Scoring 🔍

Evaluate prompt quality across multiple dimensions.

Quick Start

from llm_quick_tools import PromptEvaluator

evaluator = PromptEvaluator()
scores = evaluator.evaluate(
    "Explain quantum computing to a 5-year-old",
    task="education"
)

print(scores)

Output:

{
    'length': 0.38,        # Optimal 20-100 chars
    'clarity': 0.9,        # Sentence structure
    'toxicity': 0.02,      # Harmful content risk
    'task_alignment': 0.8  # Relevance to education
}

Scoring Metrics

Metric Range Ideal Description
Length 0-1 0.3-0.7 Prompt character length
Clarity 0-1 >0.8 Sentence complexity
Toxicity 0-1 <0.1 Risk of harmful content
Task Alignment 0-1 >0.7 Relevance to specified task

2. Mock LLM 🤖

Simulate LLM responses without API calls.

Response Modes

from llm_quick_tools import MockLLM

# Initialize with different modes
echo_llm = MockLLM(mode="echo")
template_llm = MockLLM(mode="template")

Mode Comparison

Mode Description Example Input → Output
echo Repeats input "Hi" → "Echo: Hi"
random Random responses "Help" → "Try checking our docs"
template Keyword-triggered "price" → "The cost is $9.99"

Template Management

# Add custom templates
template_llm.add_template(
    "contact support",
    "Email us at help@company.com"
)

# Load from JSON
template_llm.load_templates("path/to/templates.json")

# Generate responses
print(template_llm.generate("How to contact support?"))
# Output: "Email us at help@company.com"

Pre-Loaded Templates

{
    "hello": "Hi! How can I help?",
    "goodbye": "Have a nice day!",
    "pricing": "Our plans start at $9.99/mo",
    "refund": "Refunds take 5-7 business days",
    "tech support": "Try restarting your device"
}

Advanced Usage

Combined Workflow

# 1. Evaluate prompt
scores = evaluator.evaluate("Tell me a joke about AI")

# 2. Generate mock response
if scores['toxicity'] < 0.1:
    response = template_llm.generate("Tell me a joke about AI")
else:
    response = "I can't comply with that request"

Custom Template JSON

// custom_templates.json
{
    "feature request": "Added to our roadmap",
    "bug report": "We'll investigate this issue",
    "order {} status": "Order #{} ships in 2 days"
}

Use Cases

  • Testing - Verify LLM integration logic
  • Development - Prototype before API integration
  • Education - Teach prompt engineering concepts
  • CI/CD - Run deterministic tests in pipelines

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add feature')
  4. Push (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

MIT © Aryan

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

llm_quick_tools-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_quick_tools-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file llm_quick_tools-0.1.1.tar.gz.

File metadata

  • Download URL: llm_quick_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for llm_quick_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7b9f67a0556349eb3e2c017277c76b83e82492c2258318b21c4bbe41c1ab56cb
MD5 08b4c9a03f1d97993fd104e1c262f7fc
BLAKE2b-256 431d4e8c2f4053e21578bbc37ecb500dddb2e34369297e7b02d3ef0fa7146d24

See more details on using hashes here.

File details

Details for the file llm_quick_tools-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_quick_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4012ec6c5b2c2c51b777b5dc042056de219e990d6b61b8bac339aee6a15e7bf
MD5 005b8654ec20ca205dc697a5baa3c06b
BLAKE2b-256 b79cd8ecccb99aeee0a8f1b46f838f5ec821e1e116ad56b2b91cfac951c3eddb

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