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, composable prompt functions for LLMs. POP treats prompts like first-class functions: reusable, mutable, and structured for programmatic execution. It supports prompt enhancement, function/code generation, multiple LLM backends, and embeddings.

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


Table of Contents

  1. Updates

  2. Features

  3. Installation

  4. Setup & Configuration

  5. Usage

  6. Example

  7. Future Plans

  8. Contributing


Updates

  • 0.3.1: add image support to gemini and openai client

Features

  • Prompt as a Function: Define reusable prompts with <<<placeholders>>> for flexible execution.

  • Multi-LLM Support: Use OpenAI (default), GCP Gemini, local PyTorch, or Deepseek stubs.

  • Function Schema & Code Generation:

    • Turn natural language descriptions into OpenAI function schemas.
    • Optionally generate full Python function code with docstrings and type hints.
  • Prompt Improvement: Enhance base prompts using Fabric-inspired meta-prompts.

  • Embeddings:

    • OpenAI and Jina API embeddings
    • Local Hugging Face model support
  • Utility Functions:

    • get_text_snapshot(url) for webpage-to-text extraction with optional image captioning.

Installation

Install from PyPI:

pip install POP-guotai

Or from source:

git clone https://github.com/sgt1796/POP.git
cd POP
pip install -e .

Setup & Configuration

  1. Create a .env file in your project root:
OPENAI_API_KEY=your_openai_key
GEMINI_API_KEY=your_gcp_gemini_key
JINAAI_API_KEY=your_jina_api_key
  1. Dependencies are automatically handled via setup.py:
  • openai, requests, python-dotenv, pydantic, transformers, numpy, backoff

Usage

PromptFunction Class

from POP import PromptFunction

pf = PromptFunction(
    sys_prompt="You are a helpful AI assistant.",
    prompt="Write a short poem about <<<topic>>>."
)

result = pf.execute(topic="space travel")
print(result)

Improving Prompts

improved_prompt = pf._improve_prompt()
print(improved_prompt)

Function Schema & Code Generation

# 1. Generate a JSON function schema
schema = pf.generate_schema(description="Multiply two integers and return the product.")

# 2. Generate actual Python code
code = pf.generate_code(schema)
print(code)

Embeddings

from POP.Embedder import Embedder

embedder = Embedder(use_api="openai")
vectors = embedder.get_embedding(["Hello world", "POP is awesome!"])
print(vectors.shape)  # (2, embedding_dim)

Web Snapshot Utility

from POP import get_text_snapshot

content = get_text_snapshot("https://example.com", image_caption=True)
print(content[:500])

Example

from POP import PromptFunction

pf = PromptFunction(
    prompt="Draw a simple ASCII art of <<<object>>>."
)

print(pf.execute(object="a cat"))
print(pf.execute(object="a rocket"))

Sample Output:

 /\_/\  
( o.o )
 > ^ <  

   /\
  /  \
 /    \
 |    |
 |    |

Future Plans

  • Complete support for local PyTorch and Deepseek clients
  • Prompt chaining and workflow composition
  • Automated prompt testing framework
  • Extended multimodal support (image + text prompts)

Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Submit a PR with clear commit messages and examples/tests

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.2.tar.gz (30.9 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.2-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pop_guotai-0.3.2.tar.gz
  • Upload date:
  • Size: 30.9 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.2.tar.gz
Algorithm Hash digest
SHA256 7883c6e317207a8474946a4011f1789d49fa8c56e8afccebda3713233a9ce790
MD5 99e8c1b5630fe15acea5c09c4c64ac14
BLAKE2b-256 85f7fcab7fc384d930affb4b975b8d7bf77304165058e32185ed72caba21518f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: POP_guotai-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 30.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8bbc4fdd47303dd0eac1e21736919a6fc4fcbd12bd67f5183ef61d7be5c93991
MD5 b4412cc980bb7463fe3e5f6648a824c4
BLAKE2b-256 b86feddc30b3a9204e2abf4fd3d1c4b4b0ddc9a42d8f74402447314ec0a5fcaf

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