Compartilhar via


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:

  1. In Visual Studio Code, click View > Terminal, or press CTRL + ` to open the Terminal panel.

  2. Type npm install cors, and then press Enter. The Express CORS middleware package is now installed.

  3. Open the file that contains your Express server code. If you followed the Get started tutorial, this file is named server.js.

  4. Import the CORS middleware in the file by adding the following line of code at the top of the file:

    import cors from "cors";
    
  5. 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" }));
    
  6. Save the file.

  7. 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:

  1. 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.

  2. In Visual Studio Code, select View > Open view > Ports. The Ports panel appears:

    The Ports panel in VS Code

  3. 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:

    The Ports panel in VS Code, showing the Forwarded address

  4. Right-click the Forwarded address value, and then select Port visibility > Public.

  5. Under Forwarded address, click the Copy local address (The copy local address icon) button.

  6. Open the openapi.yaml file.

  7. In the file, change the servers.url field from http://localhost:8080 to the address you just copied. The copied address should be patterned like: https://ab12c3de-8080.uks1.devtunnels.ms/

  8. 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:

  1. Go to https://www.bing.com/copilot/devtools in a new window or tab in Microsoft Edge.

  2. Sign-in to Copilot with your personal Microsoft account (MSA). Microsoft Entra ID accounts aren't supported.

  3. In the sidebar, click Plugins. The list of installed plugins is displayed.

  4. Click the Test a plugin (The Test a plugin button icon) button:

    The plugin test sidebar in Copilot in Bing

    The Enter plugin URL dialog opens.

  5. 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.

    The Enter plugin URL dialog in Copilot in Bing

  6. Click the Find manifest file button. The Found Plugin dialog opens and displays validation information about your API plugin:

    The Found plugin dialog, showing the new API plugin and the Add plugin button

    • 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.
  7. 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:

  1. Go to https://bing.com/copilot/devtools in a new window or tab of Microsoft Edge.

  2. In the Plugins sidebar, turn on the toggle next to your API plugin, to enable it:

    The Plugins sidebar, showing the new sideloaded API plugin, and the enable button next to it

  3. In the chat user interface, under Choose a conversations style, click the More Creative button. Or, click the More Precise button.

  4. Below Choose a conversations style, click the New topic button (The "New topic" button):

    The Bing Chat UI, displaying a new, empty, conversation

  5. 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 (The Submit icon) button.

    Copilot in Bing displays a response. Depending on your question, Copilot might use your sideloaded API plugin to generate the response:

    The Bing Chat UI, displaying a response from Copilot in Bing

  6. Next to Used: <Plugin name>, click the expander triangle (Expander triangle).

    The Input and Output sections are displayed:

    Expanded information showing Input and Output

    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

External links: