sp-dev-fx-webparts/samples/react-azure-openai-connector

Using Azure OpenAI Connectors API

Summary

UPDATE: I demo-ed this sample in the Community call. Recording available here: https://t.co/Ew4XSpU6Yh

This (experimental) webpart, shows how to use the new feature (in preview at the moment of building this sample) Azure OpenAI Data Connectors.

./assets/react-azure-openai-connector.gif

The webpart is calling the Azure OpenAI API, with a specific Data source configured to an existing Azure Search service that contains the Hotels index provided by Microsoft. The following screenshots shows how you can configure the connector throught the new Azure OpenAI Studio. This is NOT required for the sample, but helps to understand what the webpart is doing behind the scenes.

First, you have configured your Search service (any tier except the free one) importing the Hotels data sample provided by Microsoft

./assets/studio01.png

./assets/studio02.png

Now, from the Azure OpenAI Studio, in the Chat playground, you can configure your data connector:

./assets/studio03.png

Connect it to your Azure Search Hotels index:

./assets/studio04.png ./assets/studio05.png

Follow the assistant to create the Connector. Once is done, you can use chatGPT to find hotels using natural language:

./assets/studio06.png

The webpart offers the same functionality, showing how to call the Azure OpenAI API, with a pre-configured Data source.

Note: this is an experimental sample, based on the preview of the Azure OpenAI service, and the preview of the Data Connectors. Ensure you check the prerequisites section if you are planning to run this sample.

Used SharePoint Framework Version

version

Applies to

Prerequisites

  • Your Azure Subscription has the Azure OpenAI service available. You will see this message if you try to add Azure OpenAI service in your Subscription (follow the link in the Azure portal to request access).

Azure OpenAI Service is currently available to customers via an application form. The selected subscription has not been enabled for use of the service and does not have quota for any pricing tiers. Click here to request access to Azure OpenAI service.

  • You have created an Azure OpenAI service in your subscription (create it in a US region, as some features may not be available in other regions)
  • Grab the Azure OpenAI Key (go to your Azure OpenAI service -> Keys and Endpoint)
  • You have configured an Azure Search service with at least a Basic plan (Free tier is not working with the Azure OpenAI Connectors feature), and have deployed the "Hotels" index that is provided as sample by Microsoft.
  • Grab the Azure Search endpoint URL (you can see it in the Overview section)
  • Grab the Azure Search API key (Keys section)

Solution

Solution Author(s)
react-azure-openai-connector Luis Mañez (ClearPeople LTD)

Version history

Version Date Comments
1.0 July 26, 2023 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.


Minimal Path to Awesome

  • Install the MS Graph Toolkit for SPFx package. Follow this
  • Clone this repository
  • Ensure that you are at the solution folder
  • Edit the file Constants.ts with your values (see prerequisites section)
  • in the command-line run:
    • npm install
    • gulp serve
  • Add the webpart in the SharePoint workbench or any SharePoint page (appending ?debug=true&noredir=true&debugManifestsFile=https://localhost:4321/temp/manifests.js to the page URL)

Features

This extension illustrates the following concepts:

  • Calling Azure OpenAI completions endpoint with a configured Azure Search connector
  • Using MS Graph toolkit with the Person component
  • Multiple FluentUI components

References