Build semantic functions.
Project description
Prompt Functions ⚙️
Easily define custom prompt functions with structured input and output.
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..
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
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_functions-0.1.22.tar.gz.
File metadata
- Download URL: prompt_functions-0.1.22.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/22.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71446ed818eedf9967f6f47e1fdd317a100407ebfe840357688cc4bc2a521d6a
|
|
| MD5 |
91258e8daae8c29d9ad55df99f916c5b
|
|
| BLAKE2b-256 |
743ced91f311dc24383bc98acff9d3e8965a046879c1b36ecef37f5720521cc7
|
File details
Details for the file prompt_functions-0.1.22-py3-none-any.whl.
File metadata
- Download URL: prompt_functions-0.1.22-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/22.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1597dc70ad832c46199da4553ce7f240fc2cf9595c8f0f8c67097d0efece575c
|
|
| MD5 |
4e67a1db323ba40bc39ad61ec37d7951
|
|
| BLAKE2b-256 |
b34da0f16dc5c240aa30195eff892e1e373b79399802c4280d0e299023504b5d
|