Skip to content

fix(amazonq): Previous and subsequent cells are used as context for completion in a Jupyter notebook #7086

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

Merged
merged 9 commits into from
May 13, 2025

Conversation

brdskggs
Copy link
Contributor

@brdskggs brdskggs commented Apr 17, 2025

Problem

VS Code treats each cell in a notebook as a separate editor. As a result, when building the left- and right-contexts for the completion from the current editor, we were limited to just the current cell, which might be very small and/or reference variables and functions defined in other cells. That meant that completions never used the context of other cells when making suggestions, and were often very generic. #7031

Solution

The extractContextForCodeWhisperer function now checks if it is being called in a cell in a Jupyter notebook. If so, it collects the surrounding cells to use as context, respecting the maximum context length. During this process, Markdown cells have each line prefixed with a language-specific comment character.


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@brdskggs brdskggs requested review from a team as code owners April 17, 2025 20:07
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

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

This is helpful, thanks! Tests for this function are here:

describe('extractContextForCodeWhisperer', function () {

You can run that test file by opening it in vscode then choose Extension tests (current file) (amazon) in the run/debug menu:

image

@brdskggs brdskggs force-pushed the multi-cell-context branch from 8ca009c to 5f29d4a Compare April 18, 2025 13:25
@brdskggs
Copy link
Contributor Author

Will consolidate the function doing the suffix and prefix context fetching.

@brdskggs
Copy link
Contributor Author

brdskggs commented Apr 18, 2025

image

Both code cells and Markdown cells are used for context now; Markdown cells have lines prefixed with a language-specific comment based on the language of the cell the completion is triggered from.

@brdskggs brdskggs requested a review from justinmk3 April 18, 2025 17:50
@brdskggs brdskggs changed the title fix(amazonq) Previous and subsequent cells are used as context for completion in a Jupyter notebook fix(amazonq): Previous and subsequent cells are used as context for completion in a Jupyter notebook Apr 22, 2025
@brdskggs brdskggs closed this Apr 22, 2025
@brdskggs brdskggs reopened this Apr 22, 2025
@brdskggs brdskggs force-pushed the multi-cell-context branch 3 times, most recently from 5b7ca22 to 76e096a Compare May 5, 2025 13:42
@brdskggs brdskggs closed this May 5, 2025
@brdskggs brdskggs reopened this May 5, 2025
@brdskggs brdskggs closed this May 7, 2025
@brdskggs brdskggs reopened this May 7, 2025
@justinmk3
Copy link
Contributor

lint failure

Error:   112:13  error  'cellText' is never reassigned. Use 'const' instead  prefer-const

@brdskggs brdskggs force-pushed the multi-cell-context branch from 130c19d to 2650145 Compare May 7, 2025 18:35
@@ -24,19 +24,130 @@ import { predictionTracker } from '../nextEditPrediction/activation'

let tabSize: number = getTabSizeSetting()

const languageCommentChars: Record<string, string> = {
python: '# ',
java: '// ',
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this. It's not sustainable for us to introduce yet another language-specific handling just for notebooks. Why isn't the notebook logic using the existing logic used by other Q functionality ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question! I'm new to this codebase, so I'll have to research what existing logic you are referring to -- any quick pointers of where to start looking are appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never mind, Q to the rescue -- figured out the changes I needed to make to runtimeLanguageContext.

@brdskggs brdskggs force-pushed the multi-cell-context branch from 2650145 to a6625ea Compare May 8, 2025 00:44
@brdskggs brdskggs force-pushed the multi-cell-context branch from a6625ea to dbfe86b Compare May 13, 2025 14:08
@justinmk3 justinmk3 merged commit 8e85476 into aws:master May 13, 2025
26 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants