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, receive structured outputs from LLMs, and enable function/tool calling capabilities with just a few lines of code.
Installation
pip install promptic
Usage
Simple Prompt
from promptic import llm
@llm
def president(year):
"""Who was the President of the United States in {year}?"""
print(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 llm
class Capital(BaseModel):
country: str
capital: str
@llm
def capital(country) -> Capital:
"""What's the capital of {country}?"""
print(capital("France"))
# country='France' capital='Paris'
Streaming Response (and litellm integration)
from promptic import llm
# most arguments are passed directly to litellm.completion
# see https://docs.litellm.ai/docs/completion
@llm(stream=True, model="claude-3-haiku-20240307")
def haiku(subject, adjective, verb="delights"):
"""Write a haiku about {subject} that is {adjective} and {verb}."""
print("".join(haiku("programming", adjective="witty")))
# Bits and bytes abound,
# Bugs and features intertwine,
# Code, the poet's rhyme.
Customize System Prompt
from promptic import llm
@llm(system="you are a snarky chatbot")
def answer(question):
"""{question}"""
print(answer("What's the best programming language?"))
# Well, that's like asking what's the best flavor of ice cream.
# It really depends on what you're trying to accomplish and your personal preferences.
# But if you want to start a flame war, just bring up Python vs JavaScript.
Agents
from promptic import llm
@llm(system="you are a posh smart home assistant named Jarvis")
def jarvis(command):
"""{command}"""
@jarvis.tool
def turn_light_on():
"""turn light on"""
return True
@jarvis.tool
def get_current_weather(location: str, unit: str = "fahrenheit"):
"""Get the current weather in a given location"""
return f"The weather in {location} is 45 degrees {unit}"
print(jarvis("Please turn the light on and check the weather in San Francisco"))
# Certainly, sir. I'll assist you with that right away.
# I've turned the light on for you. As for the weather in San Francisco,
# it is currently 45 degrees fahrenheit.
Features
- Decorator-based API: Easily define prompts using function docstrings and decorate them with
@promptic.llm. - Argument interpolation: Automatically interpolate function arguments into the prompt using
{argument_name}placeholders within docstrings. - 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.
prompticabstracts away the complexities, allowing you to focus on defining prompts and receiving structured outputs. - Seamlessly Build Agents: Decorate functions as tools that the LLM can use to perform actions or retrieve information.
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 reliable easy to understand. 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.8.2
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.8.2.tar.gz | 75.1 kB | With provenance | Details for promptic-0.8.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| promptic-0.8.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for promptic-0.8.2-py2.py3-none-any.whl |
Total release size: 84.0 kB
Release files / promptic-0.8.2.tar.gz
| Download URL | promptic-0.8.2.tar.gz |
|---|---|
| Size | 75.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db24f286f1e8ff24682c9dff130862d66aa49e42f453564370444a7ea7261ade
|
|
BLAKE2b-256 checksum How to use checksums |
0aae3059d957b0a5112c13f3569b8000cb4944d27b4d51df51b9b334000eed12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2024.
Transparency logRelease files / promptic-0.8.2-py2.py3-none-any.whl
| Download URL | promptic-0.8.2-py2.py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
ca9934dc905a388c57c5ee4554c2646a4ece31235b379c2be6edfee6de48810c
|
|
BLAKE2b-256 checksum How to use checksums |
de4de50061647b77aef4b96b7cb02b404088e8c20b71a5908c23e4f4a0c875ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2024.
Transparency logSecurity for promptic 0.8.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for promptic-0.8.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2024.
Transparency logA 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.