Skip to content

jancabala/mslearn-advanced-copilot

Open in GitHub Codespaces

Apply advanced GitHub Copilot techniques

Discover new ways to leverage advanced GitHub Copilot techniques within a Python repository to implement an interactive HTML form and an Application Programming Interface (API) endpoint. Gain more practical experience by using this repository that contains a Python Web Application that hosts a Travel Weather API.

Requirements

  1. Enable your GitHub Copilot service
  2. Open this repository with Codespaces

πŸ’ͺ🏽 Exercise

The current API is not exposing country/{country} which needs to be implemented to list cities. The route should allow only GET HTTP requests with a JSON response providing information from the historical high and low for that country, city, and given month.

As with any implementation, this addition should include at least one test function to work with the pytest runner and test framework.

πŸ›  Step 1: Add a new route

On our first exercise we will create a new route in our API. Go to the main.py file, and by using the inline chat with the following command ctrl + i (on Windows) or cmd + i(on Mac) ask GitHub Copilot to help you create a new API that shows you the cities of a country.

> Create a new route that exposes the cities of a country.

This prompt should give you something similar like this:

# Create a new route that exposes the cities of a country:
@app.get('/countries/{country}')
def cities(country: str):
    return list(data[country].keys())

Note: Try your new route and refine your prompt until the result is as desired.

πŸ”Ž Step 2: Create a test

Now that you have created a new route, let's create a test with Copilot Chat for this route that uses Spain as the country. Remember to select your code and ask Copilot Chat to help you with this specific API that we just have created.

> /tests help me to create a new test for this route that uses Spain as the country.

Copilot Chat image example

Once Copilot has helped you to create your test, try it. If this is not functioning as expected, feel free to share those details with Copilot in the chat. For example:

> This test is not quite right, it is not including cities that doesn't exist. Only Seville is part of the API.

It should give you another solution. Keep trying until you achieve the desired result.

🐍 Step 3: Use an agent to write the project

During this step we will be using an agent (workspace) to write the project documentation on how to run this project. In the GitHub Copilot Chat, we will try the following prompt:

> @workspace help me to use an agent to write the project documentation on how to run it .

Finally, verify the new endpoint is working by trying it out by going to the /docs endpoint and confirming that the endpoint shows up.

πŸš€ Congratulations, through the exercise, you haven't only used copilot to generate code but also done it in an interactive and fun way! You can use GitHub Copilot to not only generate code, but write documentation, test your applications and more.

Legal Notices

Microsoft and any contributors grant you a license to the Microsoft documentation and other content in this repository under the Creative Commons Attribution 4.0 International Public License, see the LICENSE file, and grant you a license to any code in the repository under the MIT License, see the LICENSE-CODE file.

Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.

Privacy information can be found at https://privacy.microsoft.com/en-us/

Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise.

Apply advanced GitHub Copilot techniques

Discover new ways to leverage advanced GitHub Copilot techniques within a Python repository to implement an interactive HTML form and an Application Programming Interface (API) endpoint. Gain more practical experience by using this repository that contains a Python Web Application that hosts a Travel Weather API.

Requirements

  1. Enable your GitHub Copilot service
  2. Open this repository with Codespaces

πŸ’ͺ🏽 Exercise

The current API is not exposing country/{country} which needs to be implemented to list cities. The route should allow only GET HTTP requests with a JSON response providing information from the historical high and low for that country, city, and given month.

As with any implementation, this addition should include at least one test function to work with the pytest runner and test framework.

πŸ›  Getting Started

Follow these steps to set up and run the project locally:

1. Clone the Repository

git clone https://github.com/MicrosoftDocs/mslearn-advanced-copilot.git
cd mslearn-advanced-copilot

2. Set Up the Development Environment

This project uses a Docker-based development environment. To set it up:

  1. Ensure you have Docker installed and running on your machine.
  2. Build and start the development container:
    docker-compose up --build

Alternatively, you can use GitHub Codespaces to open the project in a pre-configured environment.

3. Install Dependencies

If you're running the project locally (outside of Docker), create a virtual environment and install the dependencies:

python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
pip install -r requirements.txt

4. Run the Application

Start the FastAPI application:

uvicorn main:app --reload

The application will be available at http://127.0.0.1:8000.

5. Explore the API

Visit the API documentation at http://127.0.0.1:8000/docs to explore the available endpoints.

6. Run Tests

To ensure everything is working correctly, run the test suite:

pytest

πŸš€ Congratulations

You are now ready to use and extend the Travel Weather API!

Legal Notices

Microsoft and any contributors grant you a license to the Microsoft documentation and other content in this repository under the Creative Commons Attribution 4.0 International Public License, see the LICENSE file, and grant you a license to any code in the repository under the MIT License, see the LICENSE-CODE file.

Microsoft, Windows, Microsoft Azure and/or other Microsoft products and services referenced in the documentation may be either trademarks or registered trademarks of Microsoft in the United States and/or other countries. The licenses for this project do not grant you rights to use any Microsoft names, logos, or trademarks. Microsoft's general trademark guidelines can be found at http://go.microsoft.com/fwlink/?LinkID=254653.

Privacy information can be found at https://privacy.microsoft.com/en-us/

Microsoft and any contributors reserve all other rights, whether under their respective copyrights, patents, or trademarks, whether by implication, estoppel or otherwise.

About

No description, website, or topics provided.

Resources

License

CC-BY-4.0, MIT licenses found

Licenses found

CC-BY-4.0
LICENSE
MIT
LICENSE-CODE

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors