GPTConnect is a Python
package that simplifies the use of the new functions feature. It provides an easy-to-use framework for creating and interacting with GPT functions.
This package is in somewhat early stages of development, I'd appreciate your suggestions and feedback!
Example Usage:
import os
from gptconnect import GPTConnect, GPTFunction, GPTFunctionHandler
import requests
import dotenv
dotenv.load_dotenv()
ai = GPTConnect(token=os.environ.get("TOKEN"), model="gpt-3.5-turbo-0613")
@GPTFunctionHandler()
def custom_function_handler(function, args):
# Please make sure to update or remove this code when adding new functions
if function.__name__ == "ping_hostname":
return function(args)
else:
return "The function called is invalid. Please let the user know this operation failed."
# Decorator based defining system
@GPTFunction(
group="general_commands",
description="Ping a hostname",
params={
"type": "object",
"properties": {
"hostname": {
"type": "string",
"description": "The hostname to ping",
},
},
"required": ["hostname"],
},
)
def ping_hostname(args: dict) -> str:
print(f"Pinging hostname {args.get('hostname')}...")
url = f"https://{args.get('hostname')}"
response = requests.get(url)
return f"Response code: {response.status_code}"
print(ai.call(prompt="Ping the hostname github.com", function_group="general_commands"))
# Output:
# Pinging hostname github.com...
# {
# 'content': 'The hostname "github.com" was successfully pinged with a response code of 200.',
# 'function_called': 'ping_hostname'
# }
Github Repo: https://github.com/SleepyStew/gptconnect
(I'd appreciate a star ✨ if you find this project helpful)
PyPI: https://pypi.org/project/GPTConnect/