You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/1-hour/3-copilot-instructions.md
+21-10Lines changed: 21 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,14 @@ There are always key pieces of information anyone generating code for your codeb
4
4
5
5
## Scenario
6
6
7
-
Before we begin bigger updates to the site with the help of Copilot, we want to ensure it has a good understanding of how we're building our application. As a result, we're going to add a Copilot instructions file to the repository.
7
+
Before we begin larger updates to the site with the help of Copilot, we want to ensure Copilot has a good understanding of how we're building our application. As a result, we're going to add a Copilot instructions file to the repository.
8
8
9
9
## Overview of Copilot instructions
10
10
11
11
Copilot instructions is a markdown file is placed in your **.github** folder. It becomes part of your project, and in turn to all contributors to your codebase. You can use this file to indicate various coding standards you wish to follow, the technologies your project uses, or anything else important for Copilot Chat to understand when generating suggestions.
12
12
13
13
> [!IMPORTANT]
14
-
> The *copilot-instructions.md* file is included in **every** call to GitHub Copilot Chat, and will be part of the context sent to Copilot. Because there is always a limited set of tokens an LLM can operate on, a large set of Copilot instructions can obscure relevant information. As such, you should limit your Copilot instructions file to project-wide information, providing an overview of what you're building and how you're building it. If you need to provide more specific information for particular tasks, you can create [prompt files](https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot?tool=vscode#about-prompt-files) as needed.
14
+
> The *copilot-instructions.md* file is included in **every** call to GitHub Copilot Chat, and will be part of the context sent to Copilot. Because there is always a limited set of tokens an LLM can operate on, a large Copilot instructions file can obscure relevant information. As such, you should limit your Copilot instructions file to project-wide information, providing an overview of what you're building and how you're building it. If you need to provide more specific information for particular tasks, you can create [prompt files](https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot?tool=vscode#about-prompt-files).
15
15
16
16
Here are some guidelines to consider when creating a Copilot instructions file:
17
17
@@ -25,18 +25,26 @@ Here are some guidelines to consider when creating a Copilot instructions file:
25
25
- use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) rather than the `function` keyword in TypeScript.
26
26
- If you notice GitHub Copilot consistently provides an unexpected suggestion (e.g. using class components for React), add those notes to the instructions file.
27
27
28
+
## Create a Copilot instructions file
29
+
28
30
Let's create a Copilot instructions file. We'll start by asking Copilot to generate a block of code, then add the instructions file, then ask the same question again to see the changes.
29
31
30
32
1. Return to your IDE with your project open.
31
-
2. Open Copilot Chat and send the following prompt:
33
+
2. Close any tabs you may have open in your IDE to ensure Copilot chat has an empty context.
34
+
3. Select the `+` icon towards the top of Copilot chat to begin a new chat.
35
+
4. Open Copilot Chat and send the following prompt:
32
36
33
37
```
34
38
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
35
39
```
36
40
37
-
3. Note the function signature is similar to `def validate_age(age)` without type hints.
38
-
4. Create a new file in the **.github** folder called **copilot-instructions.md**.
39
-
5. Add the markdown to the file necessary which provides information about the project structure and requirements:
41
+
5. Note the function signature is similar to `def validate_dog_age(age)` without type hints.
42
+
43
+
> [!NOTE]
44
+
> Because LLMs are probabilistic rather than deterministic, the exact code will vary.
45
+
46
+
6. Create a new file in the **.github** folder called **copilot-instructions.md**.
47
+
7. Add the markdown to the file necessary which provides information about the project structure and requirements:
40
48
41
49
```markdown
42
50
# Dog shelter
@@ -55,7 +63,7 @@ Let's create a Copilot instructions file. We'll start by asking Copilot to gener
55
63
- Pages should be in dark mode with a modern look and feel
56
64
```
57
65
58
-
6. **Save** the file.
66
+
8. **Save** the file.
59
67
60
68
## Watch the instructions file in action
61
69
@@ -69,22 +77,25 @@ Whenever you make a call to Copilot chat, the references dialog indicates all fi
69
77
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
70
78
```
71
79
80
+
> [!TIP]
81
+
> You can use up arrow to resend previous prompts to Copilot chat.
82
+
72
83
4. Note the references now includes the instructions file and provides information gathered from it.
73
84
74
85

75
86
76
87
5. Note the resulting Python now utilizes type hints, and the function signature will resemble the following:
> The exact code generated will vary, but the resulting Python suggestion should now utilize type hints.
94
+
> The exact code generated will vary, but the new Python suggestion should now utilize type hints.
84
95
85
96
## Summary and next steps
86
97
87
-
Given the importance of context, Copilot instructions improves the quality of suggestions, and better aligns with the desired practices you have in place. With the groundwork in place, let's [add new functionality to our website](./4-add-feature.md)!
98
+
Copilot instructions improves the quality of suggestions, and ensures better alignment with the desired practices you have in place. With the groundwork in place, let's [add new functionality to our website](./4-add-feature.md)!
0 commit comments