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

Show error icon near cursor on inline completion errors #1197

Merged
merged 9 commits into from
Feb 4, 2025

Conversation

Darshan808
Copy link
Member

@Darshan808 Darshan808 commented Jan 13, 2025

Description

This PR introduces the error animation functionality to code cells for jupyter-ai. It aligns jupyter-ai's error reporting with JupyterLab's completer error animation feature.

Testing

  • Test is added to validate the error field emission.
  • Currently seeking guidance on how to simulate error scenarios for testing.

Feedback on the testing approach is appreciated, particularly on methods to programmatically raise errors during tests.

Screencast

Simulated by raising custom exception from server side

ai-error.mp4

@krassowski
Copy link
Member

I think you could override handle_stream_request in the Mock class to conditionally raise an exception (conditionally on arguments passed in to the mock?)

@andrewfulton9
Copy link
Contributor

andrewfulton9 commented Jan 14, 2025

I think you could override handle_stream_request in the Mock class to conditionally raise an exception (conditionally on arguments passed in to the mock?)

I think you will also need to bump the version of jupyterlab/completer to 4.3.0 if the main branch of jupyter-ai isn't on that version yet. It wasn't when I looked at this issue.

Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

@Darshan808 Welcome to Jupyter AI! I love seeing new contributors. Thank you for getting started on this feature request.

I've left a few suggestions below. In addition, I have a couple of questions:

  1. Could you add a screenshot to this PR?
  2. The original issue (Show error animation in code cell when error is triggered  #1144) shows an icon when the completer fails. How is the icon being added?

@Darshan808
Copy link
Member Author

Thank you for your feedback and suggestions, @dlqqq

Have a single source of truth and drop either InlineCompletionItem.error or InlineCompletionReply.error. That way, there's only one way to determine if a completion reply has an error.

Yes, this was redundant, so I dropped InlineCompletionItem.error since InlineCompletionReply.error already provides more context about the error.

The original issue (Show error animation in code cell when error is triggered #1144) shows an icon when the completer fails. How is the icon being added?

Whenever we return an item with the error field containing a message, JupyterLab's completer has implemented the necessary code to display that animation. So, I don't think we need to reimplement it here. Simply returning a completion with the error field does the job.

Could you add a screenshot to this PR?

Sure, I am adding a clip.

In LangChain, LLM._call() is (usually) the method which is called when a non-streaming reply is requested. If this doesn't work, you can try following the above steps for the _acall() method instead.

This worked perfectly.

@Darshan808
Copy link
Member Author

@Darshan808
Copy link
Member Author

The newly added test passes locally but fails on CI. Looking into it

@Darshan808 Darshan808 requested a review from dlqqq January 23, 2025 15:09
Copy link
Member

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

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

@Darshan808 Thank you for revising this PR! Apologies for the late review, I just got back from seeing my family overseas for Chinese New Year.

I left one minor comment below. In addition, it looks like the unit test you've added is failing in CI. Can you address both of these issues so I can approve & merge your PR?

@Darshan808
Copy link
Member Author

The unit test is passing locally and also passing in CI on my PR of my fork of jupyter-ai. Not sure what's causing it to fail here.
Darshan808#1

@krassowski
Copy link
Member

It looks like there are significant differences in packages installed in runs on CI on this repo vs on your fork, especially around langchain (but others too):

jupyterlab #1197 Darshan808#1
image image

@Darshan808 maybe your local installation also predates the merge of #1201? This seems plausible as both this PR and #1201 were opened around 3 weeks ago.

@dlqqq any idea why langchain upgrade would lead to the test failures?

@dlqqq
Copy link
Member

dlqqq commented Feb 4, 2025

@krassowski Thanks for doing the research. Not sure about what's going on yet. Let me rebase and investigate further if CI still fails.

@dlqqq dlqqq force-pushed the error-animation-in-code-cell branch from 61231c4 to 4e02a05 Compare February 4, 2025 17:19
@dlqqq
Copy link
Member

dlqqq commented Feb 4, 2025

The E2E test failure is not related. CI issue is being tracked in #1227 and will be fixed shortly.

@dlqqq
Copy link
Member

dlqqq commented Feb 4, 2025

@Darshan808 Hey Darshan, I took the liberty of checking out your branch locally. I was able to reproduce the unit test failure.

The issue is that MockProvider is a Pydantic BaseModel. When adding a keyword argument to this class, it needs to be defined in the class scope with a default value so Pydantic can automatically update it based on the arguments passed to __init__(). Also, BaseModel.dict() has been deprecated in favor of BaseModel.model_dump() in Pydantic v2.

I've taken the liberty of committing these changes on this branch for you to help get this PR merged. See this commit to review my changes: 28eac5e

Thank you for contributing this! 🎉

@dlqqq dlqqq force-pushed the error-animation-in-code-cell branch from 28eac5e to 67cea10 Compare February 4, 2025 18:58
@dlqqq dlqqq changed the title Add Error Animation in Code Cell for Jupyter-AI Errors Show error icon near cursor on inline completion error Feb 4, 2025
@dlqqq dlqqq changed the title Show error icon near cursor on inline completion error Show error icon near cursor on inline completion errors Feb 4, 2025
@dlqqq dlqqq merged commit c79f89d into jupyterlab:main Feb 4, 2025
10 of 11 checks passed
@dlqqq
Copy link
Member

dlqqq commented Feb 4, 2025

@meeseeksdev please backport to 2.x

meeseeksmachine pushed a commit to meeseeksmachine/jupyter-ai that referenced this pull request Feb 4, 2025
dlqqq pushed a commit that referenced this pull request Feb 4, 2025
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.

Show error animation in code cell when error is triggered
4 participants