Build semantic functions.
Project description
LLM Functions ⚙️
Easily define custom LLM (Language Learning Model) functions with structured input and output.
Getting Started
1. Installation
Install the package using pip:
pip install llm-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 LLM Function in Python
Here's how you can load and use your LLM function:
from llm_functions import LLMFunction
# Load your function
sentiment = LLMFunction.from_dir("./sentiment/")
# Make a prediction
pred = sentiment(sentence="I am super happy!")
# Expected Output:
# {
# "rationale": "The sentiment in the sentence is positive",
# "sentiment": "positive"
# }
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
llm_functions-0.1.2.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for llm_functions-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb39e0c33526c84f4a7f3a22726ad15eb124727e904c8cddc7e6dd7ea22d6bb7 |
|
MD5 | 661c6bd92ccfb4a3f6fbe96691cf4009 |
|
BLAKE2b-256 | cef4fb6b111f90d671f7655fce9be0ae7cb4e0c7ad95fd7bc72ad7ac55273a37 |