Trigger tool detection only on complete lines to help nested code block start detection #251
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR; This MR fixes the bug when you have a markdown code block nested in another tooluse code block in streaming mode.
I think it's related to this issue #111
To reproduce
Create the file foo.md and add a small explanation on how works the async in python with a code example
The response of this prompt looks something like that:
If you are using streaming mode, the tooluse detection will stop immediately after the three back quotes preceding the
python
code block type because the check is executed after every single char.Solution proposed
The idea of this MR is to wait for the end of a line (i.e. a
\n
char) to execute the tool check. That way, we know the next three back quotes aren't the end of the code block as they are followed by the code block type (python
here) and the tool use detection algorithm can handle that.It's not perfect as it still won't detect if there is no code block type but it should work in more situation waiting for a more robust solution.
Also I think it's a good idea to wait for the end of the line to try to detect the tools. I don't think we have benefits to execute it on every single char unless I missed something.