Skip to content

Commit a9fcbaa

Browse files
Merge pull request #2 from dotnet-presentations/final
Final
2 parents 036c760 + 9fafef1 commit a9fcbaa

16 files changed

Lines changed: 240 additions & 128 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ You'll use GitHub Copilot's various features to enhance and complete this applic
2424
3. [Enhancing UI with Inline Chat](lab/part2-enhancing-ui.md)
2525
4. [Referencing Code Files in Chat](lab/part3-referencing-files.md)
2626
5. [Using Custom Instructions](lab/part4-custom-instructions.md)
27-
6. [Implementing Features with Copilot Edits](lab/part5-implementing-features.md)
27+
6. [Implementing Features with Copilot Agent](lab/part5-implementing-features.md)
2828
7. [Using Copilot Vision](lab/part6-copilot-vision.md)
2929
8. [Debugging with Copilot](lab/part7-debugging-with-copilot.md)
3030
9. [Commit Summary Descriptions](lab/part8-commit-summary-descriptions.md)

lab/images/1-agent.png

17.5 KB
Loading

lab/images/1-open-copilot-chat.png

500 Bytes
Loading

lab/images/3-chat.png

15.6 KB
Loading

lab/images/5-new-edits.png

10.8 KB
Loading

lab/images/5-select-sonnet.png

26.2 KB
Loading

lab/part0-exploring-codebase.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
GitHub Copilot Chat allows you to ask questions about your code and get intelligent responses.
44

5-
1. [] Open the solution in Visual Studio 2022.
6-
2. Click on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
7-
5+
1. [] Open the solution in Visual Studio 2022 if it is not already open.
6+
1. Click on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
87
![Open chat window dialog](./images/1-open-copilot-chat.png)
9-
10-
3. [] Try asking questions about the project structure:
8+
1. [] Try asking questions about the project structure:
119
- `What projects are in this solution and how do things work together?`
12-
- `What is the TinyShop application architecture?`
1310
- `How does the Products API work?`
14-
4. [] Notice how Copilot analyzes your codebase to provide contextual answers.
11+
1. [] Notice how Copilot analyzes your codebase to provide contextual answers.
1512

1613
**Key Takeaway**: GitHub Copilot Chat helps you understand unfamiliar codebases by answering questions about the project structure, architecture, and implementation details.

lab/part1-code-completion.md

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22

33
In this section, you'll use GitHub Copilot's code completion to implement API endpoints.
44

5-
> [!IMPORTANT]
6-
> For this exercise, **DO NOT** copy and paste the code snippet provided, but rather type it manually. This will allow you to experience code completion as you would if you were coding back at your desk. You'll likely see you only have to type a few characters before GitHub Copilot begins suggesting the rest.
5+
> IMPORTANT: For this exercise, **DO NOT** copy and paste the code snippet provided, but rather type it manually. This will allow you to experience code completion as you would if you were coding back at your desk. You'll likely see you only have to type a few characters before GitHub Copilot begins suggesting the rest.
76
8-
1. [] Open **ProductEndpoints.cs** in the Products project under **Endpoints** - it should be empty or contain minimal code.
9-
2. [] Begin typing a comment to describe what you want to implement:
7+
1. [] Stop debugging the appliaction if it is currently running.
8+
9+
1. [] In the Solution Explorer, in the **Products** project, open **Endpoints/ProductEndpoints.cs** - it will have a single endpoint implemented.
10+
11+
> Note: GitHub Copilot will not give code suggestions when debugging.
12+
13+
1. [] Let's implement a new **MapGet** to get product details for a specific **id**. Move our cursor and click on line 20 under the existing **/** endpoint. Text suggestion may apprear or type:
1014
```csharp
11-
group.MapGet(
15+
g
1216
```
13-
3. [] Wait for the ghost text suggestions to appear (gray text).
14-
17+
1. [] Wait for the ghost text suggestions to appear (gray text).
18+
;
1519
![Code suggestions](./images/1-ghost-text.png)
1620

17-
4. [] Press Tab to accept the suggestion or continue typing to get more specific suggestions.
21+
1. [] Press Tab to accept the suggestion or continue typing to get more specific suggestions.
1822

19-
5. [] From there Next Edit Suggetions (NES) or addtional Ghost Text suggestions will appear.
23+
1. [] From there Next Edit Suggetions (NES) or addtional Ghost Text suggestions will appear.
2024

2125
![NES showing up](./images/1-nes.png)
2226

23-
6. [] Implement the following endpoints using GitHub Copilot's suggestions:
24-
- GET product by ID
27+
1. [] We now can implement the following endpoints using GitHub Copilot:
2528
- POST to create a new product
2629
- PUT to update a product
2730
- DELETE to remove a product
2831

29-
The end code sould look similar to:
32+
- We can continue to use suggestions OR we could open GitHub Copilot Chat and work with Agent mode:
33+
- Open GitHub Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
34+
- Switch to **Agent** mode.
35+
- ![Switch to agent mode](./images/1-agent.png)]
36+
- Ask the agent: `Can you implement the rest of the endpoints for the Product API and also implement the ProductService to call these new endpoints in the Store project?`
37+
38+
The end code in **ProductEndpoints.cs** sould look similar to:
3039

3140
```csharp
3241
group.MapGet("/", async (ProductDataContext db) =>
@@ -88,20 +97,83 @@ In this section, you'll use GitHub Copilot's code completion to implement API en
8897
.Produces(StatusCodes.Status404NotFound);
8998
```
9099

91-
> [!IMPORTANT]
92-
>Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works!
100+
In the **Store** project in the solution explorer open **Services/ProductService.cs**, the code sould look similar to:
93101

94-
7. [] Try changing the variable name of **id** to `productId` in the new **MapGet** method and see Next Edit Suggestions help out.
102+
```cs
103+
using DataEntities;
104+
using System.Text.Json;
105+
106+
namespace Store.Services;
107+
108+
public class ProductService
109+
{
110+
HttpClient httpClient;
111+
public ProductService(HttpClient httpClient)
112+
{
113+
this.httpClient = httpClient;
114+
}
115+
public async Task<List<Product>> GetProducts()
116+
{
117+
List<Product>? products = null;
118+
var response = await httpClient.GetAsync("/api/Product");
119+
if (response.IsSuccessStatusCode)
120+
{
121+
var options = new JsonSerializerOptions
122+
{
123+
PropertyNameCaseInsensitive = true
124+
};
125+
126+
products = await response.Content.ReadFromJsonAsync(ProductSerializerContext.Default.ListProduct);
127+
}
128+
129+
return products ?? new List<Product>();
130+
}
131+
132+
public async Task<Product?> GetProductById(int id)
133+
{
134+
var response = await httpClient.GetAsync($"/api/Product/{id}");
135+
if (response.IsSuccessStatusCode)
136+
{
137+
return await response.Content.ReadFromJsonAsync<Product>(ProductSerializerContext.Default.Product);
138+
}
139+
return null;
140+
}
141+
142+
public async Task<bool> CreateProduct(Product product)
143+
{
144+
var response = await httpClient.PostAsJsonAsync("/api/Product", product, ProductSerializerContext.Default.Product);
145+
return response.IsSuccessStatusCode;
146+
}
147+
148+
public async Task<bool> UpdateProduct(int id, Product product)
149+
{
150+
var response = await httpClient.PutAsJsonAsync($"/api/Product/{id}", product, ProductSerializerContext.Default.Product);
151+
return response.IsSuccessStatusCode;
152+
}
153+
154+
public async Task<bool> DeleteProduct(int id)
155+
{
156+
var response = await httpClient.DeleteAsync($"/api/Product/{id}");
157+
return response.IsSuccessStatusCode;
158+
}
159+
}
160+
```
161+
162+
> NOTE: Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works!
163+
164+
1. [] Go back to **ProductEndpoints.cs**, and try changing the variable name of **id** to `productId` in the new **MapGet** method and see Next Edit Suggestions help out.
95165

96166
![NES suggestions more](./images/1-nes-2.png)
97167

98-
8. [] Try using documentation generation:
168+
1. [] Try using documentation generation:
99169
- Type `///` above a method to generate XML documentation on the **MapProductEndpoints** this can also be brought up with `Alt+/` for inline and then entering **/** which will bring up a list of commands.
100170

101171
![documentation generation by Copilot](./images/1-docs.png)
102172

103-
9. [] Test your implementation:
173+
1. [] Test your implementation:
104174
- Run the AppHost project.
105-
- Test your new endpoints.
175+
- Test your new endpoints by going to **https://localhost:7130/api/Product/1**
176+
177+
1. [] Stop debugging and close the application
106178

107179
**Key Takeaway**: GitHub Copilot can generate complete API implementations based on your comments or partial code, significantly speeding up development.

lab/part2-enhancing-ui.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22

33
Now, you'll improve the loading experience using Copilot's inline chat.
44

5-
> [!NOTE]
6-
> This exercise does supply specific prompts to type, but as part of the learning experience we encourage you to discover how to interact with Copilot. Feel free to talk in natural language, describing what you're looking for or need to accomplish.
5+
> NOTE: This exercise does supply specific prompts to type, but as part of the learning experience we encourage you to discover how to interact with Copilot. Feel free to talk in natural language, describing what you're looking for or need to accomplish.
76
8-
1. [] Open **Products.razor** in the **Store** project under **Components**.
9-
2. [] Find the "Loading..." text in the code.
10-
3. [] Select this text and right-click.
11-
4. [] Choose "Copilot > Start inline chat" or press `Alt+/`.
12-
5. [] In the inline chat, type: "What would this look like with a loading progress spinner"
7+
1. [] In the **Solution explorer** under the **Store** project open **Components/Pages/Products.razor**.
8+
1. [] Find the "Loading..." text in the code.
9+
1. [] Select this text and right-click.
10+
1. [] Choose "Ask Copilot" or press `Alt+/`.
11+
1. [] In the inline chat, type: `Update this to have a loading progress spinner`
1312

1413
![Screenshot of VS with inline chat](./images/2-inline-code.png)
1514

16-
6. [] Preview the suggestion by clicking the "Preview" button.
17-
7. [] Accept the change by clicking "Accept."
15+
1. [] Select **Tab** to accept the changes, and it should look similar to:
1816

1917
```html
2018
<div class="spinner-border text-primary" role="status">
2119
<span class="visually-hidden">Loading...</span>
2220
</div>
2321
```
24-
8. [] Run the application to see your new loading spinner in action.
22+
23+
1. [] Run the application to see your new loading spinner in action.
24+
25+
1. [] Stop debugging and close the application
2526

2627
**Key Takeaway**: Inline chat allows you to make targeted improvements to your code without leaving your editor context.

lab/part3-referencing-files.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
In this section, you'll learn how to reference existing code files in your chat conversations.
44

5-
1. [] Open **Products.razor** from the Store project.
6-
2. [] Click on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
5+
1. [] Open the **Products.razor** again from the **Store** project.
6+
1. [] Ensure that GitHub Copilto Chat is open by clicking on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
77

88
![Open chat window dialog](./images/1-open-copilot-chat.png)
9-
10-
3. [] Type: `#ProductService.cs` to reference the ProductService file.
11-
4. [] Ask: `How would I implement getting and visualizing the products in a table using the code in ProductService?`
12-
5. [] Review the code suggestion but don't implement it yet.
13-
6. [] Follow up with: `How would this look in a grid instead of a list?`
14-
7. [] Notice how Copilot can reference existing code to provide contextual suggestions.
9+
10+
1. Change the mode to `Ask`
11+
12+
![Change to chat](./images/3-chat.png)
13+
14+
1. Start a new chat by clicking the `+` icon in the top right corner of the chat window.
15+
16+
![New chat](./images/5-new-edits.png)
17+
18+
1. [] Type: `#ProductService.cs` to reference the ProductService file.
19+
1. [] Ask: `How would I implement getting and visualizing the products in a table using the code in #ProductService and the css required.`
20+
1. [] Review the code suggestion but don't implement it yet.
21+
1. [] Notice how Copilot can reference existing code to provide contextual suggestions.
1522

1623
**Key Takeaway**: Referencing files in your chat provides Copilot with the context it needs to give more accurate, project-specific suggestions.

0 commit comments

Comments
 (0)