Skip to main content

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

ai_functions-0.4.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

ai_functions-0.4.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file ai_functions-0.4.0.tar.gz.

File metadata

  • Download URL: ai_functions-0.4.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Windows/10

File hashes

Hashes for ai_functions-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6f3f4c395ca2ea49972b93c061c73a34e8112c2488395dcc4e561ea04778e903
MD5 7cb8b72e179ce6ef738f4de6e1ac8bfc
BLAKE2b-256 85e14e733227237eeac3fe6ce305b180db77882c54c96f3e4cbe881f424b2978

See more details on using hashes here.

File details

Details for the file ai_functions-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: ai_functions-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Windows/10

File hashes

Hashes for ai_functions-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6110372a6eca8f10ca8cd9f9de2ea6f8dc8d893589ea5dcc63f809b2ec9355ec
MD5 cff493ba8a98d95df1b7e7b0cb03dfab
BLAKE2b-256 3d1224aa7e08a717c18b825fe62e5758518a7fa9fde6b076a8a9093290e17b03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page