Skip to content

Commit b8466b1

Browse files
committed
Refactor setup documentation and enhance project exploration guide
1 parent 92c9a46 commit b8466b1

File tree

10 files changed

+277
-239
lines changed

10 files changed

+277
-239
lines changed

content/1-hour/0-setup.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ With the repository created, it's now time to clone the repository locally. We'l
4242

4343
5. Start the application by running the following command:
4444

45+
```sh
46+
./scripts/start-app.sh
47+
```
48+
49+
The startup script will start two applications:
50+
51+
- The backend Flask app on [localhost:5100](http://localhost:5100). You can see a list of dogs by opening the [dogs API](http://localhost:5100/api/dogs).
52+
- The frontend Astro/Svelte app on [localhost:4321](http://localhost:4321). You can see the [website](http://localhost:4321) by opening that URL!
53+
54+
## Open your editor
55+
56+
With the code cloned locally, and the site running, let's open the codebase up in VS Code.
57+
58+
1. Open VS Code.
59+
2. Select **File** > **Open Folder**.
60+
3. Navigate to the folder which contains the project you cloned earlier in this exercise.
61+
4. With the folder highlighted, select **Open folder**.
62+
4563
## Summary and next steps
4664
47-
You've now created the repository you'll use for this workshop! Next let's [enable Code Scanning](1-code-scanning.md) to secure the code we write.
65+
You've now cloned the repository you'll use for this workshop and have your IDE setup! Next let's [add a new endpoint to the server](./1-add-endpoint.md)!

content/1-hour/1-add-endpoint.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Coding with GitHub Copilot
2+
3+
There are two main interfaces to GitHub Copilot - Chat and code completion. Code completion allows you to get suggestions in your code editor while you're coding. This can turn comments into code, and function signatures into full blocks of code. Code completion helps reduce the amount of boilerplate code and ceremony you need to type, allowing you to focus on the important aspects of what you're creating.
4+
5+
## Scenario
6+
7+
It's standard to work in phases when adding functionality to an application. Given that we know we want to allow users to filter the list of dogs based on breed, we'll need to add an endpoint to provide a list of all breeds. Later we'll add the rest of the functionality, but let's focus on this part for now.
8+
9+
## Flask routes
10+
11+
While we won't be able to provide a full overview of [routing in Flask](https://flask.palletsprojects.com/en/stable/quickstart/#routing), they are defined by using the Python decorator `@app.route`. There are a couple of parameters you can provide to `@app.route`, including the path (or URL) one would use to access the route (such as **api/breeds**), and the [HTTP method(s)](https://www.w3schools.com/tags/ref_httpmethods.asp) which can be used.
12+
13+
## Code completion
14+
15+
Code completion predicts the next block of code you're about to type based on the context Copilot has. For code completion, this includes the file you're currently working on and any tabs open in your IDE.
16+
17+
Code completion is best for situations where you know what you want to do, and are more than happy to just start writing code with a bit of a helping hand along the way. Suggestions will be generated based both on the code you write (say a function definition) and comments you add to your code.
18+
19+
> [!NOTE]
20+
> We don't provide specific prompts to use with Copilot, as part of the learning experience is to discover how to interact with Copilot. If you are unfamiliar with Flask or how to add routes, you can look at the routes defined above for inspiration, or ask Copilot chat for guidance!
21+
22+
## Create the breeds endpoint
23+
24+
Let's build our new route in our Flask backend with the help of code completion.
25+
26+
1. Return to your codespace, or reopen it by navigating to your repository and selecting **Code** > **Codespaces** and the name of your codespace.
27+
2. Open **server/app.py**.
28+
3. Locate the comment which reads `## HERE`, which should be at line 68. Delete the comment to ensure there isn't any confusion for Copilot, and leave you're cursor there.
29+
4. Add the route which will call the database to find all breeds, and returns a JSON array with their names and IDs. If you begin typing `@app.route` or add a comment with the requirements like `# Route to get all breeds`, you should notice italicized text generated by GitHub Copilot.
30+
5. Select <kbd>Tab</kbd> to accept the code suggestion.
31+
32+
The code generated should look a little like this:
33+
34+
```python
35+
@app.route('/api/breeds', methods=['GET'])
36+
def get_breeds():
37+
# Query all breeds
38+
breeds_query = db.session.query(Breed.id, Breed.name).all()
39+
40+
# Convert the result to a list of dictionaries
41+
breeds_list = [
42+
{
43+
'id': breed.id,
44+
'name': breed.name
45+
}
46+
for breed in breeds_query
47+
]
48+
49+
return jsonify(breeds_list)
50+
```
51+
52+
> [!IMPORTANT]
53+
> 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!
54+
55+
6. Save **app.py**
56+
57+
58+
## Validate the endpoint
59+
60+
With the code created and saved, let's quickly validate the endpoint to ensure it works.
61+
62+
1. Navigate to [http://localhost:5100/api/breeds](http://localhost:5100/api/breeds) to validate the route. You should see JSON displayed which contains the list of breeds!
63+
64+
## Summary and next steps
65+
66+
You've added a new endpoint with the help of GitHub Copilot! Let's start down the path of performing more complex operations by [exploring our project](./2-explore-project.md).
67+
68+
## Resources
69+
70+
- [Code suggestions in your IDE with GitHub Copilot](https://docs.github.com/en/copilot/using-github-copilot/getting-code-suggestions-in-your-ide-with-github-copilot)
71+
- [Code completions with GitHub Copilot in VS Code](https://code.visualstudio.com/docs/copilot/ai-powered-suggestions)
72+
- [Prompt crafting](https://code.visualstudio.com/docs/copilot/prompt-crafting)

content/1-hour/1-context.md

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)