AI rewriter supports delta text response events#24119
AI rewriter supports delta text response events#24119
Conversation
There was a problem hiding this comment.
In general, I'm okay with this approach. However, I think I'd prefer to handle this at an API level - both of the use cases we have here are going to end up concatenating the bits of the text together, so are probably going to duplicate that logic.
If we do go this way though, could we push the is_delta property into the CompletionEntryEvent struct (maybe a big ask, as its just deserializing a response from the server)? In my ideal world, the data would be something like:
union ConversationEntryData {
string suggestion;
string delta;
};If not, this is fine - it'll unblock the rewriter stuff 😄
I think what you proposed is a good option - not the low-level API (which would interfere with regular conversation multi-evented responses too), but at the Conversation(Driver) level, which has a specific handler for the selected text / rewriting text generation. In fact, the ConversationDriver already handles text concatenation for the regular conversation entries anyway. I've updated the PR to do that.
I didn't want to go down that route as it has implications for all UI to handle it and these events are stored as conversation history entry data. It's debatable I suppose, but probably best we give consumers simpler events and handle the delta stuff at the Conversation level. |
1c02352 to
5469c9b
Compare
5469c9b to
4e29798
Compare
fallaciousreasoning
left a comment
There was a problem hiding this comment.
LGTM, thanks for doing this @petemill
|
|
||
| base::TrimWhitespaceASCII(suggestion, base::TRIM_ALL, | ||
| &suggestion); | ||
| if (!is_delta_text) { |
There was a problem hiding this comment.
👍 I bumped into this when I was playing around with this change 😆
The Conversation API sends delta updates of text, but the text selection rewriting expects full text on every streaming event call. This PR passes through whether it's a delta update or not (based on the current engine being used). I considered handling this at the API level, but then re-considered since that wouldn't be possible for other action types with more complicated event streams. Even the rewrite event stream response could become more complicated with different event types, and I'm not sure the API client code would have been the best place to decide how to combine delta responses in between events. What do the reviewers think?
Resolves
Submitter Checklist:
QA/YesorQA/No;release-notes/includeorrelease-notes/exclude;OS/...) to the associated issuenpm run test -- brave_browser_tests,npm run test -- brave_unit_testswikinpm run presubmitwiki,npm run gn_check,npm run tslintgit rebase master(if needed)Reviewer Checklist:
gnAfter-merge Checklist:
changes has landed on
Test Plan: