| Name | ai-functions JSON |
| Version |
0.4.3
JSON |
| download |
| home_page | |
| Summary | manage openai functions and execution |
| upload_time | 2023-08-01 19:28:13 |
| maintainer | |
| docs_url | None |
| author | erik aronesty |
| requires_python | >=3.9,<4.0 |
| license | MIT |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Python AI Functions
Simple library that can convert from python functions to a JSON schema description of those functions, suitable for use with AI libraries.
## Installation
`pip install ai-functions`
## Usage
For example:
```
from ai_functions import get_openai_functions, execute_function
def search_web(query: Annotated[str, "google formatted keywords to search for"]):
"""Search the web"""
print(openai_function_dict([search_web]))
```
Also, if you get a `response.function_call` from openai, you can use `execute_function`
```
openai_function_execute([search_web], function_call)
```
Or, if you have the name and arguments split out already:
```
function_execute([search_web], name, arguments)
```
Finally, if you want a container to handle this:
```
from ai_functions import AIFunctions
container = AIFunctions([search_web, add_calendar_entry])
functions = container.openai_dict()
subset_functions = container.openai_dict(["search_web"])
container.execute("search_web", {"query":"top web hosting sites"})
container.opeanai_execute({"name": "search_web", "arguments": "{\"query\":\"top web hosting sites\"}")
```
## What stuff does this handle?
- Converts your annotated schema into an appropriate prompt
- Handles converting arguments to JSON if they are specified as a string.
- Auto-casts arguments to the right types, if they aren't right.
- Raises errors that AI engines understand if returned as a function response, instead of errors with poor descriptions.
## Async execute
- If a loop is provided to the AIFunctions constructor, or to any execute calls, it will be used to schedule a coroutine.
- Async versions of execute are available, prefix all calls with `async_`
### Some fine print
If you want to have a paramter that is still seen as "valid", but isn't part of the schema, you can
annotate it with None as the description. But this is really an "enforcement" thing, and might not
belong in this library.
Dealing with context is a beast in chat apps, so more work here might be helpful.
For example, I use meta-functions that unlock others, to prevent context-bloat.
Might put that in another lib soon, or put it here.
Raw data
{
"_id": null,
"home_page": "",
"name": "ai-functions",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "erik aronesty",
"author_email": "erik@q32.com",
"download_url": "https://files.pythonhosted.org/packages/42/36/2d7f35fd94ab1e00e16dbff9e526f3d7b50f5ffcd43871369e8ce9dad0f9/ai_functions-0.4.3.tar.gz",
"platform": null,
"description": "# Python AI Functions\n\n\nSimple library that can convert from python functions to a JSON schema description of those functions, suitable for use with AI libraries.\n\n\n## Installation\n\n`pip install ai-functions`\n\n## Usage\n\nFor example:\n\n```\nfrom ai_functions import get_openai_functions, execute_function\n\n\ndef search_web(query: Annotated[str, \"google formatted keywords to search for\"]):\n \"\"\"Search the web\"\"\"\n\nprint(openai_function_dict([search_web]))\n```\n\n\nAlso, if you get a `response.function_call` from openai, you can use `execute_function`\n\n```\nopenai_function_execute([search_web], function_call)\n```\n\nOr, if you have the name and arguments split out already:\n\n```\nfunction_execute([search_web], name, arguments)\n```\n\nFinally, if you want a container to handle this:\n\n```\nfrom ai_functions import AIFunctions\n\n\ncontainer = AIFunctions([search_web, add_calendar_entry])\n\nfunctions = container.openai_dict()\nsubset_functions = container.openai_dict([\"search_web\"])\ncontainer.execute(\"search_web\", {\"query\":\"top web hosting sites\"})\ncontainer.opeanai_execute({\"name\": \"search_web\", \"arguments\": \"{\\\"query\\\":\\\"top web hosting sites\\\"}\")\n\n```\n## What stuff does this handle?\n\n - Converts your annotated schema into an appropriate prompt \n - Handles converting arguments to JSON if they are specified as a string.\n - Auto-casts arguments to the right types, if they aren't right.\n - Raises errors that AI engines understand if returned as a function response, instead of errors with poor descriptions.\n\n## Async execute\n - If a loop is provided to the AIFunctions constructor, or to any execute calls, it will be used to schedule a coroutine.\n - Async versions of execute are available, prefix all calls with `async_`\n\n\n### Some fine print\n\nIf you want to have a paramter that is still seen as \"valid\", but isn't part of the schema, you can \nannotate it with None as the description. But this is really an \"enforcement\" thing, and might not\nbelong in this library.\n\nDealing with context is a beast in chat apps, so more work here might be helpful.\n\nFor example, I use meta-functions that unlock others, to prevent context-bloat. \n\nMight put that in another lib soon, or put it here.\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "manage openai functions and execution",
"version": "0.4.3",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8ee619c2f204cee281304374f007a5767796c485132a331fade5b3ee7562f84f",
"md5": "f03e1b25789e169e34392907537d6a1b",
"sha256": "31cabc3d2f3ce4095c4552ce9abbfde12ee2ce4fc74c412fee283bb6e248259f"
},
"downloads": -1,
"filename": "ai_functions-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f03e1b25789e169e34392907537d6a1b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 4238,
"upload_time": "2023-08-01T19:28:11",
"upload_time_iso_8601": "2023-08-01T19:28:11.779480Z",
"url": "https://files.pythonhosted.org/packages/8e/e6/19c2f204cee281304374f007a5767796c485132a331fade5b3ee7562f84f/ai_functions-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "42362d7f35fd94ab1e00e16dbff9e526f3d7b50f5ffcd43871369e8ce9dad0f9",
"md5": "8d00b6ce4a39762e62ac6c1ee8e9828a",
"sha256": "7becafbaf33a12cc000be172281d8d1c4686af01cd77e61076545216b44007d2"
},
"downloads": -1,
"filename": "ai_functions-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "8d00b6ce4a39762e62ac6c1ee8e9828a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 3852,
"upload_time": "2023-08-01T19:28:13",
"upload_time_iso_8601": "2023-08-01T19:28:13.175317Z",
"url": "https://files.pythonhosted.org/packages/42/36/2d7f35fd94ab1e00e16dbff9e526f3d7b50f5ffcd43871369e8ce9dad0f9/ai_functions-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-01 19:28:13",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ai-functions"
}