jupyter-ai
jupyter-ai copied to clipboard
Inline completer displays ``` at the end of suggested code when using provider
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.
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:
@krassowski Do you want to own this issue? 👀
It looks like the problem is two-fold:
- 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
- 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.
@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:
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:
But it does not always give the same result (see the two examples below):
Here we mimic the add_two_numbers case but get different results:
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.
Then select Inline Completer.
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.
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:
Checking the first and third boxes gives different behavior as well
Checking all three boxes again alters behavior:
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.
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:
- specific LLMs need a different template to coerce them to only produce code, which is configurable
- 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.