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
There are always key pieces of information anyone generating code for your codebase needs to know - the technologies in use, coding standards to follow, project structure, etc. Since context is so important, as we've discussed, we likely want to ensure Copilot always has this information as well. Fortunately, we can provide this overview through the use of Copilot instructions.
4
7
5
8
## Scenario
@@ -21,8 +24,8 @@ Here are some guidelines to consider when creating a Copilot instructions file:
21
24
- languages, frameworks and libraries in use.
22
25
- required assets to be generated (such as unit tests) and where they should be placed.
23
26
- any language specific rules such as:
24
-
- utilize [type hints](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html) in Python.
25
-
- use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) rather than the `function` keyword in TypeScript.
27
+
- utilize [type hints][type-hints] in Python.
28
+
- use [arrow functions][arrow-functions] rather than the `function` keyword in TypeScript.
26
29
- 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
30
28
31
## Create a Copilot instructions file
@@ -40,8 +43,8 @@ Let's create a Copilot instructions file. We'll start by asking Copilot to gener
40
43
41
44
5. Note the function signature is similar to `def validate_dog_age(age)` without type hints.
42
45
43
-
> [!NOTE]
44
-
> Because LLMs are probabilistic rather than deterministic, the exact code will vary.
46
+
> [!NOTE]
47
+
> Because LLMs are probabilistic rather than deterministic, the exact code will vary.
45
48
46
49
6. Create a new file in the **.github** folder called **copilot-instructions.md**.
47
50
7. Add the markdown to the file necessary which provides information about the project structure and requirements:
@@ -77,8 +80,8 @@ Whenever you make a call to Copilot chat, the references dialog indicates all fi
77
80
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
78
81
```
79
82
80
-
> [!TIP]
81
-
> You can use up arrow to resend previous prompts to Copilot chat.
83
+
> [!TIP]
84
+
> You can use up arrow to resend previous prompts to Copilot chat.
82
85
83
86
4. Note the references now includes the instructions file and provides information gathered from it.
84
87
@@ -90,15 +93,23 @@ Whenever you make a call to Copilot chat, the references dialog indicates all fi
90
93
def validate_dog_age(age: int):
91
94
```
92
95
93
-
> [!NOTE]
94
-
> The exact code generated will vary, but the new Python suggestion should now utilize type hints.
96
+
> [!NOTE]
97
+
> The exact code generated will vary, but the new Python suggestion should now utilize type hints.
95
98
96
99
## Summary and next steps
97
100
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)!
101
+
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][walkthrough-next]!
99
102
100
103
## Resources
101
104
102
-
- [Adding repository custom instructions for GitHub Copilot](https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot)
105
+
- [Adding repository custom instructions for GitHub Copilot][custom-instructions]
106
+
107
+
108
+
| [← Coding with GitHub Copilot][walkthrough-previous] | [Next: Add the filter feature →][walkthrough-next] |
0 commit comments