Skip to main content

Reusable, mutable, prompt functions for LLMs.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Prompt Oriented Programming (POP)

Reusable, mutable prompt functions for LLMs. Inspired by object-oriented programming (OOP), POP treats prompts as first-class citizens—defining them like functions with inputs, outputs, and reusable logic. Execution is delegated to a language model (LLM), such as OpenAI’s GPT, enabling you to call, modify, and reuse prompts in a structured, programmatic way.


Table of Contents

  1. Features
  2. Installation
  3. Setup & Configuration
  4. Usage
  5. Example
  6. Future Plans
  7. Contributing

Features

  • Prompt as a Function: Declare a prompt once, then execute it any number of times with different inputs.
  • Dynamic Placeholders: Insert variables via placeholders (<<<variable>>>), allowing flexible, user-defined parameters.
  • System Role Defaults: POP stores the main prompt in the “system” role by default, letting you easily switch between roles or contexts.
  • Prompt Enhancement: Leverages patterns from Fabric (MIT licensed) to expand basic prompts into more detailed instructions via pf._improve_prompt().

Installation

  1. Clone or Download this repository (or add it as a submodule in your project).
  2. Install via pip (recommended):
    pip install -e .
    
    This uses the setup.py (and optionally pyproject.toml) so that pop can be globally recognized as a Python package.

For more details on packaging and distribution, see the Installation Steps in the conversation.


Setup & Configuration

Environment Variables

Place a .env file in the same directory as POP.py or Embedder.py, containing API keys if you use OpenAI or other APIs. For example:

OPENAI_API_KEY=your_openai_api_key
JINAAI_API_KEY=your_jina_api_key  # Required only if you use Jina features

Note: POP uses OpenAI by default. Make sure your OPENAI_API_KEY is valid, or configure a different LLM in your code.


Usage

PromptFunction Class

from pop import PromptFunction

# Create a prompt function
pf = PromptFunction(
    sys_prompt="You are a helpful AI assistant.",
    prompt="""
    Please draw a simple ASCII art of <<<object>>>.
    """
)

# Execute with user input
art = pf.execute(object="a cat")
print(art)
  • Placeholders: <<<object>>> is replaced by your chosen argument (object="a cat").
  • Multiple Calls: You can call pf.execute(...) repeatedly with different inputs.

Improving Prompts

expanded_prompt = pf._improve_prompt()
print(expanded_prompt)
  • _improve_prompt(): Expands or refines your base prompt with more detailed instructions (inspired by Fabric’s approach).

Example

from pop import PromptFunction

# Define a prompt function
pf = PromptFunction(
    prompt="""
    Draw a simple ASCII art of an object described by: <<<user_input>>>
    """
)

# First Execution
result = pf.execute(user_input="A cat")
print("ASCII art of a cat:\n", result)

# Second Execution
result = pf.execute(user_input="An apple")
print("ASCII art of an apple:\n", result)

Sample Output:

ASCII art of a cat:
 /\_/\  
( o.o )
 > ^ <  

ASCII art of an apple:
    ,--./,-.
   / #      \
  |          |
   \        /
    `._,._,'

Future Plans

  • Additional LLM Integrations: Support local models or alternative APIs beyond OpenAI and Jina.
  • Enhanced Prompt Composition: Build chains of PromptFunctions for complex workflows.
  • Prompt Testing Framework: Automate checks to validate prompt outputs across multiple inputs.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests:

  1. Fork the repo
  2. Create a feature branch for your changes
  3. Open a PR once ready

Please include clear commit messages and relevant tests or examples.


Enjoy Prompt Oriented Programming! If you have questions or suggestions, don’t hesitate to reach out or file an issue.

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

pop_guotai-0.2.1.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file pop_guotai-0.2.1.tar.gz.

File metadata

  • Download URL: pop_guotai-0.2.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for pop_guotai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fb729bf88f4406b07448a15ceda22335c9f4cbbd37b4393f614a75000f483293
MD5 d77dfd45f6651b737c8a9784e02b2e0b
BLAKE2b-256 2908adf6b72a48039466fa7ed610fd6223c6748db813901d013ca5d3a0bd0973

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