Skip to content

Programmatically log your AI prompts for auditing, refinement, or analytics

License

Notifications You must be signed in to change notification settings

rotationalio/prompt-logger

Repository files navigation

prompt-logger

A Python package for logging AI prompts to a database and exporting them for auditing, refinement, or analytics.

Features

  • Programmatically log AI/chatbot interactions (prompts and responses) to a SQLite database
  • Command-line interface to export logs to JSONL format
  • Support for multiple user-defined namespaces
  • Decorator for easy integration with existing code

Installation

pip install prompt-logger

Usage

As a Python Package

from prompt_logger import PromptLogger, capture

# Initialize the logger
logger = PromptLogger("my-namespace", database="sqlite:///my_prompts.db")

# Log a single prompt and response
logger.save_interaction("What is the weather?", "It's sunny!")

# Export to JSONL
logger.export_to_jsonl("output.jsonl")

# Use the decorator to automatically log prompts
@capture("my-namespace", database="sqlite:///my_prompts.db")
def generate_text(prompt):
    # Your LLM call here
    return "Generated response"

As a Command-Line Tool

Export recorded prompts to a JSONL file:

$ prompt-logger export output.jsonl --namespace=my-namespace --database=sqlite:///my_prompts.db

Development

  1. Clone the repository
  2. Install development dependencies:
    pip install -e ".[dev]"
  3. Run tests:
    pytest

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

About

Programmatically log your AI prompts for auditing, refinement, or analytics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages