jupyter-ai icon indicating copy to clipboard operation
jupyter-ai copied to clipboard

Inline completer displays ``` at the end of suggested code when using provider

Open bensonlee5 opened this issue 1 year ago • 5 comments
trafficstars

As flagged in this Jupyterlab forum post; should be removed in post-processing.

bensonlee5 avatar Mar 10 '24 19:03 bensonlee5

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

welcome[bot] avatar Mar 10 '24 19:03 welcome[bot]

@krassowski Do you want to own this issue? 👀

dlqqq avatar Mar 11 '24 16:03 dlqqq

It looks like the problem is two-fold:

  1. when streaming, post-processing is only used when a problematic prefix is detected: https://github.com/jupyterlab/jupyter-ai/blob/b18b7d077119fb9f7063b0fb04f8dd28d4bc91e4/packages/jupyter-ai/jupyter_ai/completions/handlers/default.py#L86-L101
  2. post-processing does not look for suffixes at all in general: https://github.com/jupyterlab/jupyter-ai/blob/b18b7d077119fb9f7063b0fb04f8dd28d4bc91e4/packages/jupyter-ai/jupyter_ai/completions/handlers/default.py#L130-L154

I think (2) is easy to solve, I am happy to review a PR from new contributors here if anyone is interested. Ideally the PR would come with a new test case in packages/jupyter-ai/jupyter_ai/tests/completions/test_handlers.py.

krassowski avatar Mar 12 '24 09:03 krassowski

@dlqqq @krassowski Thanks for bringing up this issue. I did a detailed analysis and provide my thoughts below. The issue is that for the example shown, the JupyterLab completer enters ``` at the end of the generated code snippet. Here is a visual: image

Installed jupyterlab-transformers-completer based on https://github.com/krassowski/jupyterlab-transformers-completer.

Replicated this error on mac-os for the example above using both openai-chat:gtp-3.5-turbo and bedrock-chat:anthropic.claude-instant-v1 . As shown below for the Claude case: image

But it does not always give the same result (see the two examples below): image

Here we mimic the add_two_numbers case but get different results: image Here we want the backticks. Replicated the same results using Linux as well. At least we know this is not LLM specific nor os specific.

Clearly, adding special code to remove the ``` at the end as suggested here https://github.com/jupyterlab/jupyter-ai/issues/686#issuecomment-1991202710, will only handle one edge case, which may just be the outcome of some LLM completions, not all. It may not be desirable to build in special code for one edge case into jupyter-ai. Maybe this needs to be handled in JupyterLab , if at all.

Further, the outcome of the transformer completion also depends on the Settings in JupyterLab. In the Settings drop down, select Settings Editor. image Then select Inline Completer. image If you scroll down the Inline Completer panel, you get three boxes where transformer completion can be “Enabled”. As shown below.

The Issue can be reproduced when only the third box is checked as shown below. image

Checking any other configuration of the checkboxes generates other behavior, for example let’s check the second and third boxes and then we get the following examples: image

Checking the first and third boxes gives different behavior as well image

Checking all three boxes again alters behavior: image

A slightly different experience may arise depending on machine, environment, and code completion use cases.

We may not want to fix jupyter-ai code for varying responses from the transformer used for JupyterLab completions. Also, the UX is altered with completions, so it is better to set all the three “Enabled” checkboxes off as default as different users may want completions versus not.

We need to think/discuss the UX and generality of the code mods before going ahead.

srdas avatar Mar 20 '24 17:03 srdas

Maybe this needs to be handled in JupyterLab , if at all

No, we do not want to special case anything in JupyterLab.

I don't think that the LLMs should add any examples like on your second snapshot.

Here is my point of view - there are two issues:

  1. specific LLMs need a different template to coerce them to only produce code, which is configurable
  2. the default post-processing should handle the case of returned code being wrapped in extra backticks; nothing more nothing less

Also, the UX is altered with completions, so it is better to set all the three “Enabled” checkboxes off as default as different users may want completions versus not.

I do not understand how this relates to this issue.

krassowski avatar Mar 20 '24 17:03 krassowski