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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brdskggs
Copy link

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.

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.

return output.join('')
}

export function extractSuffixCellsContext(
Copy link
Contributor

Choose a reason for hiding this comment

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

sure seems similar to the above function, can it be deduplicated?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I'll try to clean it up -- the main difference is which direction to shorten.

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
Author

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

@brdskggs
Copy link
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
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