doc/user/project/repository/code_suggestions/_index.md
{{< details >}}
{{< /details >}}
{{< collapsible title="Model information" >}}
{{< /collapsible >}}
{{< history >}}
fireworks_qwen_code_completion.Codestral by default via the feature flag use_fireworks_codestral_code_completion in GitLab 17.11.Codestral as the default model in GitLab 18.1.code_suggestions_context in GitLab 18.6.{{< /history >}}
[!note] Code Suggestions is available for:
- GitLab Duo Agent Platform. Billing is usage-based.
- GitLab Duo Core, Pro, or Enterprise, GitLab Duo with Amazon Q. Billing is based on your add-on.
Use GitLab Duo Code Suggestions to write code more efficiently by using generative AI to suggest code while you're developing.
To use Code Suggestions:
[!note] GitLab Duo requires GitLab 17.2 or later. For GitLab Duo Core access, and for the best user experience and results, upgrade to GitLab 18.0 or later. Earlier versions might continue to work, however the experience might be degraded.
To use Code Suggestions:
Open your Git project in a supported IDE.
Add the project as a remote of your local repository using
git remote add.
Add your project directory, including the hidden .git/ folder, to your IDE workspace or project.
Author your code. As you type, suggestions are displayed. Code Suggestions provides code snippets or completes the current line, depending on the cursor position.
Describe the requirements in natural language. Code Suggestions generates functions and code snippets based on the context provided.
When you receive a suggestion, you can do any of the following:
{{< history >}}
{{< /history >}}
For a code completion suggestion in VS Code, multiple suggestion options might be available. To view all available suggestions:
Code Suggestions uses code completion and code generation:
| Code completion | Code generation | |
|---|---|---|
| Purpose | Provides suggestions for completing the current line of code. | Generates new code based on a natural language comment. |
| Trigger | Triggers when typing, usually with a short delay. | Triggers when pressing <kbd>Enter</kbd> after writing a comment that includes specific keywords. |
| Scope | Limited to the current line or small block of code. | Can generate entire methods, functions, or even classes based on the context. |
| Accuracy | More accurate for small tasks and short blocks of code. | Is more accurate for complex tasks and large blocks of code because a bigger large language model (LLM) is used, additional context is sent in the request (for example, the libraries used by the project), and your instructions are passed to the LLM. |
| How to use | Code completion automatically suggests completions to the line you are typing. | You write a comment and press <kbd>Enter</kbd>, or you enter an empty function or method. |
| When to use | Use code completion to quickly complete one or a few lines of code. | Use code generation for more complex tasks, larger codebases, when you want to write new code from scratch based on a natural language description, or when the file you're editing has fewer than five lines of code. |
Code Suggestions always uses both of these features. You cannot use only code generation or only code completion.
<i class="fa-youtube-play" aria-hidden="true"></i> View a code completion vs. code generation comparison demo.
<!-- Video published on 2024-09-26 -->To get the best results from code generation:
For example, to create a Python web service with some specific requirements, you might write something like:
# Create a web service using Tornado that allows a user to sign in, run a security scan, and review the scan results.
# Each action (sign in, run a scan, and review results) should be its own resource in the web service
...
AI is non-deterministic, so you may not get the same suggestion every time with the same input. To generate quality code, write clear, descriptive, specific tasks.
For use cases and best practices, follow the GitLab Duo examples documentation.
Different language models can be the source for Code Suggestions.
Learn about the default response times for Code Suggestions, and options for streaming, prompt caching, and configuring connections.
Code Suggestions is powered by a generative AI model.
Your personal access token enables a secure API connection to GitLab.com or to your GitLab instance. This API connection securely transmits a context window from your IDE/editor to the GitLab AI Gateway, a GitLab hosted service. The gateway calls the large language model APIs, and then the generated suggestion is transmitted back to your IDE/editor.
Streaming of code generation responses is supported in JetBrains and Visual Studio, leading to perceived faster response times. Other supported IDEs will return the generated code in a single block.
Streaming is not enabled for code completion.
{{< history >}}
{{< /history >}}
Prompt caching is enabled by default on all Fireworks-hosted models to improve Code Suggestions latency.
When prompt caching is enabled, code completion prompt data is temporarily stored in memory by the model vendor.
Prompt caching significantly improves latency by avoiding the re-processing of cached prompt and input data. The cached data is never logged to any persistent storage.
You can turn off prompt caching for top-level groups in the GitLab Duo settings. This also turns off prompt caching for GitLab Duo Agentic Chat.
Prerequisites:
On GitLab.com:
On GitLab Self-Managed:
{{< history >}}
code_suggestions_direct_access. Disabled by default.{{< /history >}}
By default, code completion requests are sent from the IDE directly to the AI Gateway to minimize the latency.
For this direct connection to work, the IDE must be able to connect to https://cloud.gitlab.com:443. If this is not
possible (for example, because of network restrictions), you can disable direct connections for all users. If you do this,
code completion requests are sent indirectly through the GitLab Self-Managed instance, which in turn sends the requests
to the AI Gateway. This might result in your requests having higher latency.
Prerequisites:
{{< tabs >}}
{{< tab title="In 17.4 and later" >}}
{{< /tab >}}
{{< tab title="In 17.3 and earlier" >}}
{{< /tab >}}
{{< /tabs >}}
Because of LLM limits and performance reasons, the content of the currently opened file is truncated:
Content above the cursor is prioritized over content below the cursor. The content above the cursor is truncated from the left side, and content below the cursor is truncated from the right side. These numbers represent the maximum input context size for Code Suggestions.
Support for increasing the code generation limit is proposed in issue 585841.
Because of LLM limits and for performance reasons, the output of Code Suggestions is limited:
We are continuing to work on the accuracy of overall generated content. However, Code Suggestions might generate suggestions that are:
When using Code Suggestions, code review best practices still apply.
Provide feedback about your Code Suggestions experience in issue 435783.