AutoFNS
Introduction
AutoFNS is a utility for automatically calling functions when interacting with OpenAI Completions API.
Note: This is a work in progress and may not be ready for production use. If you find any bugs or have any suggestions, please open an issue or a pull request.
Requirements
- python >= 3.10
- openai
- regex
Installation
pip install autofns
Usage
from autofns import AutoFNS
FUNCTION_DEFINITIONS = [
{
"type": "function",
"function": {
"name": "get_temp_units",
"description": "Get a list of temperature units",
}
},
{
"type": "function",
"function": {
"name": "get_current_temperature",
"description": "Get the current temperature in a city",
},
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city to get the temperature of",
},
"unit": {
"type": "string",
"description": "The unit to get the temperature in",
"enum": ["Fahrenheit", "Celsius", "Kelvin"],
}
},
"required": ["city", "unit"],
}
},
]
def get_temp_units():
return ["Fahrenheit", "Celsius", "Kelvin"]
def get_current_temperature(city: str, unit: str):
return "The current temperature in {} is {} degrees {}".format(
city, 72, unit
)
fns = AutoFNS(
"gpt-4-32k",
fns_mapping={
"get_temp_units": get_temp_units,
"get_current_temperature": get_current_temperature
},
fns_definitions=FUNCTION_DEFINITIONS,
)
result = fns.create_completion(messages=[...])
You can also use the @fns.map_function decorator to add a function to
AutoFNS internal mapping:
from autofns import AutoFNS
fns = AutoFNS(...)
@fns.map_function # can also pass a name to map_function
def get_temp_units():
return ["Fahrenheit", "Celsius", "Kelvin"]
You can also use the AutoFNSAsync class to use async functions:
from autofns import AutoFNSAsync
fns = AutoFNSAsync(...)
result = await fns.create_completion(messages=[...])
Metadata
Release files for autofns 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autofns-0.1.6.tar.gz | 2.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autofns-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.2 kB
Release files / autofns-0.1.6.tar.gz
| Download URL | autofns-0.1.6.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d78dc36a02ad100daaa84ae78ceb73fc80d368dda9b1d85423e56094a636e9d3
|
|
BLAKE2b-256 checksum How to use checksums |
19f1d483c572326e7fbc6f321a66fd68e468ac6a36347522e131b883fd23f3da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / autofns-0.1.6-py3-none-any.whl
| Download URL | autofns-0.1.6-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f849526d6235174fe3c12afbd49ba4a5efca7ca0e1dd6a6b31aeff313a4ba2f8
|
|
BLAKE2b-256 checksum How to use checksums |
310cf905398207967ca4cf3df28e752222b11ad5c4ed1d09363af719ed4a5bfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|