manage openai functions and execution
Project description
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.
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\"}")
It handles converting arguments to JSON if they are specified as a string.
It auto-casts arguments to the right types, if they aren't right.
It returns errors that AI engines understands, instead of errors with poor descriptions.
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_
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
Built Distribution
Hashes for ai_functions-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baab96f2ff2bdeeb84488cc85691b3c87b18a0c4ecf215cdce1ba81320de57ea |
|
MD5 | 5a0830a4b8610ceaeae060e088d49f6d |
|
BLAKE2b-256 | f8ff8a6c14517d9c1d760d69a3980ab4ae000bb5b8bbef2c5cf87cb2cf1f0bb6 |