autofns


Nameautofns JSON
Version 0.1.7 PyPI version JSON
download
home_pagehttps://github.com/rhymiz/autofns
SummaryAutoFNS is a utility for automatically calling functions when interacting with the OpenAI Completions.
upload_time2023-12-27 23:46:46
maintainer
docs_urlNone
authorLemuel Boyce
requires_python>=3.10,<4.0
licenseMIT
keywords ai openai gpt-3 gpt-4 functions chat completions utility autofns
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # AutoFNS

## Introduction

AutoFNS is a wrapper around OpenAI's Chat Completion API. 

It allows you to define functions as you normally would, and have them be called
automatically when a message containing tool calls is detected. This allows you to focus on
more important things, like the logic of your application.

Note: 🧪 This is a work in progress and may not be ready for production use.

## Requirements

- python >= 3.10
- openai

## Installation

```bash
pip install autofns
```

## Usage

```python
from autofns import AutoFNS

FUNCTION_DEFINITIONS = [
    {
        "type": "function",
        "function": {
            "name": "get_temp_units",
            "description": "Get a list of temperature units",
        }
    },
    {
        "type": "function",
        "function": {
            "name": "get_current_temperature",
            "description": "Get the current temperature in a city",
        },
        "parameters": {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string",
                    "description": "The city to get the temperature of",
                },
                "unit": {
                    "type": "string",
                    "description": "The unit to get the temperature in",
                    "enum": ["Fahrenheit", "Celsius", "Kelvin"],
                }
            },
            "required": ["city", "unit"],
        }
    },
]


def get_temp_units():
    return ["Fahrenheit", "Celsius", "Kelvin"]


def get_current_temperature(city: str, unit: str):
    return "The current temperature in {} is {} degrees {}".format(
        city, 72, unit
    )


fns = AutoFNS(
    "gpt-4-32k",
    fns_mapping={
        "get_temp_units": get_temp_units,
        "get_current_temperature": get_current_temperature
    },
    fns_definitions=FUNCTION_DEFINITIONS,
)

result = fns.create_completion(messages=[...])
```


You can also use the `AutoFNSAsync` class to use async functions:

```python
from autofns import AutoFNSAsync

fns = AutoFNSAsync(...)

result = await fns.create_completion(messages=[...])
```

## License
This project is licensed under the terms of the MIT license.

## Contributing
Contributions are welcome! Please open an issue or a pull request.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rhymiz/autofns",
    "name": "autofns",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "ai,openai,gpt-3,gpt-4,functions,chat completions,utility,autofns",
    "author": "Lemuel Boyce",
    "author_email": "lemuelboyce@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dd/2e/a50aa0cfadc44ab9d9c0f91fdd81801048dc2ea49a758849dfb857200303/autofns-0.1.7.tar.gz",
    "platform": null,
    "description": "# AutoFNS\n\n## Introduction\n\nAutoFNS is a wrapper around OpenAI's Chat Completion API. \n\nIt allows you to define functions as you normally would, and have them be called\nautomatically when a message containing tool calls is detected. This allows you to focus on\nmore important things, like the logic of your application.\n\nNote: \ud83e\uddea This is a work in progress and may not be ready for production use.\n\n## Requirements\n\n- python >= 3.10\n- openai\n\n## Installation\n\n```bash\npip install autofns\n```\n\n## Usage\n\n```python\nfrom autofns import AutoFNS\n\nFUNCTION_DEFINITIONS = [\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_temp_units\",\n            \"description\": \"Get a list of temperature units\",\n        }\n    },\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_current_temperature\",\n            \"description\": \"Get the current temperature in a city\",\n        },\n        \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"city\": {\n                    \"type\": \"string\",\n                    \"description\": \"The city to get the temperature of\",\n                },\n                \"unit\": {\n                    \"type\": \"string\",\n                    \"description\": \"The unit to get the temperature in\",\n                    \"enum\": [\"Fahrenheit\", \"Celsius\", \"Kelvin\"],\n                }\n            },\n            \"required\": [\"city\", \"unit\"],\n        }\n    },\n]\n\n\ndef get_temp_units():\n    return [\"Fahrenheit\", \"Celsius\", \"Kelvin\"]\n\n\ndef get_current_temperature(city: str, unit: str):\n    return \"The current temperature in {} is {} degrees {}\".format(\n        city, 72, unit\n    )\n\n\nfns = AutoFNS(\n    \"gpt-4-32k\",\n    fns_mapping={\n        \"get_temp_units\": get_temp_units,\n        \"get_current_temperature\": get_current_temperature\n    },\n    fns_definitions=FUNCTION_DEFINITIONS,\n)\n\nresult = fns.create_completion(messages=[...])\n```\n\n\nYou can also use the `AutoFNSAsync` class to use async functions:\n\n```python\nfrom autofns import AutoFNSAsync\n\nfns = AutoFNSAsync(...)\n\nresult = await fns.create_completion(messages=[...])\n```\n\n## License\nThis project is licensed under the terms of the MIT license.\n\n## Contributing\nContributions are welcome! Please open an issue or a pull request.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "AutoFNS is a utility for automatically calling functions when interacting with the OpenAI Completions.",
    "version": "0.1.7",
    "project_urls": {
        "Homepage": "https://github.com/rhymiz/autofns",
        "Repository": "https://github.com/rhymiz/autofns"
    },
    "split_keywords": [
        "ai",
        "openai",
        "gpt-3",
        "gpt-4",
        "functions",
        "chat completions",
        "utility",
        "autofns"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f3ed69e93849163f6239b1a0e3d7fdcf90fee136be1b80b872b5f3165a1714c",
                "md5": "b2c82b393a0097f84c0dc3269d463a09",
                "sha256": "c6f1d2a1947a35680738a2cd04a0ba2a658ccdad6bf028f6011e031bfdf0228c"
            },
            "downloads": -1,
            "filename": "autofns-0.1.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2c82b393a0097f84c0dc3269d463a09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 4400,
            "upload_time": "2023-12-27T23:46:44",
            "upload_time_iso_8601": "2023-12-27T23:46:44.836160Z",
            "url": "https://files.pythonhosted.org/packages/3f/3e/d69e93849163f6239b1a0e3d7fdcf90fee136be1b80b872b5f3165a1714c/autofns-0.1.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dd2ea50aa0cfadc44ab9d9c0f91fdd81801048dc2ea49a758849dfb857200303",
                "md5": "432fae7ade67133eb6bf48d80f95cb7d",
                "sha256": "0a7ab25a77787c4f91dab2a39844170cf9a018465f73f06f01077979eb0b9e62"
            },
            "downloads": -1,
            "filename": "autofns-0.1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "432fae7ade67133eb6bf48d80f95cb7d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 3995,
            "upload_time": "2023-12-27T23:46:46",
            "upload_time_iso_8601": "2023-12-27T23:46:46.513620Z",
            "url": "https://files.pythonhosted.org/packages/dd/2e/a50aa0cfadc44ab9d9c0f91fdd81801048dc2ea49a758849dfb857200303/autofns-0.1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-27 23:46:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rhymiz",
    "github_project": "autofns",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "autofns"
}
        
Elapsed time: 0.16893s