Skip to main content

autofunc

Easily define Python functions for structured output from GPT-4.

⚠️ 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

Metadata

Release files for autofunc 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autofunc 0.1.0
File Size Uploaded
autofunc-0.1.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autofunc 0.1.0
File Interpreter ABI Platform
autofunc-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 kB

Release files / autofunc-0.1.0.tar.gz

Download URL autofunc-0.1.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
60ec5a986808cad7bc1263ffdeb2688805b1f1fd33be92d0a2df0c502ea7fc04
BLAKE2b-256 checksum
How to use checksums
2ad3321c1aaa6b1ffe1db2b1b50f808e0e649af38963b3d1e574d0d61060625c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / autofunc-0.1.0-py3-none-any.whl

Download URL autofunc-0.1.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e82e3ac40627ea76836bedfccbbc669beb2135dc60851d3a10b355fe83d2610
BLAKE2b-256 checksum
How to use checksums
d1a60fa4b26796581897ddb57652ef17de69ffe93d6f03a43487fdfbe066a065
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page