Skip to content

Commit

Permalink
Fix Python 3.11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Nov 17, 2024
1 parent 6e99bd2 commit aee9ce5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 71 deletions.
18 changes: 8 additions & 10 deletions plugins/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,9 @@ async def embeds_to_text(self, ctx: commands.Context, embeds: List[discord.Embed
asyncio.gather(
clean_content_converter.convert(ctx, field.name),
clean_content_converter.convert(ctx, field.value),
loop=self.bot.loop,
)
for field in embed.fields
),
loop=self.bot.loop,
)
parts.append("\n".join(f"{name}: {value}" for name, value in embed_fields_cleaned))
if embed.footer.text:
Expand Down Expand Up @@ -249,7 +247,7 @@ async def hey(self, ctx: commands.Context):
clean_content = await self.message_to_text(ctx, message)
if clean_content is None:
continue
clean_content = clean_content.split('-#')[0].strip() # Remove citations
clean_content = clean_content.split("-#")[0].strip() # Remove citations
except IndexError:
break
# Append
Expand Down Expand Up @@ -302,7 +300,9 @@ async def hey(self, ctx: commands.Context):
iteration_choice = iteration_result.choices[0]
if iteration_choice.finish_reason == "tool_calls":
if iteration_choice.message.content:
self.bot.send(ctx, iteration_choice.message.content, reply=not final_resulted_in_command_message)
self.bot.send(
ctx, iteration_choice.message.content, reply=not final_resulted_in_command_message
)
function_call = iteration_choice.message.tool_calls[0].function
if function_call.name == ASK_ONLINE_FUNCTION_DEFINITION.name:
resulting_message_content = await self.execute_ask_online(citations, function_call)
Expand Down Expand Up @@ -342,9 +342,7 @@ async def hey(self, ctx: commands.Context):
)
if math_operations:
final_message += "\n-# Obliczenia: "
final_message += ", ".join(
f"`{operation}`" for operation in math_operations
)
final_message += ", ".join(f"`{operation}`" for operation in math_operations)
break

await self.bot.send(ctx, final_message, reply=not final_resulted_in_command_message)
Expand Down Expand Up @@ -378,11 +376,11 @@ async def execute_ask_online(self, citations, function_call):
def execute_calculator(self, math_operations, function_call):
expr = json.loads(function_call.arguments)["expr"]
try:
result = arithmetic_eval.evaluate(expr)
result = arithmetic_eval.evaluate(expr)
except Exception as e:
return f"⚠️ {e}"
math_operations.append(f'{expr} = {result:n}')
return f'{result:n}'
math_operations.append(f"{expr} = {result:n}")
return f"{result:n}"

async def invoke_command(self, ctx: commands.Context, prompt_messages: list, function_call) -> tuple[str, bool]:
command_invocation = (
Expand Down
Loading

0 comments on commit aee9ce5

Please sign in to comment.