promptic
promptic is a lightweight, decorator-based Python library that simplifies the process of interacting with large language models (LLMs) using litellm. With promptic, you can effortlessly create prompts, handle input arguments, and receive structured outputs from LLMs, all in under 100 lines of code.
Installation
pip install promptic
Usage
Simple Prompt
from promptic import promptic
@promptic
def us_president(year):
"""Who was the President of the United States in {year}?"""
print(us_president(2000))
# The President of the United States in 2000 was Bill Clinton until January 20th, when George W. Bush was inaugurated as the 43rd President.
Structured Output with Pydantic
from pydantic import BaseModel
from promptic import promptic
class Capital(BaseModel):
country: str
capital: str
@promptic
def get_capital(country) -> Capital:
"""What's the capital of {country}?"""
print(get_capital("France"))
# country='France' capital='Paris'
Streaming Response (and litellm integration)
from promptic import promptic
@promptic(
# keyword args are passed to litellm.completion
stream=True,
model="claude-3-haiku-20240307",
)
def haiku(subject, adjective, verb) -> str:
"""Write a haiku about {subject} that is {adjective} and {verb}."""
print("".join(haiku("programming", "witty", "delights")))
# Bugs in the code taunt,
# Syntax errors abound, yet
# Caffeine fuels the fix.
Features
- Decorator-based API: Easily define prompts using function docstrings and decorate them with
@promptic. - Argument interpolation: Automatically interpolate function arguments into the prompt using
{argument_name}placeholders. - Pydantic model support: Specify the expected output structure using Pydantic models, and
prompticwill ensure the LLM's response conforms to the defined schema. - Streaming support: Receive LLM responses in real-time by setting
stream=Truewhen calling the decorated function. - Simplified LLM interaction: No need to remember the exact shape of the OpenAPI response object or other LLM-specific details. Thanks to litellm,
prompticabstracts away the complexities, allowing you to focus on defining prompts and receiving structured outputs.
Why promptic?
promptic is designed to be simple, functional, and robust, providing exactly what you need 90% of the time when working with LLMs. It eliminates the need to remember the specific shapes of OpenAPI response objects or other LLM-specific details, allowing you to focus on creating prompts and receiving structured outputs.
With its legible and concise codebase, promptic is easy to understand and extend. It leverages the power of litellm under the hood, ensuring compatibility with a wide range of LLMs.
License
promptic is open-source software licensed under the Apache License 2.0.
Metadata
Release files for promptic 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| promptic-0.1.4.tar.gz | 7.9 kB | Without provenance | Details for promptic-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptic-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for promptic-0.1.4-py2.py3-none-any.whl |
Total release size: 14.9 kB
Release files / promptic-0.1.4.tar.gz
| Download URL | promptic-0.1.4.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc747bfaa5075b44816d53c6ce091c5495e0761b2cb18c55ac5684d15e2b44ac
|
|
BLAKE2b-256 checksum How to use checksums |
cbf6364feab66856e699721766064eb04d25311e11a571227a707d8d6cf7e0ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.2
|
Release files / promptic-0.1.4-py2.py3-none-any.whl
| Download URL | promptic-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b3cb52e774794ba130e0e2a09be359d502eeb92455ab3e042f1effedc614268b
|
|
BLAKE2b-256 checksum How to use checksums |
970657d0d859076d70aa8b7ab96885497f0f7d17e7376d85aed9befacfe16a1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.32.2
|
Security for promptic 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.