Test and debug an API plugin
To test and debug an API plugin for Microsoft Copilot, you sideload the API plugin in Copilot in Bing by using https://www.bing.com/copilot/devtools. Sideloading an API plugin means temporarily adding your own plugin to Copilot in Bing, where you can then use, test, and debug your plugin, before publishing your plugin.
Sideloading an API plugin allows you to test your API plugin locally before submitting it to Partner Center to make it available to your users. When you sideload your API plugin, your API plugin is only available to you, and only temporarily. To make your API plugin available to your users, you need to publish it, as described in Publish an API plugin.
Important
These features are in Private Preview.
Manifests that use the auth
field are not supported.
This article is a continuation that builds on the tutorial Get started building an API plugin for Microsoft Copilot. The source code for the API plugin that results from following that tutorial is in the contoso-real-estate directory of the mslearn-copilot-plugins
repo.
Allow Bing to access your API plugin files
Before testing your API plugin in Copilot in Bing, you need to grant Bing access to your API plugin files. By default, the web browser that you use to load your API plugin won't allow access to your API plugin files unless you grant Bing access to the origin that hosts the files.
To allow Bing to access your API plugin files, use CORS, described at Cross-Origin Resource Sharing (CORS) at MDN. Add the Access-Control-Allow-Origin
CORS response header, with its value set to https://www.bing.com
, to your web server's responses.
If you followed the tutorial Get started building an API plugin for Microsoft Copilot, your web server uses the Express NPM package to serve your API plugin files. To add the Access-Control-Allow-Origin
CORS header to your web server's responses, use Express' CORS middleware:
In Visual Studio Code, click View > Terminal, or press CTRL + ` to open the Terminal panel.
Type
npm install cors
, and then press Enter. The Express CORS middleware package is now installed.Open the file that contains your Express server code. If you followed the Get started tutorial, this file is named
server.js
.Import the CORS middleware in the file by adding the following line of code at the top of the file:
import cors from "cors";
Configure the CORS middleware to allow access to your API plugin files, by adding the following line of code after the
app
variable is defined:app.use(cors({ origin: "https://www.bing.com" }));
Save the file.
Restart your web server. For example, in the Terminal panel, press Ctrl+C to stop the web server, type
node server.js
, and then press Enter. The server restarts.
Continue to the next section.
Make your local server accessible to the internet
If you intend to sideload an API plugin that's already deployed to a web server that's accessible from the internet, you can skip this section and go to Sideload your API plugin in Copilot in Bing, below.
If you're developing a locally hosted API plugin, your API, API specification, and manifest file are only available on your local web server, which means that Copilot in Bing can't access them.
To make your API plugin available to Copilot in Bing, for testing, it needs to be on a server that's accessible from the internet via HTTPS. If you want to continue working on your local device only, make your local web server temporarily available over the internet by using the port forwarding feature of Visual Studio Code. To learn more, see Local Port Forwarding.
To make your local server accessible to Copilot in Bing over the internet:
Make a note of the port number which your web server is using. If you followed Get started building an API plugin for Microsoft Copilot, this is
8080
.In Visual Studio Code, select View > Open view > Ports. The Ports panel appears:
Click Forward a port, enter 8080 in the Port number or address field, and then press Enter. If your web server is running on a different port number, use the port number that your web server is using.
The Forwarded address value appears:
Right-click the Forwarded address value, and then select Port visibility > Public.
Under Forwarded address, click the Copy local address () button.
Open the
openapi.yaml
file.In the file, change the
servers.url
field fromhttp://localhost:8080
to the address you just copied. The copied address should be patterned like:https://ab12c3de-8080.uks1.devtunnels.ms/
Save the file.
Continue to the next section.
Sideload your API plugin in Copilot in Bing
To sideload your API plugin in Copilot in Bing:
Go to https://www.bing.com/copilot/devtools in a new window or tab in Microsoft Edge.
Sign-in to Copilot with your personal Microsoft account (MSA). Microsoft Entra ID accounts aren't supported.
In the sidebar, click Plugins. The list of installed plugins is displayed.
Click the Test a plugin () button:
The Enter plugin URL dialog opens.
Enter the URL of the web server that hosts your API plugin files. If your web server is on your local device, make it accessible to the internet by using port forwarding. See Make your local server accessible to the internet.
Click the Find manifest file button. The Found Plugin dialog opens and displays validation information about your API plugin:
- If your API plugin was validated successfully, the API plugin title and description is displayed, and the Add plugin button appears.
- If Copilot in Bing found errors while validating your API plugin, the errors are listed in the dialog. Review the errors, correct them, and start again.
Click the Add plugin button. Copilot displays your new API plugin.
Continue to the next section.
Test your API plugin in Copilot
To test your API plugin:
Go to https://bing.com/copilot/devtools in a new window or tab of Microsoft Edge.
In the Plugins sidebar, turn on the toggle next to your API plugin, to enable it:
In the chat user interface, under Choose a conversations style, click the More Creative button. Or, click the More Precise button.
Below Choose a conversations style, click the New topic button ():
In the Ask me anything text box, type a message, such as "Properties for sale with 2 bedrooms in San Francisco", and then press Enter, or click the Submit () button.
Copilot in Bing displays a response. Depending on your question, Copilot might use your sideloaded API plugin to generate the response:
Next to Used: <Plugin name>, click the expander triangle ().
The Input and Output sections are displayed:
Use the Input and Output sections to help debug your plugin's activity.
- The Input section shows the API request that was sent to your API, which Copilot in Bing generated based on the text that you entered.
- The Output section shows the response that your API returned for this request.
See also
- Get started building an API plugin for Microsoft Copilot - a previous step.
- contoso-real-estate directory of the
mslearn-copilot-plugins
repo.
- contoso-real-estate directory of the
- Publish an API plugin - a next step.
External links:
- https://www.bing.com/copilot/devtools
- Cross-Origin Resource Sharing (CORS) - description at MDN.
- CORS - Node.js package; web framework middleware.
- Local Port Forwarding in Visual Studio Code.
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de