- Use Code Suggestions
- Best practices
- Response time
- Accuracy of results
- Progressive enhancement
- Disable Code Suggestions
- Feedback
Code Suggestions
- Introduced support for Google Vertex AI Codey APIs in GitLab 16.1.
- Removed support for GitLab native model in GitLab 16.2.
- Introduced support for Code Generation in GitLab 16.3.
- Generally available in GitLab 16.7.
- Subscription changed to require GitLab Duo Pro on February 15, 2024.
Write code more efficiently by using generative AI to suggest code while you’re developing.
With GitLab Duo Code Suggestions, you get:
- Code completion, which suggests completions to the current line you are typing.
- Code generation, which generates code based on a natural language code
comment block. Write a comment like
# Type more here
, then press Enter to generate code based on the context of your comment and the rest of your code.
Use Code Suggestions
Prerequisites:
- You must have one of the supported IDE extensions.
- Your organization must have purchased the GitLab Duo Pro add-on and assigned you a seat.
- For self-managed GitLab, you must have GitLab 16.8 or later, and have configured proxy settings.
To use Code Suggestions:
-
Author your code. As you type, suggestions are displayed. Code Suggestions provide code snippets or complete 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.
- To accept a suggestion, press Tab. To reject a suggestion, press Esc.
- To ignore a suggestion, keep typing as you usually would.
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.
Best practices
To get the best results from code generation:
- Be as specific as possible while remaining concise.
- State the outcome you want to generate (for example, a function) and provide details on what you want to achieve.
- Add additional information, like the framework or library you want to use.
- Add a space or new line after each comment. This space tells the code generator that you have completed your instructions.
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 log in, run a security scan, and review the scan results.
# Each action (log 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.
Best practice examples
For use cases and best practices, follow the GitLab Duo examples documentation.
Response time
- Code completion suggestions are usually low latency.
- For code generation:
- Algorithms or large code blocks might take more than 10 seconds to generate.
- Streaming of code generation responses is supported in VS Code, leading to faster average response times. Other supported IDEs offer slower response times and will return the generated code in a single block.
Accuracy of results
We are continuing to work on the accuracy of overall generated content. However, Code Suggestions might generate suggestions that are:
- Irrelevant.
- Incomplete.
- Results in failed pipelines.
- Potentially insecure.
- Offensive or insensitive.
When using Code Suggestions, code review best practice still applies.
Progressive enhancement
This feature is designed as a progressive enhancement to developer IDEs. Code Suggestions offer a completion if a suitable recommendation is provided to the user in a timely manner. In the event of a connection issue or model inference failure, the feature gracefully degrades. Code Suggestions do not prevent you from writing code in your IDE.
Disable Code Suggestions
To disable Code Suggestions, disable the feature in your IDE editor extension.
Disable Code Suggestions for a project
- Introduced in GitLab 16.10. This feature is an Experiment.
Prerequisites:
- You must have at least the Maintainer role in the project.
You can disable Code Suggestions for specific projects.
To do so, use the GraphQL API to update the duoFeaturesEnabled
setting in your project.
For more information on this setting, see the API documentation on the projectSettingsUpdate
mutation.
Feedback
Provide feedback about your Code Suggestions experience in issue 435783.