Skip to content
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

feat: improve tool use response format #306

Merged
merged 4 commits into from
Dec 21, 2024

Conversation

jrmi
Copy link
Contributor

@jrmi jrmi commented Dec 3, 2024

This is an attempt to match the expected output for each API regarding tool use response.

It modify the message dicts to match the expected output.

Also fix tool call not working with stream == False

@jrmi jrmi marked this pull request as draft December 3, 2024 23:14
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a 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 a7b9ef4 in 53 seconds

More details
  • Looked at 289 lines of code in 6 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. gptme/message.py:44
  • Draft comment:
    Update the docstring to include 'tool_result' as a possible role for the message sender.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a new role 'tool_result' in the Message class, which is used in various places. This change should be reflected in the documentation of the Message class to ensure clarity.

Workflow ID: wflow_Bqw5JXPSO6DeDHb2


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@jrmi jrmi mentioned this pull request Dec 3, 2024
3 tasks
@jrmi jrmi force-pushed the 302-improve-tool-support branch 7 times, most recently from a1cadba to e63fbab Compare December 10, 2024 22:25
@jrmi jrmi force-pushed the 302-improve-tool-support branch 7 times, most recently from 8a22723 to 97e7e7c Compare December 13, 2024 22:11
gptme/cli.py Show resolved Hide resolved
assert len(content) == 1
return content[0].text # type: ignore

parsed_block = []
Copy link
Contributor Author

@jrmi jrmi Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tool call was broken with non stream API.

@@ -99,7 +108,7 @@ def stream(
block = chunk.content_block
if isinstance(block, anthropic.types.ToolUseBlock):
tool_use = block
yield f"\n@{tool_use.name}: "
yield f"\n@{tool_use.name}({tool_use.id}): "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add the tool uid here to save it in the message.

@@ -224,7 +303,7 @@ def _transform_system_messages(

# for any subsequent system messages, transform them into a <system> message
for i, message in enumerate(messages):
if message.role == "system":
if message.role == "system" and message.call_id is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to change messages with call_id. They will be handled by the _handle_tool function.

Copy link
Owner

@ErikBjare ErikBjare Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this as a code comment, as it's good to know when reading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@jrmi jrmi marked this pull request as ready for review December 13, 2024 22:16
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a 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 97e7e7c in 1 minute and 32 seconds

More details
  • Looked at 1066 lines of code in 10 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. tests/test_tool_use.py:70
  • Draft comment:
    The regex pattern for tool calls has been updated to include a call ID, but the test cases here still use the old pattern without the call ID. Update the test cases to include a call ID in the tool call format.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_FEtlgo6qaP9zjkPI


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@jrmi
Copy link
Contributor Author

jrmi commented Dec 13, 2024

Hey @ErikBjare this MR is ready to review:

  • it fixes the tool response to match the expected format by adding the call_id to the message
  • it fixes the tool call with non-stream API
  • it improves openai msg2dict process by adding the _prepare_messages_for_api
  • it adds tests for message preparation process
  • it fixes small bugs

Let me know what you think.

FYI I tested it with openai and anthropic ;-)

@jrmi jrmi force-pushed the 302-improve-tool-support branch from 97e7e7c to 6e66c1b Compare December 13, 2024 22:24
@jrmi jrmi changed the title Improve tool responses feat: improve tool responses Dec 13, 2024
@jrmi jrmi force-pushed the 302-improve-tool-support branch 3 times, most recently from 43785e5 to 372163b Compare December 13, 2024 22:32
Copy link
Owner

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

Will test this out and merge :)

@jrmi jrmi force-pushed the 302-improve-tool-support branch 2 times, most recently from 7bd93ea to 4b12180 Compare December 20, 2024 10:35
@jrmi jrmi force-pushed the 302-improve-tool-support branch from 4b12180 to a0c39f2 Compare December 21, 2024 11:41
Copy link
Owner

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super impressive, works amazingly! 💪

Thanks again 🙏

🥇 👑

@ErikBjare ErikBjare changed the title feat: improve tool responses feat: improve tool use response format Dec 21, 2024
@ErikBjare ErikBjare merged commit 1934fcf into ErikBjare:master Dec 21, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants