logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AI-Prompt-Refiner-Service

An intelligent utility that restructures rudimentary user inputs into highly effective, optimized directives for generative AI engines. It accomplishes this by dynamically associating requests with suitable predefined instructional blueprints and injecting derived data points. This process guarantees superior output quality while faithfully preserving the user's core intent.

Author

AI-Prompt-Refiner-Service logo

iRahulPandey

Apache License 2.0

Quick Info

GitHub GitHub Stars 6
NPM Weekly Downloads 0
Tools 1
Last Updated 2026-02-19

Tags

apisrequestspromptsrequests irahulpandeyirahulpandey promptlabprompts ai

AI-Prompt-Refiner-Service: Advanced Directive Optimization with MLflow Integration

This sophisticated utility transforms simple user inquiries into high-performance directives for Artificial Intelligence models by leveraging the MLflow Prompt Registry. It features intelligent assignment of user requests to the optimal directive blueprint and subsequent parameter injection.

🔍 Core Concept

By integrating the MLflow Prompt Registry with dynamic blueprint selection logic, this service establishes a robust and adaptable framework for directive engineering:

  • Centralized Blueprint Repository: Manage, version, and oversee directives within MLflow.
  • Contextual Mapping: Intelligently map incoming queries to the most contextually relevant instructional blueprint.
  • Change Tracking: Maintain a complete historical record of directive iterations using production and archival designations.
  • Adaptability: Easily incorporate novel directive formats without necessitating code recompilation.

🏗️ System Structure

The architecture is partitioned into three primary functional modules:

  1. Directive Registry Tool (register_prompts.py) - Facilitates the registration and lifecycle management of directives within MLflow.
  2. Orchestration Engine (promptlab_server.py) - Hosts the core logic, featuring dynamic directive mapping and LangGraph orchestration.
  3. Client Interface (promptlab_client.py) - A lightweight module for submitting and processing end-user data requests.

Operational Sequence

  1. Directive Ingestion: Register instructional blueprints in MLflow, assigning versions and lifecycle aliases.
  2. Blueprint Initialization: The Orchestration Engine loads all accessible directives from MLflow upon startup.
  3. Query Submission: The Client Interface relays a natural language request from the user.
  4. Intelligent Mapping: An integrated Large Language Model (LLM) evaluates the request to select the most fitting directive blueprint.
  5. Data Point Extraction: Necessary variables (parameters) are automatically extracted from the user's input.
  6. Blueprint Assembly: The selected blueprint is populated using the extracted data points.
  7. Refinement & Vetting: The resulting enhanced directive undergoes validation and necessary refinement.
  8. Response Generation: The optimized directive yields a high-fidelity result.

📂 File Layout

AI-Prompt-Refiner-Service/
├── promptlab_server.py            # Core engine with LangGraph workflow
├── promptlab_client.py            # User query processing utility
├── register_prompts.py            # MLflow directive management utility
├── requirements.txt               # Project dependencies manifest
├── advanced_prompts.json          # Supplementary directive templates
└── README.md                      # System documentation

Key Modules Detail:

register_prompts.py

  • Function: Manages directives lifecycle in the MLflow Registry.
  • Principal Operations:
  • register_prompt(): Enrolls a new directive or version.
  • update_prompt(): Supersedes an existing directive (automatically archives the prior production iteration).
  • list_prompts(): Displays all registered blueprints.
  • register_from_file(): Ingests multiple directives from a JSON source.
  • register_sample_prompts(): Initializes the registry with baseline directives.

promptlab_server.py

  • Function: Executes requests using the LangGraph orchestration paradigm.
  • Core Elements:
  • load_all_prompts(): Fetches directives from MLflow.
  • match_prompt(): Determines the optimal blueprint for the input.
  • enhance_query(): Implements the chosen blueprint.
  • validate_query(): Verifies the enhanced directive.
  • LangGraph workflow: Manages the sequential enhancement process.

promptlab_client.py

  • Function: Offers the user interaction layer for the service.
  • Key Capabilities:
  • Process inputs using refined directives.
  • Query the registry for available blueprints.
  • Present detailed information regarding blueprint selection.

🚀 Initiation Guide

Prerequisites

  • Python Version 3.12 required.
  • Dependencies listed in requirements.txt must be installed.
  • Valid OpenAI API access credential.

Setup

# Obtain the repository source
git clone https://github.com/iRahulPandey/PromptLab.git
cd PromptLab

# Install required libraries
pip install -r requirements.txt

# Configure API access
export OPENAI_API_KEY="your-openai-api-key"

Directive Ingestion

Load initial blueprints before operational use:

# Enroll baseline directives (e.g., narrative, correspondence, technical, creative)
python register_prompts.py register-samples

# Ingest supplementary blueprint types (recommended)
python register_prompts.py register-file --file advanced_prompts.json

# Confirm successful registration
python register_prompts.py list

Launching the Orchestration Engine

# Start the service
python promptlab_server.py

Utilizing the Client Interface

# Execute a request using the optimized directive
python promptlab_client.py "Draft an article about advancements in deep learning"

# Display the current registry catalog
python promptlab_client.py --list

# Enable detailed logging for troubleshooting
python promptlab_client.py --verbose "Generate a slide deck outline for the topic of ecological preservation"

📋 Blueprint Management

Supported Directive Formats

This service accommodates a diverse spectrum of instructional categories:

Blueprint Type Purpose Typical Application Scenario
essay_prompt Scholarly composition Research reports, detailed analyses
email_prompt Message composition Formal professional correspondence
technical_prompt Explaining technical subjects Concepts definition, technology deep-dives
creative_prompt Fictional writing Short stories, poetic verse, imaginative content
code_prompt Script generation Algorithmic solutions, function creation
summary_prompt Information condensation Document or article abstract generation
analysis_prompt Critical evaluation Textual data, conceptual frameworks
qa_prompt Context-aware answering Providing answers based on provided context
social_media_prompt Platform-specific content Posts tailored for social networks
blog_prompt Web article creation Long-form online publication pieces
report_prompt Structured documentation Business or technical findings summaries
letter_prompt Formal correspondence Job applications, recommendation submissions
presentation_prompt Presentation structure generation Talk outlines, slide narrative flow
review_prompt Critique generation Feedback on goods, media, or services
comparison_prompt Comparative assessment Analyzing differences between items or ideas
instruction_prompt Procedural guidance Step-by-step operational manuals
custom_prompt Tailored specifications Niche requirements not covered above

Registering Novel Blueprints

New blueprints can be added via several input methods:

1. Via Command Line Interface

python register_prompts.py register \
  --name "novel_directive" \
  --template "Your blueprint text containing {{ parameters }}" \
  --message "Initial commit description" \
  --tags '{"category": "custom", "intent": "specialized_task"}'

2. From a Source File

# Create a text file holding the template content
echo "Blueprint content including {{ variables }}" > directive_draft.txt

# Register using the file path
python register_prompts.py register \
  --name "file_based_directive" \
  --template directive_draft.txt \
  --message "Bulk template addition"

3. From a Structured JSON Manifest

Prepare a JSON file listing multiple blueprints:

{
  "blueprints": [
    {
      "name": "new_blueprint_id",
      "template": "Template structure with {{ variables }}",
      "commit_message": "Description of changes",
      "tags": {"type": "category", "function": "purpose"}
    }
  ]
}

Then execute the batch registration:

python register_prompts.py register-file --file your_blueprints_manifest.json

Modifying Existing Blueprints

Updating an extant blueprint triggers an automatic archival process: 1. The preceding active iteration is moved to the archive status. 2. The newest iteration is immediately promoted to production status.

python register_prompts.py update \
  --name "essay_prompt" \
  --template "Significantly refined template focusing on {{ focus_area }} and {{ tone }}" \
  --message "Improved structural coherence"

Querying Blueprint Metadata

# List all currently managed blueprints
python register_prompts.py list

# Retrieve granular data for a specific blueprint
python register_prompts.py details --name "essay_prompt"

🛠️ Advanced Deployment Scenarios

Template Data Placeholders

Placeholders within blueprints must adhere to the {{ variable_name }} convention:

Compose a {{ formality }} electronic letter directed toward my {{ target_audience }} detailing the subject of {{ main_concern }}. Ensure the following are present:
- A precise subject header
- A suitable salutation
... 

The mapping process automatically identifies and extracts values corresponding to these placeholders from the user's input.

Lifecycle Aliases (Production vs. Archive)

Each blueprint version can possess distinct lifecycle markers: - production: The currently active, default-used version. - archived: Previous iterations retained for historical reference.

This facilitates: - Seamless reversion to prior stable states if performance degrades. - Comprehensive tracking of directive evolution over time.

Custom Directive Formulation

For highly specific operational needs, bespoke blueprints can be authored:

python register_prompts.py register \
  --name "financial_analysis_directive" \
  --template "Act as a {{ authorized_role }} specialized in {{ financial_sector }}. Produce a {{ document_format }} concerning {{ subject_matter }} that emphasizes {{ required_metric }} metrics." \
  --message "Specialized directive for Q3 financial reporting" \
  --tags '{"type": "custom", "task": "reporting", "sector": "finance"}'

🔧 Contingency Planning

Failure to Map a Directive

Should the system be unable to find a suitable blueprint for an input query, the fallback mechanism is: 1. A notification is logged indicating no match was established. 2. The raw, unrefined query is processed without template modification. 3. A response is generated based on the original input.

To mitigate this, continually expand the library with more contextually varied instructional blueprints.

Disruption in LLM Connectivity

If the primary AI service endpoint becomes unreachable, the system degrades gracefully by employing: 1. Heuristic (keyword-based) methods for blueprint selection. 2. Simplified, rule-based parameter extraction. 3. Basic directive enhancement procedures.

This ensures core functionality persists even during external service outages.

See Also

`