CallingGPT
GPT's Function Calling Demo, a experiment of self-hosted ChatGPT-Plugins-like platform.
Recommend reading: function-calling
Abstract
OpenAI's GPT models provide a function calling feature, so we can easily create ChatGPT-Plugins-like tools. This repository is a proof-of-concept of the function calling feature.
In this experiment, we defined the Plugin as Namespace which contains a serial of functions. While user performing a conversation, the functions in Namespace will be called by the API and return the result to the user.
Usage
-
Clone this repository and install the dependencies.
git clone https://github.com/RockChinQ/CallingGPT cd CallingGPT pip install -r requirements.txt
-
Run the
main.pyto generateconfig.yamlpython main.py -
Edit the
config.yamlto set your API key and other settings. -
Run the
main.pyand pass your modules.python main.py <module0> <module1> ...
Example
Use the example/greet.py, provides a greet function called when user ask GPT to greet someone.
python main.py example/greet.py
Then you can talk to the bot.
$ python main.py examples/greet.py
Using module: examples.greet
>>> Hello and who are you?
<<< Hello! I am an AI assistant. How can I assist you today?
>>> say hello to Rock
call<examples-greet-greet>: {
"user": "Rock"
}
<<< Hello, Rock! How can I assist you today?
>>> and to Alice
call<examples-greet-greet>: {
"user": "Alice"
}
<<< Hello, Alice! How can I assist you today?
>>>
Type help to get help.
See wiki for the function format.
Other Examples
examples/draw_and_wrapper_md.py
Provides a dalle_draw function to use DALL·E model when user ask GPT to draw something.
python main.py examples/draw_and_wrapper_md.py
$ python main.py examples/draw_and_wrapper_md.py
Using module: examples.draw_and_wrapper_md
>>> hello!
<<< Hi there! How can I assist you today?
>>> draw a sunset for me please
call<examples-draw_and_wrapper_md-draw>: {
"prompt": "sunset"
}
<<< Sure! Here's a beautiful sunset for you:

I hope you like it! Let me know if there's anything else I can help you with.
>>>
For Code
-
Install the package
pip install --upgrade CallingGPT
-
Create your own functions in modules(these modules can also be used in the CLI mode)
# your_module_a.py def func_a(prompt: str) -> str: # Type hint of EACH argument and return value is REQUIRED. """ The description of this func a, will be provided to the api. Args: prompt(str): The prompt of the function. Returns: The result of the function. """ # Google style docstring is REQUIRED, it will be split into # `description` and `params`(required if there are args) and # `returns`(optional), `\n\n` between each part. return "func_a: " + prompt
# your_module_b.py def adder(a: int, b: int) -> int: """ Add two numbers. Args: a: The first number. b: The second number. Returns: The sum of a and b. """ # Type hints of args in docstring is optional. return a + b
-
Call the wrapper
from CallingGPT.session.session import Session import your_module_a, your_module_b import openai openai.api_key = 'your_openai_api_key' session = Session([your_module_a, your_module_b]) for reply in session.ask("your prompt"): # session.ask will yield each time the api returns a result, # before calling function, it will print the function name and args. # e.g. here's a function call: # { # "role": "assistant", # "content": null, # "function_call": { # "name": "examples-draw_and_wrapper_md-draw", # "arguments": "{\n \"prompt\": \"cat\"\n}" # } # } # # while here's a normal reply: # { # "role": "assistant", # "content": "Hello, I am an AI assistant. How can I assist you today?" # } print(reply)
Sessionwill automatically manage context for you.
See wiki for the function format.
Metadata
Release files for CallingGPT 0.0.1.0
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 |
|---|---|---|---|---|
| CallingGPT-0.0.1.0.tar.gz | 8.4 kB | Without provenance | Details for CallingGPT-0.0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| CallingGPT-0.0.1.0-py3-none-any.whl | Python 3 | none | any | Details for CallingGPT-0.0.1.0-py3-none-any.whl |
Total release size: 15.6 kB
Release files / CallingGPT-0.0.1.0.tar.gz
| Download URL | CallingGPT-0.0.1.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7cd173d2bca7202b9fcb311342675dd2a5d409ccdb0f245dd1e6596a8bbabf2d
|
|
BLAKE2b-256 checksum How to use checksums |
0622a64557f5fe6b3db94f2aa899c566377a07c527345b08624f79c4e795b17e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Release files / CallingGPT-0.0.1.0-py3-none-any.whl
| Download URL | CallingGPT-0.0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d275cd667d20c29296d03ce81a8b2c0328b96528bd6d6da97e6dffd23c31608
|
|
BLAKE2b-256 checksum How to use checksums |
47f432bb0676a425afd1961018ce3432602d6a91b1616eca57ce02b478e47647
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.8
|
Security for CallingGPT 0.0.1.0
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.