# 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](https://github.com/jackmpcollins/magentic).
## Install
```
pip install autofunc
```
## Usage
Expects `OPENAI_API_KEY` to be defined in your environment.
### Define your function
```python
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
```python
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
```python
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)
```
```python
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
Raw data
{
"_id": null,
"home_page": "https://github.com/nk412/autofunc",
"name": "autofunc",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Nagarjuna Kumarappan",
"author_email": "nagarjuna.412@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2a/d3/321c1aaa6b1ffe1db2b1b50f808e0e649af38963b3d1e574d0d61060625c/autofunc-0.1.0.tar.gz",
"platform": null,
"description": "# autofunc\n\nEasily define Python functions for structured output from GPT-4.\n\n: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](https://github.com/jackmpcollins/magentic).\n\n\n## Install\n\n```\npip install autofunc\n```\n\n## Usage\n\nExpects `OPENAI_API_KEY` to be defined in your environment.\n\n### Define your function\n\n```python\nfrom autofunc import AutoFunc\n\n\nswap_animals = AutoFunc(\"Swap the animals in the sentence. Eg. The dog barked at the cat -> the cat meowed at the dog\")\n```\n\n### Call it\n\n```python\nswap_animals(\"The tigers growled at each other until they saw the snakes slithering near the trees.\")\n\n'The snakes hissed at each other until they saw the tigers prowling near the trees.'\n```\n\n### Use `pydantic` for structured output\n\n```python\nfrom pydantic import BaseModel, Field\n\nclass TravelDescription(BaseModel):\n from_city: str = Field(description=\"City name including the country\")\n to_city: str = Field(description=\"City name including the country\")\n mode_of_travel: str = Field(description=\"eg. train or flight\")\n description: str = Field(description=\"A one-line description of a fictional journey, in the style of an adventure game. Simple present tense.\")\n duration: str\n\ntravel_fn = AutoFunc(\"Describe travelling between the two provided cities.\", TravelDescription)\n```\n\n```python\ntravel_fn(\"londres to paris\")\n\n{\n 'from_city': 'London, United Kingdom',\n 'to_city': 'Paris, France',\n 'mode_of_travel': 'train',\n '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.',\n 'duration': '2 hours 20 minutes'\n}\n```\n\nCHANGES\n=======\n\n2023.10.05: Initial release\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Easily define python functions for structured LLM output",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/nk412/autofunc"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d1a60fa4b26796581897ddb57652ef17de69ffe93d6f03a43487fdfbe066a065",
"md5": "14c8d8e76a4e3501a6a133a144a36f26",
"sha256": "4e82e3ac40627ea76836bedfccbbc669beb2135dc60851d3a10b355fe83d2610"
},
"downloads": -1,
"filename": "autofunc-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "14c8d8e76a4e3501a6a133a144a36f26",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3774,
"upload_time": "2024-02-26T17:45:43",
"upload_time_iso_8601": "2024-02-26T17:45:43.735754Z",
"url": "https://files.pythonhosted.org/packages/d1/a6/0fa4b26796581897ddb57652ef17de69ffe93d6f03a43487fdfbe066a065/autofunc-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2ad3321c1aaa6b1ffe1db2b1b50f808e0e649af38963b3d1e574d0d61060625c",
"md5": "3a2f05854e0c9299df563181e194c0e0",
"sha256": "60ec5a986808cad7bc1263ffdeb2688805b1f1fd33be92d0a2df0c502ea7fc04"
},
"downloads": -1,
"filename": "autofunc-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3a2f05854e0c9299df563181e194c0e0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4411,
"upload_time": "2024-02-26T17:45:45",
"upload_time_iso_8601": "2024-02-26T17:45:45.353967Z",
"url": "https://files.pythonhosted.org/packages/2a/d3/321c1aaa6b1ffe1db2b1b50f808e0e649af38963b3d1e574d0d61060625c/autofunc-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-26 17:45:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nk412",
"github_project": "autofunc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "autofunc"
}