Skip to content

feat: allow tool calling to respond without a tool #2614

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

Merged
merged 8 commits into from
Oct 10, 2024

Conversation

drbh
Copy link
Collaborator

@drbh drbh commented Oct 7, 2024

This PR is an improved version of #2597 and handles processing streaming responses as well as non streaming generations. This PR unrolls tool responses that do not select one of the user provided tools.

This implementation parses the first few tokens of generations requests with user provided tools to determine if a tool was selected. If no tool was selected the response is parsed and returned as a normal content value.

This PR also supersedes draft PR #2606 as this approach has more benefits and less downsides

@drbh drbh changed the title feat: process token stream before returning to client feat: allow tool calling to respond without a tool Oct 7, 2024
@drbh drbh marked this pull request as ready for review October 7, 2024 13:42
@drbh drbh force-pushed the identify-function-name-while-streaming-and-unroll branch from 7bd57e6 to fcc822f Compare October 7, 2024 15:27
Comment on lines 469 to 470
let event = Event::default();
yield Ok(event);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why ? You're changing functionality here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

great catch, Thanks. I've updated the logic to emit an event in both cases of a token or an error (to match the existing functionality).

@drbh drbh force-pushed the identify-function-name-while-streaming-and-unroll branch from d8ef7ac to 7d2aa27 Compare October 8, 2024 15:43
Narsil
Narsil previously approved these changes Oct 9, 2024
Copy link
Collaborator

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

LGTM.

Some fixes in _err.
Remove send_function_name logic.
Add stream test variant.

print(content_generated)
assert (
content_generated
== "There is no weather related function available to answer your prompt"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Odd answer to be honest.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea I agree, I think its because the model is technically responding to the error field in the notify_error tool, so the text is more of an error text than an actual response. Going to make a couple changes to see if I can minimize the issue

Copy link
Collaborator

@Narsil Narsil left a comment

Choose a reason for hiding this comment

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

LGTM

@drbh drbh merged commit e36dfaa into main Oct 10, 2024
11 of 12 checks passed
@drbh drbh deleted the identify-function-name-while-streaming-and-unroll branch October 10, 2024 13:28
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