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.

PyPI Link: https://pypi.org/project/POP-guotai/

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.3.1.tar.gz (31.4 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.3.1-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pop_guotai-0.3.1.tar.gz
  • Upload date:
  • Size: 31.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.3.1.tar.gz
Algorithm Hash digest
SHA256 c7e317470d50cbccb65080f635091d6a9ea9c9166dfba27e008ba0cace453f03
MD5 987ee9595469f5a034474d03504723c1
BLAKE2b-256 2ebc5401819467d00d82f22e980eff692326c74377f14c664eb780453e0b3a99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: POP_guotai-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 31.1 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3704d532572ad98ef9e5bd8ed4f2497be5421b2ab8948fbc8049f10dd24a1f5
MD5 50d16f1e4aa49958ea7555882c7a2643
BLAKE2b-256 a97a196b4fc864445bf8b37015eaed0e8894a3059b42cad0eeb0ba1f2f541ff1

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