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
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
- Clone or Download this repository (or add it as a submodule in your project).
- Install via
pip(recommended):pip install -e .
This uses thesetup.py(and optionallypyproject.toml) so thatpopcan 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_KEYis 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:
- Fork the repo
- Create a feature branch for your changes
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pop_guotai-0.2.2.tar.gz.
File metadata
- Download URL: pop_guotai-0.2.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e06d463a12bac9105a018c858fb81904c6220ed88aac89a19578c20adff117d
|
|
| MD5 |
09003639282032be96dc4355ed17dada
|
|
| BLAKE2b-256 |
28eb3890569887e5b9daa074b881055dc63b1a2686b4a7dba9c9e2d07ab90264
|