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.1.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

POP_guotai-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pop_guotai-0.1.0.tar.gz
  • Upload date:
  • Size: 13.2 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.1.0.tar.gz
Algorithm Hash digest
SHA256 dcc0609f79b2136dd8d143000373ff81b0ada188e170a97fa289964023440a7e
MD5 fe76f411f86deb967fbd98f3fe42aac2
BLAKE2b-256 43d35643f8ccc6e6f6074f1232493b9e68e6450abc0f259573e098faea661976

See more details on using hashes here.

File details

Details for the file POP_guotai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: POP_guotai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for POP_guotai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3d61511904185e762c6504aedf61600086aa161deb2f24dc342340673066fb
MD5 82fa03608d5d9806a7b125c13291c91b
BLAKE2b-256 3fa37c639f8905c4a1a2f68ed7c324df2f46916401f41a6700ae2d70bf12d2f3

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