Functools for OpenAI GPT Functions
OpenAI just released GPT Functions: https://openai.com/blog/function-calling-and-other-api-updates
But it's really cumbersome to make the actual function signature. And manually parse results and chain the calls:
curl https://api.openai.com/v1/chat/completions -u :$OPENAI_API_KEY -H 'Content-Type: application/json' -d '{
"model": "gpt-3.5-turbo-0613",
"messages": [
{"role": "user", "content": "What is the weather like in Boston?"}
],
"functions": [
{
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
]
}'
Use aifunctools instead
Instead, aifunctools automatically parses available python type annotations and docstrings so you don't have to do all of the manual work:
from aifunctools.openai_funcs import complete_with_functions
def get_current_weather(location: str, unit: str) -> dict:
"""
Get the current weather in a given location
:param location: The city and state, e.g. San Francisco, CA
:param unit: Either "celsius" or "fahrenheit"
:return: the current temperature, unit, and a description
"""
return {"temperature": 22, "unit": "celsius", "description": "Sunny"}
resp = complete_with_functions("What is the weather like in Boston?",
get_current_weather)
# The response should contain: "The weather in Boston is currently sunny with a temperature of 22 degrees Celsius."
What's next
OpenAPI Specs
Python functions are great, but what would really be great is to parse openapi specs from remote services. Imagine where every service provider makes their api spec available and agents can just crawl these APIs and use aifunctools to chain them together.
Richer types
For this hack we only support the basic string / number / boolean types. By making this more flexible we can get much richer behavior.
Error handling
I'm sure there are lots of cases where incomplete docstrings and type signatures will cause errors. We can make these more robust (or use some reasonable defaults).
Metadata
Release files for aifunctools 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aifunctools-0.1.2.tar.gz | 15.3 kB | Without provenance | Details for aifunctools-0.1.2.tar.gz |
Release files / aifunctools-0.1.2.tar.gz
| Download URL | aifunctools-0.1.2.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a721745670d35417e843080d2a17dfe1a29a9aa54e9874052f5f5aa75868210c
|
|
BLAKE2b-256 checksum How to use checksums |
cf217f1ad5a605d1ae7ba460efc16a1da10a8252b759ac215771261f0f61a31f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for aifunctools 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.