Easily define python functions for structured LLM output
Project description
autofunc
Easily define Python functions for structured output from GPT-4.
:warning: This was primarily written for personal use, and is neither well-tested nor documented. There are similar and much better projects out there, such as magentic.
Install
pip install autofunc
Usage
Expects OPENAI_API_KEY
to be defined in your environment.
Define your function
from autofunc import AutoFunc
swap_animals = AutoFunc("Swap the animals in the sentence. Eg. The dog barked at the cat -> the cat meowed at the dog")
Call it
swap_animals("The tigers growled at each other until they saw the snakes slithering near the trees.")
'The snakes hissed at each other until they saw the tigers prowling near the trees.'
Use pydantic
for structured output
from pydantic import BaseModel, Field
class TravelDescription(BaseModel):
from_city: str = Field(description="City name including the country")
to_city: str = Field(description="City name including the country")
mode_of_travel: str = Field(description="eg. train or flight")
description: str = Field(description="A one-line description of a fictional journey, in the style of an adventure game. Simple present tense.")
duration: str
travel_fn = AutoFunc("Describe travelling between the two provided cities.", TravelDescription)
travel_fn("londres to paris")
{
'from_city': 'London, United Kingdom',
'to_city': 'Paris, France',
'mode_of_travel': 'train',
'description': 'You embark on a journey from the bustling city of London, crossing the English Channel through the Eurotunnel, to the romantic city of Paris.',
'duration': '2 hours 20 minutes'
}
CHANGES
2023.10.05: Initial release
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
autofunc-0.1.0.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file autofunc-0.1.0.tar.gz
.
File metadata
- Download URL: autofunc-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60ec5a986808cad7bc1263ffdeb2688805b1f1fd33be92d0a2df0c502ea7fc04 |
|
MD5 | 3a2f05854e0c9299df563181e194c0e0 |
|
BLAKE2b-256 | 2ad3321c1aaa6b1ffe1db2b1b50f808e0e649af38963b3d1e574d0d61060625c |
File details
Details for the file autofunc-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: autofunc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e82e3ac40627ea76836bedfccbbc669beb2135dc60851d3a10b355fe83d2610 |
|
MD5 | 14c8d8e76a4e3501a6a133a144a36f26 |
|
BLAKE2b-256 | d1a60fa4b26796581897ddb57652ef17de69ffe93d6f03a43487fdfbe066a065 |