mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
🔧 fix(functionscalls.py): fix typo in FunctionCallError class name
✨ feat(functionscalls.py): add call_function function to handle function calls with name and arguments 🔧 fix(makeprompt.py): remove individual function imports from functionscalls and use call_function instead
This commit is contained in:
@@ -299,6 +299,17 @@ async def send_ascii_art_image(
|
|||||||
await message_in_channel_in_wich_to_send.channel.send(message)
|
await message_in_channel_in_wich_to_send.channel.send(message)
|
||||||
|
|
||||||
|
|
||||||
|
async def call_function(message: discord.Message, function_call):
|
||||||
|
name = function_call.get("name", "")
|
||||||
|
if name == "":
|
||||||
|
raise FuntionCallError("No name provided")
|
||||||
|
arguments = function_call.get("arguments", {})
|
||||||
|
if name not in functions_matching:
|
||||||
|
raise FuntionCallError("Invalid function name")
|
||||||
|
function = functions_matching[name]
|
||||||
|
await function(message, arguments)
|
||||||
|
|
||||||
|
|
||||||
functions_matching = {
|
functions_matching = {
|
||||||
"add_reaction_to_last_message": add_reaction_to_last_message,
|
"add_reaction_to_last_message": add_reaction_to_last_message,
|
||||||
"reply_to_last_message": reply_to_last_message,
|
"reply_to_last_message": reply_to_last_message,
|
||||||
|
|||||||
@@ -8,17 +8,7 @@ import json
|
|||||||
from src.config import curs_data, max_uses, curs_premium, gpt_3_5_turbo_prompt
|
from src.config import curs_data, max_uses, curs_premium, gpt_3_5_turbo_prompt
|
||||||
from src.utils.misc import moderate
|
from src.utils.misc import moderate
|
||||||
from src.utils.openaicaller import openai_caller
|
from src.utils.openaicaller import openai_caller
|
||||||
from src.functionscalls import (
|
from src.functionscalls import call_function, functions, server_normal_channel_functions
|
||||||
add_reaction_to_last_message,
|
|
||||||
reply_to_last_message,
|
|
||||||
send_a_stock_image,
|
|
||||||
create_a_thread,
|
|
||||||
send_a_gif,
|
|
||||||
send_ascii_art_text,
|
|
||||||
send_ascii_art_image,
|
|
||||||
functions,
|
|
||||||
server_normal_channel_functions,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def replace_mentions(content, bot):
|
async def replace_mentions(content, bot):
|
||||||
@@ -146,56 +136,7 @@ async def chatgpt_process(
|
|||||||
print(f"response: {response}")
|
print(f"response: {response}")
|
||||||
if response.get("function_call"):
|
if response.get("function_call"):
|
||||||
function_call = response.get("function_call")
|
function_call = response.get("function_call")
|
||||||
name = function_call.get("name", "")
|
await call_function(message, function_call)
|
||||||
arguments = function_call.get("arguments", {})
|
|
||||||
print(f"arguments: {arguments}")
|
|
||||||
arguments = json.loads(arguments)
|
|
||||||
if name == "add_reaction_to_last_message":
|
|
||||||
if arguments.get("emoji"):
|
|
||||||
emoji = arguments.get("emoji")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
await add_reaction_to_last_message(message, emoji, reply)
|
|
||||||
if name == "reply_to_last_message":
|
|
||||||
if arguments.get("message"):
|
|
||||||
reply = arguments.get("message")
|
|
||||||
await reply_to_last_message(message, reply)
|
|
||||||
if name == "send_a_stock_image":
|
|
||||||
if arguments.get("query"):
|
|
||||||
query = arguments.get("query")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
await send_a_stock_image(message, query, reply)
|
|
||||||
if name == "create_a_thread":
|
|
||||||
if arguments.get("name") and arguments.get("message"):
|
|
||||||
name = arguments.get("name")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
if isinstance(message.channel, discord.TextChannel):
|
|
||||||
await create_a_thread(message.channel, name, reply)
|
|
||||||
else:
|
|
||||||
await message.channel.send(
|
|
||||||
"`A server normal text channel only function has been called in a non standard channel. Please retry`",
|
|
||||||
delete_after=10,
|
|
||||||
)
|
|
||||||
if name == "send_a_gif":
|
|
||||||
if arguments.get("query"):
|
|
||||||
query = arguments.get("query")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
limit = arguments.get("limit", 15)
|
|
||||||
await send_a_gif(message, query, reply, limit)
|
|
||||||
if name == "send_ascii_art_text":
|
|
||||||
if arguments.get("text"):
|
|
||||||
text = arguments.get("text")
|
|
||||||
font = arguments.get("font", "standard")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
await send_ascii_art_text(message, text, font, reply)
|
|
||||||
if name == "send_ascii_art_image":
|
|
||||||
if arguments.get("query"):
|
|
||||||
query = arguments.get("query")
|
|
||||||
reply = arguments.get("message", "")
|
|
||||||
await send_ascii_art_image(message, query, reply)
|
|
||||||
if name == "":
|
|
||||||
await message.channel.send(
|
|
||||||
"The function call is empty. Please retry.", delete_after=10
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
content = response.get("content", "")
|
content = response.get("content", "")
|
||||||
while len(content) != 0:
|
while len(content) != 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user