In this blog, we’ll explore how to integrate GPT into an enterprise intranet application using C#. We’ll deploy the application as an Azure Function and log the prompt and response data in MongoDB/CosmosDB for intellectual property analysis and actions. We will first utilize Azure OpenAI Cognitive Services and later implement a data loss prevention solution to safeguard private confidential information while leveraging GPT and public LLM to the company’s advantage.

Table of Contents:
  • Integrating Azure OpenAI Cognitive Services
  • Deploying the Azure Function
  • Logging Prompt and Response Data in MongoDB
  • Implementing Data Loss Prevention
  • Leveraging Public LLM for Company Advantage
  • Final Thoughts

Setting Up the Azure Function Project

To start, create a new C# project in Visual Studio or any other IDE of your choice. Make sure to have the latest .NET Core SDK installed. In this example, we’ll be using the .NET Core 6.x SDK. Create a new console application and install the necessary packages:

  • Microsoft.Azure.WebJobs
  • Microsoft.Azure.WebJobs.Extensions.Http
  • Azure.AI.OpenAI
  • MongoDB.Driver
  • MongoDB.Bson.Serialization.Attributes
  • MongoDB.Bson

Fully functional sample code can be downloaded from github

Integrating Azure OpenAI Cognitive Services

First, create an Azure account and set up a Cognitive Services resource to access the GPT API. You’ll need to obtain the API key and endpoint (ex: {account} from the Azure portal. Next, add a new class to your project to handle the interaction with the GPT API. You can use the Azure.AI.OpenAI package to make API calls. Instantiate the Azure.AI.OpenAI with your API key and endpoint, and create a method to send your intranet application prompts to the GPT API and receive responses.

After setting up the Azure Function, you can integrate GPT into your intranet application using C#. To do this, follow these steps:

  • Add the OpenAI API key to the Function App settings
  • Install the OpenAI SDK for C# via NuGet package manager
  • Create a new function in the Function App with an HTTP trigger
  • In the new function, import the OpenAI SDK and call the API to generate a response based on the input prompt

Deploying the Azure Function

To deploy your Azure Function, first, modify your project to support Azure Functions. Update the project file (.csproj) with the required dependencies and target framework. Create an Azure Function using an HTTP trigger to handle intranet application requests. In the function’s method, call the GPT API interaction method created earlier to send prompts and receive responses.

Setting up the Azure Function:

To start, you’ll need to create an Azure Function App in the Azure Portal. Follow these steps to set it up:

  • Log in to the Azure Portal (
  • Click “Create a resource” and search for “Function App”
  • Choose the subscription, resource group, name, OS, and hosting plan
  • Select “Runtime stack” as .NET
  • Click “Create” and wait for the deployment to finish

Logging Prompt and Response Data in MongoDB

For logging the data in MongoDB, first, set up a MongoDB database and collection. You can use a MongoDB Atlas cloud-based instance or an on-premises installation. Create a new class in your project to interact with the MongoDB database using the MongoDB.Driver package. In this class, create methods for connecting to the database, inserting documents, and querying data. Log the prompt and response in the MongoDB collection individually.

  • Add the MongoDB connection string to the Function App settings
  • Install the MongoDB.Driver NuGet package
  • In the function code, import the MongoDB.Driver namespace and establish a connection to the MongoDB instance

Logging Prompts and Responses:

Once connected to MongoDB, you can log the prompts and responses to a MongoDB collection:

  • Create a new MongoDB collection for storing interactions
  • In the function code, create a new document with the input prompt, generated response, and timestamp
  • Insert the document into the MongoDB collection

Implementing Data Loss Prevention

To implement a data loss prevention solution, utilize Azure’s built-in data loss prevention capabilities or integrate a third-party DLP service or use standard DLP implementation methodology. Configure the DLP solution to monitor the intranet application data flow and flag any sensitive or confidential information. Implement necessary actions based on the DLP findings, such as redacting sensitive data or blocking specific types of content from being sent to the GPT API.

To ensure the security and privacy of sensitive information, you can integrate a Data Loss Prevention (DLP) solution using Azure Cognitive Services:

  • Add the Azure Cognitive Services API key to the Function App settings
  • Install the Azure.AI.TextAnalytics NuGet package
  • In the function code, import the Azure.AI.TextAnalytics namespace and create a new instance of the TextAnalyticsClient
  • Analyze the input prompt and generated response for sensitive information using the TextAnalyticsClient
  • If sensitive information is detected, redact or mask it before logging to MongoDB

Leveraging Public LLM for Company Advantage

To take advantage of public LLM, you can configure your chatbot to access and consume publicly available language models, allowing your chatbot to benefit from the latest advances in AI. You can integrate additional AI services and tools, like sentiment analysis or natural language understanding, language translation to improve your intranet application capabilities further.


Explore options to Integrate with vector database with company private information.


Ravi Raghu

Pardha Jasti

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x