Skip to content

Commit 33f4c0b

Browse files
committed
Optimize AI iterations handling
1 parent 5a7fc69 commit 33f4c0b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

plugins/chat.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ async def hey(self, ctx: commands.Context):
243243
model="gpt-4o",
244244
messages=prompt_messages,
245245
user=str(ctx.author.id),
246-
tools=[{"function": f, "type": "function"} for f in self._all_available_commands_as_tools],
246+
tools=[{"function": f, "type": "function"} for f in self._all_available_commands_as_tools]
247+
if iterations_left
248+
else [],
247249
)
248250
iteration_choice = iteration_result.choices[0]
249251
if iteration_choice.finish_reason == "tool_calls":
@@ -282,7 +284,7 @@ async def hey(self, ctx: commands.Context):
282284
# Found a message which probably resulted from the tool's command invocation
283285
reply_resulted_in_command_message = True
284286
resulting_message_content = await self.message_to_text(command_ctx, message)
285-
if resulting_message_content and resulting_message_content[0] in ("⚠️", "❔"):
287+
if resulting_message_content and resulting_message_content[0] in ("⚠️", "🙁", "❔"):
286288
# There was some error, which hopefully we'll correct on next try
287289
await message.delete()
288290
reply_resulted_in_command_message = False
@@ -303,11 +305,11 @@ async def hey(self, ctx: commands.Context):
303305
prompt_messages.append(
304306
{
305307
"role": "user",
306-
"content": "Nie możesz już wykonać kolejnej komendy!"
308+
"content": "Wykorzystano limit użycia komend."
307309
if iterations_left == 1
308-
else f"Spróbuj ponownie naprawiając wskazany błąd. Masz do wykorzystania jeszcze {word_number_form(iterations_left, 'komendę','komendy', 'komend')}."
310+
else "Spróbuj ponownie naprawiając wskazany błąd."
309311
if resulting_message_content and "⚠️" in resulting_message_content
310-
else f"Jeśli w powyższym wyniku brakuje informacji w sprawie mojej prośby, spróbuj ponownie z inną komendą. Masz do wykorzystania jeszcze {word_number_form(iterations_left, 'komendę','komendy', 'komend')}. Nie ponawiaj komendy bez znaczących zmian.",
312+
else "Jeśli w powyższym wyniku brakuje informacji w sprawie mojej prośby, spróbuj ponownie z inną komendą. Nie ponawiaj komendy bez znaczących zmian.",
311313
}
312314
)
313315
else:

0 commit comments

Comments
 (0)