Search code examples
c#openai-api

Programmatically add website content to OpenAI with C#


Our goal is to have a ChatGPT answer questions about our website's content.

We are trying to integrate something similar to a tutorial by Open IA: How to build an AI that can answer questions about your website. I've been converting the code from Python to C# and all has been pretty successful so far. In detail we are storing the files in Azure Storage blobs.

As I've gotten to the end of this, I noticed that for every question the embeddings are being sent as the context (pardon if that's not correctly worded). Our website has 5000+ pages with lots of content so I feel like this is not correct to what we want.

Is there a way in C# to give (or maybe it's called 'train') our model this data once so that questions do not need to continuously provide it for every question? We are using OpenAI and not Azure OpenAI but all the samples I find concerning using my own data are using Azure OpenAI and Azure Cognitive Search, and even then it seems like they are feeding the data for each question.

import Azure.AI.OpenAI

var apiKey = "<my api key>";
var client = new OpenAIClient(apiKey);
var prompt = "<question about website>";

var options = new ChatCompletionOptions {
    Messages = {
        new ChatMessage(ChatRole.User, prompt),
    },
    /*
    Not currently working for some reason, further inspection needed;
    - Is it because we need Azure OpenAI instead?;
    Receiving the following error:
        
        - Azure.RequestFailedException: Invalid URL (POST /v1/extensions/chat/completions)
        - Status: 404 (Not Found)


    AzureExtensionsOptions = new AzureChatExtensionsOptions {
        Extensions = {
            new Azure CognitiveSearchExtensionConfiguration {
                SearchEndpoint = new Uri("<my search url>"),
                IndexName = "<my index name>",
                SearchKey = new AzureKeyCredential("<my search key>"),
            }
        }
    }*/
};

var response = await GetChatCompletionsAsync("gpt-3.5-turbo", options);

foreach (var choice in response.Value.Choices) {
    Console.WriteLine(choice.Message.Content);
}

Solution

  • We finally applied for and started using Azure Open AI and Azure Cognitive Search. The results are huge! Results are now in 2-3 seconds.