doc/user/gitlab_duo_chat/examples.md
{{< details >}}
{{< /details >}}
{{< collapsible title="Model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
GitLab Duo Chat can help you perform a variety of tasks, including:
The examples on this page, including the slash commands, are deliberately generic.
You might receive more useful responses from Chat by asking questions that are specific to your current goal.
For example, How does the clean_missing_data function in data_cleaning.py decide which rows to drop?.
For additional practical examples, see the GitLab Duo use cases.
The following Chat features have an agentic version which consumes GitLab Credits, and a non-agentic version that does not consume GitLab Credits:
If you have access to both Agentic Chat and Non-Agentic Chat, the default feature version depends on the tool you're using:
If you do not have access to Agentic Chat and therefore the GitLab Duo Agent Platform, the feature version defaults to the non-agentic version.
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
ai_gateway_docs_search. Enabled by default.{{< /history >}}
You can ask questions about how GitLab works. Things like:
Explain the concept of a 'fork' in a concise manner.Provide step-by-step instructions on how to reset a user's password.GitLab Duo Chat uses the GitLab documentation from the GitLab repository as source.
To keep Chat up to date with the documentation, its knowledge base is updated daily.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask about a specific GitLab issue. For example:
Generate a summary for the issue identified via this link: <link to your issue>Generate a concise summary of the current issue.How can I improve the description of <link to your issue> so that readers understand the value and problems to be solved?[!note] If the issue contains a large amount of text (more than 40,000 words), GitLab Duo Chat might not be able to consider every word. The AI model has a limit to the amount of input it can process at one time.
<i class="fa-youtube-play" aria-hidden="true"></i> For tips on how GitLab Duo Chat can improve your productivity with issues and epics, see Boost your productivity with GitLab Duo Chat.
<!-- Video published on 2024-04-17 -->{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask about a specific GitLab epic. For example:
Generate a summary for the epic identified via this link: <link to your epic>Generate a concise summary of the opened epic.What are the unique use cases raised by commenters in <link to your epic>?[!note] If the epic contains a large amount of text (more than 40,000 words), GitLab Duo Chat might not be able to consider every word. The AI model has a limit to the amount of input it can process at one time.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab about the merge request you're viewing. You can ask about:
While in the merge request, open Chat and type your question. For example:
Why was the .vue file changed?What do the reviewers say about this merge request?How can this merge request be improved?Which files and changes should I review first?{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask about a specific GitLab commit. For example:
Generate a summary for the commit identified with this link: <link to your commit>How can I improve the description of this commit?Generate a summary of the current commit.{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask about a specific GitLab pipeline job. For example:
Generate a summary for the pipeline job identified via this link: <link to your pipeline job>Can you suggest ways to fix this failed pipeline job?What are the main steps executed in this pipeline job?Generate a summary of the current pipeline job.{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask about a specific GitLab work item. For example:
Generate a summary for the work item identified via this link: <link to your work item>Generate a concise summary of the current work item.How can I improve the description of <link to your work item> so that readers understand the value and problems to be solved?[!note] If the work item contains a large amount of text (more than 40,000 words), GitLab Duo Chat might not be able to consider every word. The AI model has a limit to the amount of input it can process at one time.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to explain selected code:
Select some code in your IDE.
In GitLab Duo Chat, type /explain.
You can also add additional instructions to be considered. For example:
/explain the performance/explain focus on the algorithm/explain the performance gains or losses using this code/explain the object inheritance (classes, object-oriented)/explain why a static variable is used here (C++)/explain how this function would cause a segmentation fault (C)/explain how concurrency works in this context (Go)/explain how the request reaches the client (REST API, database)For more information, see:
In the GitLab UI, you can also explain code in:
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat questions about code by pasting that code into the Chat window. For example:
Provide a clear explanation of this Ruby code: def sum(a, b) a + b end.
Describe what this code does and how it works.
You can also ask Chat to generate code. For example:
Write a Ruby function that prints 'Hello, World!' when called.Develop a JavaScript program that simulates a two-player Tic-Tac-Toe game. Provide both game logic and user interface, if applicable.Create a regular expression for parsing IPv4 and IPv6 addresses in Python.Generate code for parsing a syslog log file in Java. Use regular expressions when possible, and store the results in a hash map.Create a product-consumer example with threads and shared memory in C++. Use atomic locks when possible.Generate Rust code for high performance gRPC calls. Provide a source code example for a server and client.{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask follow-up questions to delve deeper into the topic or task at hand. This helps you get more detailed and precise responses tailored to your specific needs, whether it's for further clarification, elaboration, or additional assistance.
A follow-up to the question Write a Ruby function that prints 'Hello, World!' when called could be:
Can you also explain how I can call and execute this Ruby function in a typical Ruby environment, such as the command line?A follow-up to the question How to start a C# project? could be:
Can you also explain how to add a .gitignore and .gitlab-ci.yml file for C#?{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
Programming languages that require compiling the source code may throw cryptic error messages. Similarly, a script or a web application could throw a stack trace. You can ask GitLab Duo Chat by prefixing the copied error message with, for example, Explain this error message:. Add the specific context, like the programming language.
Explain this error message in Java: Int and system cannot be resolved to a typeExplain when this C function would cause a segmentation fault: sqlite3_prepare_v2()Explain what would cause this error in Python: ValueError: invalid literal for int()Why is "this" undefined in VueJS? Provide common error cases, and explain how to avoid them.How to debug a Ruby on Rails stacktrace? Share common strategies and an example exception.{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
duo_additional_context and duo_include_context_file. Disabled by default.{{< /history >}}
Add repository files to your GitLab Duo Chat conversations in your supported IDE
by typing /include and choosing the files.
Prerequisites:
To do this:
/include.For example, if you are developing an e-commerce app, you can add the cart_service.py and checkout_flow.js files to Chat's context and ask:
How does checkout_flow.js interact with cart_service.py? Generate a sequence diagram using Mermaid.Can you extend the checkout process by showing products related to the ones in the user's cart? I want to move the checkout logic to the backend before proceeding. Generate the Python backend code and change the frontend code to work with the new backend.[!note] You cannot use Quick Chat to add files or ask questions about files added for Chat's context.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to refactor selected code:
/refactor.You can include additional instructions to be considered. For example:
/refactor with ActiveRecord or /refactor into a class providing static functions./refactor using mysql./refactor into a stringstream with multiple lines in C++./refactor to TypeScript./refactor improving performance./refactor avoiding memory leaks and exploits./refactor uses Repository X-Ray to deliver more accurate, context-aware suggestions.
For more information, see:
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to fix selected code:
/fix.You can include additional instructions to be considered. For example:
/fix grammar mistakes and typos./fix duplicate database inserts or /fix race conditions./fix potential bugs./fix performance problems./fix the build./fix uses Repository X-Ray to deliver more accurate, context-aware suggestions.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to create tests for the selected code:
/tests.You can include additional instructions to be considered. For example:
/tests using the Boost.test framework (C++) or /tests using Jest (JavaScript)./tests focus on extreme cases, force regression testing./tests focus on performance./tests focus on regressions and potential exploits./tests uses Repository X-Ray to deliver more accurate, context-aware suggestions.
For more information, see Use GitLab Duo Chat in VS Code.
<i class="fa-youtube-play" aria-hidden="true"></i> Watch an overview
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to create a CI/CD configuration:
Create a .gitlab-ci.yml configuration file for testing and building a Ruby on Rails application in a GitLab CI/CD pipeline.Create a CI/CD configuration for building and linting a Python application.Create a CI/CD configuration to build and test Rust code.Create a CI/CD configuration for C++. Use gcc as compiler, and cmake as build tool.Create a CI/CD configuration for VueJS. Use npm, and add SAST security scanning.Generate a security scanning pipeline configuration, optimized for Java.You can also ask to explain specific job errors by copy-pasting the error message, prefixed with Explain this CI/CD job error message, in the context of <language>::
Explain this CI/CD job error message in the context of a Go project: build.sh: line 14: go command not foundAlternatively, you can use GitLab Duo Root Cause Analysis to troubleshoot failed CI/CD jobs.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can use GitLab Duo Root Cause Analysis in GitLab Duo Chat to quickly identify and fix CI/CD job failures. It analyzes the last 100,000 characters of the job log to determine the cause of failure and provides an example fix.
You can access this feature either from the Pipelines tab in merge requests or directly from the job log.
<i class="fa-youtube-play" aria-hidden="true"></i> Watch overview
Root Cause Analysis does not support:
Provide feedback on this feature in epic 13872.
Prerequisites:
To troubleshoot a failed CI/CD job from a merge request:
To troubleshoot a failed CI/CD job from the job log:
/troubleshoot.{{< details >}}
{{< /details >}}
{{< collapsible title="Editor and model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
You can ask GitLab Duo Chat to explain a vulnerability when you are viewing a SAST vulnerability report.
For more information, see Explaining a vulnerability.
GitLab Duo Chat has a list of universal, GitLab UI, and IDE commands, each of which is preceded by a slash (/).
Use the commands to quickly accomplish specific tasks.
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
| Command | Purpose |
|---|---|
| /new | Start a new conversation, but keep the previous conversations in the chat history |
| /reset | Clear the chat window and reset the conversation |
| /help | Learn more about how GitLab Duo Chat works |
[!note] On GitLab.com, in GitLab 17.10 and later, when having multiple conversations, the
/clearand/resetslash commands are replaced by the/newslash command.
{{< details >}}
{{< /details >}}
{{< history >}}
{{< /history >}}
These commands are dynamic and are available only in the GitLab UI when using GitLab Duo Chat:
| Command | Purpose | Area |
|---|---|---|
| /summarize_comments | Generate a summary of all comments on the current issue | Issues |
| /troubleshoot | Troubleshoot failed CI/CD jobs with Root Cause Analysis | Jobs |
| /vulnerability_explain | Explain current vulnerability | Vulnerabilities |
{{< details >}}
{{< /details >}}
{{< collapsible title="Editor information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
These commands work only when using GitLab Duo Chat in supported IDEs:
| Command | Purpose |
|---|---|
| /tests | Write tests |
| /explain | Explain code |
| /refactor | Refactor the code |
| /fix | Fix the code |
| /include | Include file context <sup>1</sup> |
Footnotes: