Skip to content

Add review code command - #28

Merged
brichet merged 10 commits into
QuantStack:mainfrom
Yahiewi:review
Aug 10, 2026
Merged

Add review code command#28
brichet merged 10 commits into
QuantStack:mainfrom
Yahiewi:review

Conversation

@Yahiewi

@Yahiewi Yahiewi commented Jul 24, 2026

Copy link
Copy Markdown
Member

This PR adds a new "Review Code" command in the cell toolbar which sends the code cell to the agent to review the changes made by the user.

Key Changes:

-Added computeDiff() function in utils.ts to generate the diffs between initial_source and current code (source). This is better than giving the LLM the initial code and the current code and letting it make out the diff itself as that's not deterministic like it is this way and, from what I tested, the LLM often can't accurately make out the diff on its own.
-Added a <diff> tag to the prompt payload sent to the LLM, containing this computed diff. It's now sent instead of initial_source because of the aforementioned reasons, but it could still be useful to send initial_source too, for now I just removed it for 'economical' reasons.
-Added Review Code command and its button next to the Explain Code button in the cell toolbar.
-Auto-initializes initial_source cell metadata on load if missing. Since this metadata is necessary for the Review Code feature to function properly, if it's missing, then we just save the current content as initial_source.
-The Review Code button is disabled if the diff is empty, i.e if the student hasn't yet made any changes. In this case, there is nothing to review and I found that this disabling it in this case is simpler and better than telling the agent how to handle it.

Screencast.from.2026-07-24.12-52-41.mp4

@github-actions

Copy link
Copy Markdown

Binder 👈 Launch a Binder on branch Yahiewi/jupyter-ai-tutor/review

@Yahiewi
Yahiewi marked this pull request as ready for review August 4, 2026 16:15
@brichet brichet added the enhancement New feature or request label Aug 5, 2026

@brichet brichet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Yahiewi for working on this.

I have some comments below, to open the discussion about some changes.

Comment thread src/index.ts Outdated
// Keep the enabled state in sync when active cell or cell content changes.
notebookTracker?.activeCellChanged.connect((_, cell) => {
if (cell) {
ensureInitialSource(cell);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably keep initial source only on first opening the document, as it reflect the instructor document as it was sent.
IMO, if the student create a new cell, there should not be initial source.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the code to run ensureInitialSource only when the notebook document is first loaded. New student cells no longer have an initial_source automatically added to them. If a student requests a review on a cell without an initial_source, the tutor will evaluate the code cell directly.
EDIT: I removed it completely for now, I think it's better to have this feature in a separate PR.

Comment thread src/index.ts Outdated
formattedBody += `\n\n<evaluation_criteria>\n${evaluationCriteria}\n</evaluation_criteria>`;
}
if (initialSource && typeof initialSource === 'string') {
formattedBody += `\n\n<diff>\n${computeDiff(initialSource, source)}\n</diff>`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably stick to the initial source.
Setting up our own comparison tool could be a source of errors, whereas the LLM should handle it quite easily.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I reverted it back to use initial_source and I've removed computeDiff from utils.ts and updated back formattedBody to include the <initial_source> block instead of .
However it's still worth noting that some models (at least mistral/ministral-8b-latest which I'm using to test) are very inconsistent and seem to not be able to spot small differences in the code.
Here's what I mean, in this screencast, I fixed a one letter typo in the code cell and asked for review, and the model was only able to see I fixed the bug 3 out of 5 times:

Screencast.from.2026-08-07.13-11-28.mp4

This is the reason I implemented a TS diff function: to avoid the randomness of LLMs and make the review process more deterministic. I'm not sure what exactly LLMs do when you ask them to compare text, maybe the stronger models are better at this. I think I'll open an issue/PR to look into how I can improve this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for testing and opening the issue.
It looks good to handle it in a separate PR 👍

Comment thread jupyter_ai_tutor/handlers.py Outdated
except StreamClosedError:
pass

def _filter_prompt_for_action(self, raw_prompt: str, action: str) -> str:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will be overwritten if we move to a template.
Maybe for this PR we should keep the whole content for now, but add the expected action in the formatted body instead.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done!

@brichet brichet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @Yahiewi, LGTM.

I have one nitpick comment, otherwise we can merge it.

Comment thread jupyter_ai_tutor/handlers.py
Co-authored-by: Nicolas Brichet <32258950+brichet@users.noreply.github.com>
@Yahiewi

Yahiewi commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Great, thanks @brichet for reviewing this!

@brichet
brichet merged commit c1faafc into QuantStack:main Aug 10, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants