A small library to call local functions using openai function calling
Project description
ActionAI
A small library to run local functions using the openai function calling
Warning This library is still in its early stages, so please use it cautiously. If you find any bugs, please create a new issue.
Install
pip install actionai
Usage
Note A function must be fully typed and must have a docstring
# define a new function
def get_current_weather(location: str, unit: str = "fahrenheit"):
"""Function to get current weather for the given location"""
weather_info = {
"location": location,
"temperature": "72",
"unit": unit,
"forecast": ["sunny", "windy"],
}
return weather_info
import actionai
action = actionai.ActionAI()
action.register(get_current_weather)
response = action.prompt("What is the current weather in the north pole?")
print(response["choices"][0]["message"]["content"])
# The current weather at the North Pole is 72°F. It is sunny and windy.
The openai api key will be read automatically from the OPENAI_API_KEY environment variable. You can pass it manually as,
import actionai
action = actionai.ActionAI(openai_api_key="YOUR_KEY")
Adding context
Sometimes your function will have variables that need to be set by the program.
def list_todos(user: str):
"""Function to list all todos"""
return todos[user]
action = actionai.ActionAI(context={"user": "jason"})
The context keys are skipped when creating json schema. The values are directly passed at the time of the function call.
Choosing a model
By default, the completion run on the gpt-3.5-turbo-0613 model. You can change the model using the model argument.
import actionai
action = actionai.ActionAI(model="gpt-4")
You can see the complete list of supported chat completion models here
Demo
Running todo example 👇🏻
For more examples, check out the examples directory.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file actionai-0.0.7.tar.gz.
File metadata
- Download URL: actionai-0.0.7.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.10 Darwin/22.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c19f95c272fef2567c87d02966492d33a7f28ed0da59ddd85f3559f4b6e6144b
|
|
| MD5 |
86e6507aa928be4e725921721b729b20
|
|
| BLAKE2b-256 |
a41fb753f6e634cb8d879770a43559fe73d134ce5a3d48ca26d022fd5adc1fd7
|
File details
Details for the file actionai-0.0.7-py3-none-any.whl.
File metadata
- Download URL: actionai-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.10 Darwin/22.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae4e8e892a8424f5ad7483e86710dce43825d09df696780f68724d2e9bad629c
|
|
| MD5 |
0161afd9a2f0519031760610fe61dd5c
|
|
| BLAKE2b-256 |
374de9add6f05101a4651b26dff6af969222597e6d182ec9f53c67db3b3d0164
|