Build semantic functions.
Project description
LLM Functions
Define custom LLM functions with minimal code.
How to install
pip install llm-functions
How to build a sentiment classifier with llm-functions
Here is an example of a directory with files that defines a simple sentiment classification function.
└─ sentiment
├── args.json
└── template.txt
The content of template.txt
:
Aalyze and determine whether the sentiment of the following sentence is positive, negative, or neutral.
Sentence:
{sentence}
The content of args.json
:
{
"temperature": 0.0,
"model": "gpt-3.5-turbo",
"function_name": "sentiment_classifier",
"description": "Classify the sentiment of a sentence",
"properties": {
"rationale": {
"type": "string",
"description": "Your rationale when classifying sentiment of the given sentence."
},
"sentiment": {
"type": "string",
"enum": ["positive", "negative", "neutral"],
"description": "The sentiment of the given sentence."
}
}
}
Load the LLM function:
from llm_functions import LLMFunction
sentiment = LLMFunction.from_dir("sentiment/")
pred = sentiment(sentence="I am super happy!")
# 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.1.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for llm_functions-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bac0fda972d990c0c30ab55f01b88f6cd56576040ce7f52493ee8578401ada8 |
|
MD5 | bdc1ddd6ea985dd6fddf3ff4903705e5 |
|
BLAKE2b-256 | cee9795f6123303c28291c451c4e587c626b3d0abf0816e2444c5657ec52b79a |