GPT's function calling feature wrapper
Project description
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.py
to generateconfig.yaml
python main.py
-
Edit the
config.yaml
to set your API key and other settings. -
Run the
main.py
and pass your modules.python main.py <module0> <module1> ...
Example
Use the example/greet.py
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 here to help you. How may I assist you today?
>>> say hello to Rock
func<examples.greet.greet>: Hello, Rock!
>>> and to Alice
func<examples.greet.greet>: Hello, Alice!
>>>
Type help
to get help.
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.apikey = 'your_openai_api_key' session = Session([your_module_a, your_module_b]) session.ask("your prompt")
Session
will automatically manage context for you.
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
Hashes for CallingGPT-0.0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb9a74df45e435d5f6a21594f543c0dc1eb7cbf24742a3a9c3255df5e01632ad |
|
MD5 | 8a4b26687143b2321e2d5c9af5c69de5 |
|
BLAKE2b-256 | 6144f6e132b1b413e1458aeb48443821ac901cb9d3c837721f6f99e8f856eb0d |