Skip to main content

A Python package to simplify type-safe LLM prompts chaining

Project description

Prompt Pipeline

A modern, type-safe prompt pipeline for LLM interactions. This package provides a clean, intuitive API for building prompt pipelines with full type safety and modern Python features.

Features

  • 🔒 Full type safety with generics and Pydantic models
  • 🔗 Chain-style API for building pipelines
  • 🎨 Decorator support for clean prompt definitions
  • 📦 Context sharing between prompts
  • 🔄 Automatic dependency handling between prompts
  • ⚡ Modern Python features and best practices

Installation

pip install prompt-pipeline

Quick Start

Here's a simple example of using the pipeline:

from pydantic import BaseModel
from prompt_pipeline import PromptPipeline

# Define your models
class TranslatorContext(BaseModel):
    source_text: str
    target_language: str

class ContextModel(BaseModel):
    context: str

class TranslationModel(BaseModel):
    translation: str

# Chain-style API
pipeline = (
    PromptPipeline[TranslatorContext, TranslationModel]()
    .add_prompt(
        "Analyze the context of this text: {context.source_text}",
        output_model=ContextModel,
        name="context"
    )
    .add_prompt(
        "Translate this text to {context.target_language} using the context: {prev.context}",
        output_model=TranslationModel,
        name="translate",
        depends_on="context"
    )
)

# Execute the pipeline
result = pipeline.execute(TranslatorContext(
    source_text="Hello, world!",
    target_language="Spanish"
))

Decorator Style

You can also use decorators for a more declarative style:

from prompt_pipeline import PromptPipeline, prompt

class TranslationPipeline(PromptPipeline[TranslatorContext, TranslationModel]):
    @prompt(output_model=ContextModel)
    def get_context(self, context: TranslatorContext) -> ContextModel:
        """
        Analyze the context of this text: {context.source_text}
        Consider the target language: {context.target_language}
        """
        pass
    
    @prompt(output_model=TranslationModel, depends_on="get_context")
    def translate(self, context: TranslatorContext) -> TranslationModel:
        """
        Translate this text to {context.target_language}
        Using the context: {prev.context}
        """
        pass

# Use the pipeline
pipeline = TranslationPipeline()
result = pipeline.execute(context)

Advanced Features

Configuration

Configure prompts with specific parameters:

pipeline = (
    PromptPipeline()
    .add_prompt("Your prompt", output_model=YourModel)
    .model("gpt-4")
    .configure(
        temperature=0.7,
        max_tokens=100
    )
)

Context Variables

Share variables between prompts:

context = pipeline.context(
    text="Hello",
    language="Spanish"
)
context.set_var("style", "formal")

Single Prompt Execution

Execute a single prompt without building a pipeline:

result = pipeline.execute_single(
    "Translate {text} to {language}",
    output_model=TranslationModel
)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

prompt_pipeline-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

prompt_pipeline-0.1.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file prompt_pipeline-0.1.1.tar.gz.

File metadata

  • Download URL: prompt_pipeline-0.1.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for prompt_pipeline-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8f0355208f21d69aba8fde2f12dc39dd8272ccbd5be564a0f55683a6ec7d35bc
MD5 1842b59430067e59f3c139d5a663fd28
BLAKE2b-256 86c31198df88fd5099844b1350306b3e3bdaa02184c371aa6d1c6e3f361b9a4c

See more details on using hashes here.

File details

Details for the file prompt_pipeline-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prompt_pipeline-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d866c815cd169bab261f8fcdbd26aa51b94b65b3719ed0c08641e29744dc4d4e
MD5 e770a6e14cd7c14daf3071ee077136ee
BLAKE2b-256 59bd70a67035efba14959baaa269c7d3a25b8f38bc78be9504d85ff341b8f4d1

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