Skip to main content

Prompt Functions ⚙️

prompt-functions aims to make it easy to build functions with LLMs that have structured I/O, and to move prompts out of the code into serialized and versioned formats.

Getting Started

1. Installation

Install the package using pip:

pip install prompt-functions

2. Setting Up Your First Function

Let's create a sentiment classification function:

Step 1: Create a directory named sentiment. Inside this directory, you need two files:

└─ sentiment
   ├── function_args.json
   ├── model_args.json
   └── template.txt

Step 2: Define your prompt template in template.txt:

Aalyze and determine whether the sentiment of the following sentence is positive, negative, or neutral.
Sentence:
{sentence}

Step 3: Set model paramters in model_args.json:

{
    "temperature": 0.0,
    "model": "gpt-3.5-turbo"
}

Step 4: Specify the function's output format in function_args.json:

{
    "function_name": "sentiment_classifier",
    "description": "Classify the sentiment of a sentence",
    "properties": {
        "thoughts": {
            "type": "string",
            "description": "Your thoughts when classifying sentiment of the given sentence."
        },
        "sentiment": {
            "type": "string",
            "enum": ["positive", "negative", "neutral"],
            "description": "The sentiment of the given sentence."
        }
    }
}

3. Using Your Prompt Function in Python

Here's how you can load and use your prompt function:

from prompt_functions import PromptFunction

# Load your function
sentiment = PromptFunction.from_dir("./sentiment/")

# Make a prediction
pred = sentiment(sentence="I am super happy!")

# Expected Output:
# {
#   "thoughts": "The sentiment in the sentence is positive",
#   "sentiment": "positive"
# }

Prompt Versioning

Coming up..

Metadata

Release files for prompt-functions 0.1.27

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prompt-functions 0.1.27
File Size Uploaded Provenance
prompt_functions-0.1.27.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for prompt-functions 0.1.27
File Interpreter ABI Platform
prompt_functions-0.1.27-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / prompt_functions-0.1.27.tar.gz

Download URL prompt_functions-0.1.27.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dbdc0bef422a7d72d4c1f70f721384243a9cf2626ec94165b449649cba9e1d16
BLAKE2b-256 checksum
How to use checksums
1432422e6b5e43a164698c3aca26a3c204a30783393f5d2d43292fdfeb541e73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.6 Darwin/22.4.0

Release files / prompt_functions-0.1.27-py3-none-any.whl

Download URL prompt_functions-0.1.27-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b1b064cd35e7526d46cdeba7aba989baa9c8e0ab89933d364f5c953cb9dc86c
BLAKE2b-256 checksum
How to use checksums
6ea31568b7c961188060d57126b2d0b154c79272ae550bf5a985b22df55b56ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.6 Darwin/22.4.0

Security for prompt-functions 0.1.27

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page