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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prompt_pipeline-0.1.0.tar.gz.
File metadata
- Download URL: prompt_pipeline-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0812c1d0f420914e2bbe73378cb651fd9858c04a3a3a5410bd29ad7bda3bbdf
|
|
| MD5 |
02213b62758598d70cad4ab62b31a577
|
|
| BLAKE2b-256 |
241c978cca15ed7da8b8ee057d0b0f4eee6027949d603729472c3f3c0137656b
|
File details
Details for the file prompt_pipeline-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prompt_pipeline-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c880851a9b562b3a59b46346d8f610998272439c450606aaae94584699432a7
|
|
| MD5 |
cb1b6b91edbc7048c2bb3bdd2743ab84
|
|
| BLAKE2b-256 |
31d96bed869cce8935ca701b58931f5a186c128f257680123d861022827ce51a
|