Implementing Azure OpenAI in C# .NET for Custom Data Integration from OneDrive, SharePoint, Azure Cognitive Search, and Blob Storage.

REDDY, REDDYVALLA NAVEENKUMAR 115 Reputation points
2023-06-23T07:00:28.24+00:00

Hi Team,

I am interested in utilizing Azure OpenAI with custom data from various sources such as OneDrive/SharePoint files, local files, Azure Cognitive Search, and Blob Storage.

While searching for information, I came across a sample on https://github.com/Azure-Samples/azure-search-openai-demo/, but it is implemented in Python. I would like to understand how this works in C# .NET. Thank you.

Microsoft 365 and Office OneDrive For business Windows
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Lewis Thrasher 20 Reputation points
    2023-07-07T14:26:16.1633333+00:00

    So for anyone still looking for this. Going through the playground and hitting "View Code" does not show the correct code that utilizes the new custom datasource. However, I was able to find the documentation on what you need to send in the REST command to get it. If you go here, https://learn.microsoft.com/en-us/azure/cognitive-services/openai/use-your-data-quickstart?source=recommendations&tabs=powershell&pivots=rest-api . This will show you the endpoint, and explain the variables needed, but the body is also incomplete in this example. It doesn't show you how to send the field mapping information. To get that I found it here. https://github.com/Azure/azure-rest-api-specs/blob/main/specification/cognitiveservices/data-plane/AzureOpenAI/inference/preview/2023-06-01-preview/inference.json . If you scroll down to line 1139 you can see an example of the full body that you need to send to the new /extensions/chat/completions endpoint. Here is the example

    {		
    		"dataSources": [
                {
                  "type": "AzureCognitiveSearch",
                  "parameters": {
                    "endpoint": "https://mysearchexample.search.windows.net",
                    "key": "***(admin key)",
                    "indexName": "my-chunk-index",
                    "fieldsMapping": {
                      "titleField": "productName",
                      "urlField": "productUrl",
                      "filepathField": "productFilePath",
                      "contentFields": [
                        "productDescription"
                      ],
                      "contentFieldsSeparator": "\n"
                    },
                    "topNDocuments": 5,
                    "queryType": "semantic",
                    "semanticConfiguration": "defaultConfiguration",
                    "inScope": true,
                    "roleInformation": "roleInformation"
                  }
                }
              ],
              "messages": [
                {
                  "role": "user",
                  "content": "Where can I find a hiking place in Seattle?"
                }
              ],
              "temperature": 0.9
    }
          
    

    I have tested this in my c# app and using postman and it is working.

    3 people found this answer helpful.

  2. Ziggy Zulueta 495 Reputation points MVP
    2023-07-01T01:46:07.46+00:00

    @REDDYVALLA NAVEENKUMAR REDDY

    Let me try to break down your question a bit: I am interested in utilizing Azure OpenAI with custom data from various sources such as OneDrive/SharePoint files, local files, Azure Cognitive Search, and Blob Storage.

    • From what we see, there is only one data source right now that you can link your Azure Open AI2

    Give this, You would have to put all your data in Azure Cognitive Search.

    Second you needed a C# implementation yes? I see two ways to do this:

    1.There is a sample code available now in the studio:

    1

    1. You can create your C# application then call the Azure OpenAI via API calls. I tested this myself via Postman. You can see a sample of the call by checking the curl

    3

    I hope this help you in your journey. Please accept this answer if this helps you.

    1 person found this answer helpful.

  3. Gabriele Simula 50 Reputation points
    2023-07-13T09:16:49.81+00:00

    for me was the URL wrong.

    I was using

    .../openai/deployments/gpt-turbo/chat/completions?api-version=2023-07-01-preview

    instead this is the right url

    .../openai/deployments/gpt-turbo/extensions/chat/completions?api-version=2023-07-01-preview


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.