Skip to main content

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_

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.1.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_functions-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_functions-0.1.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ai_functions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fbdce75308ff62076241b697513463ae151639d3724d4727cb452b67e0a4bfec
MD5 1cd4512d7ce5cddb90c9f49e20fd492a
BLAKE2b-256 96862a0143d5fcfc3fd2021bedd6aa8eb3883c99901466cba19abf5bdc6bde52

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ai_functions-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ai_functions-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09c1e104f114f81f1e31a1e29b816538ab0f1e1d03368243ae28ae042131826e
MD5 11d9c2ba6e96b323273d020b9a309ef9
BLAKE2b-256 3989b6f68a08c30d220dbed06588822e083469abf3171107e14853aef22f7c2d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.3

2 files

0.4.2

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page