Build semantic functions.
Project description
LLM Functions
Define custom LLM functions with minimal code.
How to Define a LLM Function
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.0.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for llm_functions-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71206a5bc50c7b8656e955fd09ca8edbfe03d5ba0260ee602fb69791436c4f5d |
|
MD5 | 4755537c2b7828f4f716cd4e76984223 |
|
BLAKE2b-256 | 0dc2575aeeda9218af87a895120242a81e0f178d19db5efb420a09f60dd0b955 |