Fetch realtime data based on user question and get response from OpenAI based on fetched data

I have a tour booking system, and I’ve created a chatbot using OpenAI. Here are the key points in my approach:

  • I have fine-tuned it with my Q&A data.
  • I am also using embeddings to provide context with questions, which I have stored in some JSON files.
  • Additionally, I need to pass dynamic data to my model, such as tour-related information like available tours, prices, and multiple-person packages. I can obtain this data by calling an API. Since this data could change frequently, I cannot store it as embedded data.

I am currently facing a problem with the third point. How can I fetch data from the API based on the user’s query (human question) and pass it to OpenAI to generate an appropriate answer for the user?

I have attempted to use LangChain for interacting with APIs. You can find more information about LangChain at the following source: Interacting with APIs | 🦜️🔗 Langchain

What LangChain is doing is something like the following: When I ask a question about something, it randomly generates filter/query parameters, as shown in the examples below. However, the API query parameters are fixed.

For example, when I ask the question: “Do you have any tour plans for India?” LangChain attempts to query the API like this:

And when I ask the question: “Do you have any tour plans for India in December 2023?” LangChain generates the API call like this:

I would greatly appreciate any assistance with this issue. Thank you in advance.

Did you consider function calling? (or an “instruction-based” alternative)

Is it possible to solve this with Function calling?
There is a requirements that we need to make filter params from user question(natural language). then call the api with those params. How can i do this part with function calling ?

I might be missing something about your exact usecase, but in general this is how function calling works- you describe a function along with its parameters in the prompt and your response will include how this function should be called (with what parameters of course), if relevant.

See official documentation.

*You’re welcome to check out Promptotype to test out functions in a playground (full disclosure: a product created by me).