In this lab, you'll configure the metadata for your Copilot extension to enable it to understand and process the delete function. This will be done by mapping the implementation of the delete functionality from your API into the metadata that Copilot requires.
Before we begin, let's add some items to the shopping list through the chat window by interacting with the configured agent.
- Open the GitHub Copilot Chat panel by clicking the Copilot icon at the bottom-right of any page on GitHub.com.
- Invoke your extension by typing
@EXTENSION-NAME
, replacing any spaces in the name with hyphens. - In the chat window, ask your Copilot agent to add something to the shopping list. For example:
- Verify that the item has been added successfully by reviewing the response in the chat window.
To enable Copilot to process deletion requests, we will need to look at the existing delete function which has been implemented and turn that into the metadata that Copilot can understand.
-
Open the
client.js
file in your repository. -
Locate the function responsible for deleting items from the shopping list. The code should resemble something like this:
async function deleteShoppingListItem(id) { const url = `${baseurl}/items/${JSON.parse(id).id}` // implementation }
-
Now, navigate to
functionMappings.js
. This is where you will configure the metadata for your Copilot extension. -
Add a new entry for the delete function, mapping it to the functionality defined in
client.js
. The structure should define how Copilot can understand and invoke this action. For example:{ type: 'function', title: 'Delete an item from the shopping list', description: 'This item will remove ID {id} from the shopping list.', requiresConfirmation: true, function: { name: 'deleteShoppingListItem', parameters: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] } } }
title
,description
, functionname
andparameters
are the fields that you need to pay attention to.requiresConfirmation
is a boolean that indicates if the function requires a confirmation from the user before being invoked and should be used for all destructuve operations. -
Save your changes to
functionMappings.js
.
Now that you've configured the metadata for the delete function, it's time to test it in the chat window.
-
Open the GitHub Copilot Chat panel again.
-
Invoke your extension by typing
@EXTENSION-NAME
. -
Ask Copilot to delete the item you added earlier. For example:
"@shopping-list-agent Delete the apples from the shopping list."
-
Verify that Copilot processes the request and removes the item from the list.
-
If the item is successfully deleted, your metadata is correctly configured, and Copilot can now handle delete actions.
In this lab, you've enabled your Copilot extension to understand the delete function by:
- Translating the delete functionality from
client.js
into metadata infunctionMappings.js
. - Testing the delete functionality via the chat window.
Now that you've successfully completed this task, you can move on to the next lab to extend the capabilities of your Copilot extension further.
Continue to Lab 3.2 - Integrating with the Shopping List API's Update Endpoint