Skip to content

Commit 180c33c

Browse files
committed
Refine Copilot instructions for clarity and consistency in the 1-hour guide
1 parent 7324efd commit 180c33c

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

content/1-hour/3-copilot-instructions.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ There are always key pieces of information anyone generating code for your codeb
44

55
## Scenario
66

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.
88

99
## Overview of Copilot instructions
1010

1111
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.
1212

1313
> [!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).
1515
1616
Here are some guidelines to consider when creating a Copilot instructions file:
1717

@@ -25,18 +25,26 @@ Here are some guidelines to consider when creating a Copilot instructions file:
2525
- use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) rather than the `function` keyword in TypeScript.
2626
- If you notice GitHub Copilot consistently provides an unexpected suggestion (e.g. using class components for React), add those notes to the instructions file.
2727

28+
## Create a Copilot instructions file
29+
2830
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.
2931

3032
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:
3236

3337
```
3438
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
3539
```
3640
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:
4048
4149
```markdown
4250
# Dog shelter
@@ -55,7 +63,7 @@ Let's create a Copilot instructions file. We'll start by asking Copilot to gener
5563
- Pages should be in dark mode with a modern look and feel
5664
```
5765
58-
6. **Save** the file.
66+
8. **Save** the file.
5967
6068
## Watch the instructions file in action
6169
@@ -69,22 +77,25 @@ Whenever you make a call to Copilot chat, the references dialog indicates all fi
6977
Create a Python function to validate dog age. Ensure age is between 0 and 20. Throw an error if it is outside this range.
7078
```
7179
80+
> [!TIP]
81+
> You can use up arrow to resend previous prompts to Copilot chat.
82+
7283
4. Note the references now includes the instructions file and provides information gathered from it.
7384
7485
![Screenshot of the chat window with the references section expanded displaying Copilot instructions in the list](./images/copilot-chat-references.png)
7586
7687
5. Note the resulting Python now utilizes type hints, and the function signature will resemble the following:
7788
7889
```python
79-
def validate_age(age: Union[int, float, str]) -> float:
90+
def validate_dog_age(age: int):
8091
```
8192
8293
> [!NOTE]
83-
> 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.
8495
8596
## Summary and next steps
8697
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)!
8899
89100
## Resources
90101

0 commit comments

Comments
 (0)