Skip to content

5. Testing Code Changes Live

We looked at how we can test and debug the chat AI application. Now let's use this in practice to test changes to our solution interactively so we can iterate faster. Leave the FastAPI dev server running - recall that it supports hot reload, so changes made to code are reflected instantly.

Sidebar: Understanding API Routes and Requests

By default, API requests are sent to a server "endpoint" (or route) that the server listens on, for incoming requests.

  • The "/" route is the default API server URL that returns a message (as a health check)
  • The "/api/create_response" route is an enhanced URL that listens for copilot requests.

Our API server is implemented in the src/api/main.py file. Let's see how it handles these requests:

  • See: @app.get("/") - requests to the default route ("/") get a "Hello World" health check message.
  • @app.put("/api/create_response") - requests to this endpoint are parsed, with query parameters extracted and passed to the get_response function (copilot), with the response then returned to the caller.

1. Code Change Options

We can think of code changes being made at different stages of the processing workflow:

  • Modify src/main.py - to change API endpoint routes or incoming request processing.
  • Modify chat_request.py - to change how the get_request workflow is orchestrated.
  • Modify chat.prompty - to change the model prompt behavior (template, configuration).

Let's try the first option, and change how an incoming API request is handled.


2. Change API handler

Let's change how the API server handles the health-check request on "/". This is a simple change that lets us validate automatic reload on the FastAPI server.

  1. Make sure the fastapi dev src/main.py command is still running
  2. Check: the browser is showing the "/" route on *.github.dev with "Hello, World"
  3. Open src/api/main.py
    • Find line 48 - should currently say: return {"message": "Hello World"}
    • Modify it to: return {"message": "Hello Microsoft AI Tour"}
  4. Return to the browser page above.
    • Check: The displayed message should have updated to "Hello Microsoft AI Tour"

CONGRATULATIONS. You just made changes & verified them live (without restarting dev server)!