In the previous post, we saw what is OpenAI function calling and how to use it to chat with your organization's user directory using Microsoft Graph. Please have a look at the article here: Chat with your user directory using OpenAI functions and Microsoft Graph
In this post, we will implement function calling for a very common scenario of augmenting the large language model's responses with data fetched from internet search.
Since the Large Language model (LLM) was trained with data only up to a certain date, we cannot talk to it about events which happened after that date. To solve this, we will use OpenAI function calling to call out the Bing Search API and then augment the LLM's responses with the data returned via internet search.
This pattern is called Retrieval Augmented Generation or RAG.
Let's look at the code now on how to achieve this. In this code sample I have used the following nuget packages:
The very first thing we will look at is our function definition for informing the model that it can call out to external search API to search information:In this function we are informing the LLM that if it needs to search the internet as part of providing the responses, it can call this function. The function name will be returned in the response and the relevant parameters will be provided as well.
The Bing Web Search API key can be found in the "Keys and Endpoint" section on the Azure resource:
This way, we can use Open AI function calling together with Bing Web Search API to connect our chat bot to the internet!