Skip to main content

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)

Uploaded Source

Built Distribution

llm_functions-0.1.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page