-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: tool api call broken when user answer no to when asked for confirmation #371
base: master
Are you sure you want to change the base?
fix: tool api call broken when user answer no to when asked for confirmation #371
Conversation
@@ -235,9 +235,6 @@ def step( | |||
if msg_response: | |||
yield msg_response.replace(quiet=True) | |||
yield from execute_msg(msg_response, confirm) | |||
except KeyboardInterrupt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now handled in the execute_msg
as we need the call_id
in the message response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good to me! Reviewed everything up to 2d25236 in 1 minute and 12 seconds
More details
- Looked at
223
lines of code in7
files - Skipped
0
files when reviewing. - Skipped posting
2
drafted comments based on config settings.
1. gptme/llm/llm_anthropic.py:203
- Draft comment:
The change frommessage["role"] == "system"
tomessage["role"] == "user"
seems incorrect. The original condition was likely correct as it was handling system messages withcall_id
. Please verify the intent of this change. - Reason this comment was not posted:
Comment did not seem useful.
2. gptme/llm/llm_openai.py:287
- Draft comment:
The function_merge_tool_results_with_same_call_id
is defined but not used in this file. Consider integrating it where necessary or removing it if not needed. - Reason this comment was not posted:
Comment looked like it was already resolved.
Workflow ID: wflow_Iq0Ct3a5VFKQWQwU
You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
2d25236
to
ac85af3
Compare
@@ -235,9 +235,6 @@ def step( | |||
if msg_response: | |||
yield msg_response.replace(quiet=True) | |||
yield from execute_msg(msg_response, confirm) | |||
except KeyboardInterrupt: | |||
clear_interruptible() | |||
yield Message("system", "Interrupted") | |||
finally: | |||
clear_interruptible() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is correct, I think the clear_interruptible
is no longer called?
I think the finally
clause might not run for the generator until the next()
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, it's there in the except clause for that very reason, but no longer needed.
Not quite clear to me if the new behavior is correct though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm no it's probably not the same. Let me find something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the MR. To stay on the safe side, I've called clear_interruptible
in the execute_msg
function. Notice the break
in the except clause. Before it was still calling subsequent tools if any after a user interruption 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also call clear_interruptible
inside the handle_keyboard_interrupt
itself just before raising the KeyboardInterrupt
exception, what do you think?
f09caaf
to
871c76e
Compare
messages_new | ||
and messages_new[-1].role == "user" | ||
and message.role == "user" | ||
and message.call_id == messages_new[-1].call_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this condition needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the function call API, multiple calls may occur within a single answer (parallel calls). To handle this properly, ensure there is one tool response per tool call. By verifying that the call_id is distinct, we can ensure messages are not merged unless they originate from the same function call.
gptme/tools/__init__.py
Outdated
clear_interruptible() | ||
yield Message( | ||
"system", | ||
"User hit Ctrl-c to interrupt the process", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda want to make these shorter
"User hit Ctrl-c to interrupt the process", | |
"Interrupted by user", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of what I did in #384
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the message (and used a constant to have the same value everywhere it's needed.)
871c76e
to
420b2d9
Compare
This MR fixes a few bug regarding tool call in tool format:
Ctrl+c
to interrupt gptmeThe underlying problems where that sometimes the
call_id
wasn't set in certain situations or multiple messages where returned by thetooluse.execute
call but all were the response from the tool so we needed to merge them.Important
Fixes tool API call issues by ensuring
call_id
is set and merging tool responses, with updates to message handling and tests.Ctrl+c
.call_id
is set correctly inexecute_msg()
intools/__init__.py
andToolUse.execute()
intools/base.py
.call_id
in_merge_tool_results_with_same_call_id()
inllm_openai.py
andllm_anthropic.py
._handle_tools()
inllm_anthropic.py
andllm_openai.py
to handle user role messages withcall_id
._transform_system_messages()
inllm_anthropic.py
to merge consecutive user messages with the samecall_id
.test_llm_anthropic.py
andtest_llm_openai.py
to verify message conversion and tool handling withcall_id
.This description was created by for 2d25236. It will automatically update as commits are pushed.