AI Request Context

Index of All Documentation » Wing Pro Reference Manual » AI Assisted Development »


Wing always sends at least some of the contents of your current editor to the AI provider as part of its completion and refactoring requests. At your discretion, other files may be sent as well as context for the request, so that results are better tailored to your existing code base. You can specify the amount and type of context sent with AI requests, and this can have considerable impact on the quality of the results that you receive.

Adding context can cause your requests to become hugely compute intensive and costly over time, so you will want to include additional context only when necessary. The more relevant context you provide, the better results you will obtain, but larger requests take longer to complete, cost significantly more, and may reach rate limits imposed by the AI provider. In some cases, providing irrelevant context may even have a negative impact on the quality of results that you receive.

In general, you should think about whether your request needs anything more than the contents of the current file and the AI's training set to be answered correctly. If you are asking the AI to write or refactor code using only code in the current file, then you do not need to include additional context. On the other hand, if your request needs to use imported custom modules that won't exist in the AI's training set, then you will get better results if you first add those imports to your file and enable auto-context for your request.

Auto-Context

For AI requests that would benefit from context found outside of the current editor file, you can enable auto-context and let Wing automatically find files that are likely to be relevant to your request.

For AI code suggestion, auto-context is enabled with AI Suggest Uses Auto-Context on the Request Context page of the AI tool.

For AI refactoring, auto-context may be enabled or disabled on a case by case basis from the AI Refactoring page of the AI tool.

Auto-context adds other files to AI requests in the following order, until the maximum request size has been reached: (1) any project files that are imported into the current file, (2) any other project files that are currently open in an editor, and (3) any other files in the project that were not imported or open in an editor. Which of these are added and how much total context to include can be configured, as described below.

In many cases, only a small subset of all possible files will be included with your request, because of the computationally intensive nature of generative AI. To increase the chances that the more relevant files are included, more recently used files are given priority.

Configuration

You can configure AI request context by opening the AI tool from the Tools menu and selecting Request Context from the drop down at the top of the tool. The following options are available for controlling the size of request context:

  • Max Local Context (KB) sets the maximum number of kilobytes of code from the current editor that may be sent as context for AI requests. Up to this amount of context is always sent with every request.
  • Max External Context (KB) sets the maximum number of kilobytes of code from files other than the current editor that may be sent as context for AI requests. This includes files specified with Context Files and files identified as relevant when auto-context is enabled.

The maximum sizes to use here are governed by the specific rate limits imposed by your AI provider account, and the cost of requests. Note, however, that the upper limit may never be reached if your files are small and/or you have not enabled auto-context or specified any custom context files.

It may take some experimentation to find the best value to use, where enough context is provided for quality results without overwhelming the AI provider or running into your account's rate limits.

You can also configure what files are included in auto-context with the following options:

  • Auto-Context: Imported Project Files specifies whether imported project files should be included as request context, when auto-context is enabled.
  • Auto-Context: Open Project Files specifies whether open project files that were not imported should be included as request context, when auto-context is enabled.
  • Auto-Context: Other Project Files specifies whether other project files that were not imported and are not open in an editor should be included as request context, when auto-context is enabled.
  • Context Files allows you to specify files to always include as context with all AI requests, even when auto-context is disabled. These files are prioritized over any files added by auto-context, so that they will always be included, as long as they don't themselves exceed the configured maximum external context size.

Finally, you can control whether AI code suggestion uses auto-context:

  • AI Suggest Uses Auto-Context controls whether Wing will automatically add additional files, other than the current file, as context when you are invoking AI code suggestion for the current insertion point in the editor.

This option is disabled by default since for many AI code suggestion tasks, no additional context is needed. You will want to enable it only if your request needs access to the content of files other than the current one, and in that case should first import the files you want to use in the AI's implementation.