Skip to main content

Contextual Optimization and Refinement Engine for AI

Project description

Core4AI: Contextual Optimization and Refinement Engine for AI

Core4AI is an intelligent system that transforms basic user queries into optimized prompts for AI systems using MLflow Prompt Registry. It dynamically matches user requests to the most appropriate prompt template and applies it with extracted parameters.

✨ Key Features

  • 📚 Centralized Prompt Management: Store, version, and track prompts in MLflow
  • 🧠 Intelligent Prompt Matching: Automatically match user queries to optimal templates
  • 🔄 Dynamic Parameter Extraction: Identify and extract parameters from natural language
  • 🔍 Content Type Detection: Recognize the type of content being requested
  • 🛠️ Multiple AI Providers: Seamless integration with OpenAI and Ollama
  • 📊 Detailed Response Tracing: Track prompt optimization and transformation stages
  • 📝 Version Control: Track prompt history with production and archive aliases
  • 🧩 Extensible Framework: Add new prompt types without code changes

🚀 Installation

Basic Installation

# Install from PyPI
pip install core4ai

Development Installation

# Clone the repository
git clone https://github.com/iRahulPandey/core4ai.git
cd core4ai

# Install in development mode
pip install -e ".[dev]"

⚙️ Initial Configuration

After installation, run the interactive setup wizard:

# Run the setup wizard
core4ai setup

The wizard will guide you through:

  1. MLflow Configuration:

    • Enter the URI of your MLflow server (default: http://localhost:8080)
    • Core4AI will use MLflow to store and version your prompts
  2. AI Provider Selection:

    • Choose between OpenAI or Ollama
    • For OpenAI: Set your API key as an environment variable:
      export OPENAI_API_KEY="your-api-key-here"
      
    • For Ollama: Specify the server URI and model to use

🛠️ Usage Examples

Managing Prompts

# Register a new prompt with a template
core4ai register --name "essay_prompt" \
    --message "Basic essay template" \
    "Write a well-structured essay on {{ topic }} that includes an introduction, body paragraphs, and conclusion."

# Register multiple prompts from a JSON file
core4ai register --file prompts.json

# List all available prompts
core4ai list

# Get details about a specific prompt
core4ai list --name "essay_prompt@production" --details

# Later, update the same prompt (creates a new version)
core4ai register --name "email_prompt" "Write an updated {{ formality }} email..."

Basic Chat Interactions

# Simple query - Core4AI will match to the best prompt template
core4ai chat "Write about the future of AI"

# Get a simple response without enhancement details
core4ai chat --simple "Write an essay about climate change"

# See verbose output with prompt enhancement details
core4ai chat --verbose "Write an email to my boss about a vacation request"

💡 Sample Prompts

Core4AI comes with several pre-registered prompt templates:

# Register sample prompts
core4ai register --samples

This will register the following prompt types:

Prompt Type Description Sample Variables
essay_prompt Academic writing topic
email_prompt Email composition formality, recipient_type, topic
technical_prompt Technical explanations topic, audience
creative_prompt Creative writing genre, topic
code_prompt Code generation language, task, requirements
summary_prompt Content summarization content, length

🔄 Provider Configuration

OpenAI

To use OpenAI, set your API key:

# Set environment variable (recommended)
export OPENAI_API_KEY="your-api-key-here"

# Or configure during setup
core4ai setup

Available models include:

  • gpt-3.5-turbo (default)
  • gpt-4
  • gpt-4-turbo

Ollama

To use Ollama:

  1. Install Ollama on your system
  2. Start the Ollama server:
    ollama serve
    
  3. Configure Core4AI:
    core4ai setup
    

📋 Command Reference

Command Description Examples
core4ai setup Run the setup wizard core4ai setup
core4ai register Register a new prompt core4ai register --name "email_prompt" "Write a {{ formality }} email..."
core4ai list List available prompts core4ai list --details
core4ai chat Chat with enhanced prompts core4ai chat "Write about AI"
core4ai version Show version info core4ai version

🧪 Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run all tests
pytest

# Run specific test category
pytest tests/unit
pytest tests/functional
pytest tests/integration

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

📊 How Core4AI Works

Core4AI follows this workflow to process queries:

  1. Query Analysis: Analyze the user's query to determine intent
  2. Prompt Matching: Match the query to the most appropriate prompt template
  3. Parameter Extraction: Extract relevant parameters from the query
  4. Template Application: Apply the template with extracted parameters
  5. Validation: Validate the enhanced prompt for completeness and accuracy
  6. Adjustment: Adjust the prompt if validation issues are found
  7. AI Response: Send the optimized prompt to the AI provider

📜 License

This project is licensed under the Apache License 2.0

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

core4ai-1.0.0.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

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

core4ai-1.0.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file core4ai-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for core4ai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 799acf8a05f1b26cff0caa2ecaba087acc82fded60ebcc62050b1ca91fbc2f63
MD5 a8d71993497edf786a1540f089ab30c6
BLAKE2b-256 a56319f57764c28b2175b5a3c39c14fd74131440ca35c6aff20a1aacd1360af4

See more details on using hashes here.

File details

Details for the file core4ai-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: core4ai-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 35.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for core4ai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65f783025c2d129c887d9fa1ddb0d926b4ba194d996b159696832d45455e0591
MD5 28c42d0bafc690c0d070f6f7d2230fd2
BLAKE2b-256 6dea9d997e8a17c57b5b698991180dd08094f2bdfd666bc34668fda05abfd45f

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