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: docs/3-custom-instructions.md
+30-30Lines changed: 30 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ Context is key across many aspects of life, and when working with generative AI.
7
7
8
8
In this exercise, you will learn how to:
9
9
10
-
- provide Copilot with project-specific context, coding guidelines and documentation standards using custom instructions (.github/copilot-instructions.md).
10
+
- provide Copilot with project-specific context, coding guidelines and documentation standards using custom instructions `.github/copilot-instructions.md`.
11
11
- use instruction files to guide Copilot for repetitive or templated tasks.
12
12
- implement both repository-wide instructions and task-specific instructions.
13
13
@@ -17,8 +17,7 @@ As any good dev shop, Tailspin Toys has a set of guidelines and requirements for
17
17
18
18
- API always needs unit tests.
19
19
- UI should be in dark mode and have a modern feel.
20
-
- Documentation should be added to code in the form of docstrings.
21
-
- All newly created files should have a comment header describing what it does.
20
+
- Documentation should be added to code in the form of docstrings and header comments.
22
21
23
22
Through the use of instruction files you'll ensure Copilot has the right information to perform the tasks in alignment with the practices highlighted.
24
23
@@ -50,10 +49,10 @@ There are two types of instructions files:
50
49
51
50
To see the impact of custom instructions, we will start by sending a prompt with the current version of the files. We'll then make some updates, send the same prompt again, and note the difference.
52
51
53
-
1.Open the GitHub codespace if not already open.
54
-
2. Close any open files in your codespace from the previous exercises.
52
+
1.Return to your codespace.
53
+
2. Close any open files in your codespace from the previous exercises. This will ensure Copilot has the context we want it to have.
55
54
3. Open **server/routes/publishers.py**, an empty file.
56
-
4. Open **Copilot chat**.
55
+
4. Open **Copilot chat** by selecting the Copilot icon towards the top of your codespace.
57
56
5. Create a new chat session by selecting the **New Chat** button, which will remove any previous context.
58
57
59
58

@@ -72,26 +71,27 @@ To see the impact of custom instructions, we will start by sending a prompt with
72
71
9. Notice the generated code **is missing** either a docstring or a comment header - or both!
73
72
74
73
> [!IMPORTANT]
75
-
> As highlighted previously, GitHub Copilot and LLM tools are probabilistic, not deterministic. As a result, the exact code generated may vary, and there's even a chance it'll abide by our rules without us spelling it out! But to help with consistency, we should always document anything we want to ensure Copilot should understand about how we want our code generated.
74
+
> As highlighted previously, GitHub Copilot and LLM tools are probabilistic, not deterministic. As a result, the exact code generated may vary, and there's even a chance it'll abide by our rules without us spelling it out! But to aid consistency in code we should always document anything we want to ensure Copilot should understand about how we want our code generated.
76
75
77
76
## Add global standards to copilot-instructions.md
78
77
79
78
As highlighted previously, `copilot-instructions.md` is designed to provide project-level information to Copilot. Let's ensure global coding standards are documented to improve code suggestions from Copilot chat.
80
79
81
-
1. Open **.github/copilot-instructions.md**.
82
-
2. Explore the file, noting the brief description of the project and sections for `Code standards`, `Scripts` and `GitHub Actions Workflows`. These are applicable to any interactions we'd have with Copilot, are robust, and provide clear guidance on what we're doing and how we want to accomplish it.
83
-
3. Locate the `###Global language guidance` section, which should be around like 16. Note how it contains a note to use type hints. That's why we saw those in the code generated previously.
84
-
4. Add the following lines below the note about type hints to instruct Copilot to add comment headers to files and docstrings:
80
+
1. Return to your codespace.
81
+
2. Open **.github/copilot-instructions.md**.
82
+
3. Explore the file, noting the brief description of the project and sections for `Code standards`, `Scripts` and `GitHub Actions Workflows`. These are applicable to any interactions we'd have with Copilot, are robust, and provide clear guidance on what we're doing and how we want to accomplish it.
83
+
4. Locate the `### Global language guidance` section, which should be around like 16. Note how it contains a note to use type hints. That's why we saw those in the code generated previously.
84
+
5. Add the following lines of markdown right below the note about type hints to instruct Copilot to add comment headers to files and docstrings:
85
85
86
86
```markdown
87
87
- Include a comment block at the top of each new file to describe what it does
88
88
- Every function should have docstrings or the language equivalent
89
89
```
90
90
91
-
5. Close **copilot-instructions.md**.
92
-
6. Select **New Chat** in Copilot chat to clear the buffer and start a new conversation.
93
-
7. Return to **server/routes/publishers.py** to ensure focus is set correctly.
94
-
8. Send the same prompt as before to create the endpoint.
91
+
6. Close **copilot-instructions.md**.
92
+
7. Select **New Chat** in Copilot chat to clear the buffer and start a new conversation.
93
+
8. Return to **server/routes/publishers.py** to ensure focus is set correctly.
94
+
9. Send the same prompt as before to create the endpoint.
95
95
96
96
```plaintext
97
97
Create a new endpoint to return a list of all publishers. It should return the name and id for all publishers.
@@ -138,7 +138,7 @@ We want to create a new endpoint to list all publishers, and to follow the same
138
138
5. Review the following entries inside the instruction file, which includes:
139
139
140
140
- an overview of requirements, including that tests must be created, and endpoints are created in Flask using blueprints.
141
-
- a link to another the above mentioned **python-tests.instructions.md** file.
141
+
- a link to another the previously mentioned **python-tests.instructions.md** file.
142
142
- links to two existing files which follow the patterns we want - both the games blueprint and tests. Notice how these are setup as normal markdown links, allowing an instruction file to incorporate additional files for context.
143
143
144
144
6. Return to **server/routes/publishers.py** to ensure focus is set correctly.
@@ -154,41 +154,41 @@ We want to create a new endpoint to list all publishers, and to follow the same
154
154
> [!TIP]
155
155
> If the list of options is long, you can type **instructions** to filter to the Instructions option then select **Instructions**.
156
156
157
-
9. Select **flask-endpoint .github/instructions** to add the instruction file to the context.
157
+
12. Select **flask-endpoint .github/instructions** to add the instruction file to the context.
158
158
159
159

160
160
161
-
10. Send the same prompt as before to generate the desired endpoint:
161
+
13. Send the same prompt as before to generate the desired endpoint:
162
162
163
163
```plaintext
164
164
Create a new endpoint to return a list of all publishers. It should return the name and id for all publishers.
165
165
```
166
166
167
-
11. Note the **References** section, and how **games.py**, **test_games.py**, and **python-tests.instructions.md** were all included in call to Copilot.
167
+
14. Note the **References** section, and how **games.py**, **test_games.py**, and **python-tests.instructions.md** were all included in call to Copilot.
168
168
169
169

170
170
171
-
12. Copilot generates the files. Notice how it generates updates across multiple files, like **games.py** and **test_games.py**.
172
-
13. After reviewing the code, select **Keep** and **Done** in Copilot Chat to accept the changes.
173
-
14. Open a terminal window by selecting <kbd>Ctl</kbd>+<kbd>\`</kbd>.
174
-
15. Run the tests by running the script with the following command:
171
+
15. Copilot generates the files. Notice how it generates updates across multiple files, like **games.py** and **test_games.py**
172
+
16. After reviewing the code, select **Keep** and **Done** in Copilot Chat to accept the changes.
173
+
17. Open a terminal window by selecting <kbd>Ctl</kbd>+<kbd>\`</kbd>.
174
+
18. Run the tests by running the script with the following command:
175
175
176
176
```sh
177
177
./scripts/run-server-tests.sh
178
178
```
179
179
180
-
16. Ensure all tests pass. If any tests fail, feel free to prompt Copilot Chat as needed, asking it to update the code based on the error messages you see.
180
+
19. Ensure all tests pass. If any tests fail, feel free to prompt Copilot Chat as needed, asking it to update the code based on the error messages you see.
181
181
182
182
> [!TIP]
183
-
> Copy and paste the error message from the console window into the chat window to provide context!
183
+
> Copy and paste the error message from the console window into the chat window to provide context! You can also use the `@terminal /explain` directive in Copilot Chat to ask Copilot to explain the last messages received in your terminal window.
184
184
185
-
17. Once correct, and all tests pass, open the **Source Control** panel on the left of the Codespace and review the changes made by Copilot.
186
-
18. Stage the changes by selecting the **+** icon in the **Source Control** panel.
187
-
19. Generate a commit message using the **Sparkle** button.
185
+
20. Once the code is correct, and all tests pass, open the **Source Control** panel on the left of the Codespace and review the changes made by Copilot.
186
+
21. Stage the changes by selecting the **+** icon in the **Source Control** panel.
187
+
22. Generate a commit message using the **Sparkle** button.
188
188
189
-

189
+

190
190
191
-
20. Commit the changes to your repository by selecting **Commit**.
191
+
23. Commit the changes to your repository by selecting **Commit**.
0 commit comments