How to use GPT's function calling for complex sequential tasks?

249 views Asked by At

I am working on a project where the user can ask any question about their emails to a chatbot, and get an answer. I have been trying to use GPT to achieve this using a RAG (Retrieval Augmented Generation) model with the help of semantic search. However, I have noticed that the primitive chatbot I developed can answer questions such as "Did I receive an email from X" or "Do I have any payments due?" but often retrieves emails from a long time ago. The problem is that when I modify the question to state "Did I receive an email from X in the past week?", it can't retrieve the right emails because the embeddings I used do not understand "in the past week" even if I provide the current date in the query. In order to fix this and a few other problems, I want to implement a two layered system where I put all my emails in a SQL database with their message-ids, to, and from etc, choose the relevant emails from the database and then run semantic search on those to provide the final answer.

Now, my idea is to define two functions: one to generate a SQL query and retrieve emails from the database, and the other to run semantic search. I want to input these as functions to the GPT module and let it decide when it wants to call either function.

For example, if the question was "How many emails did I receive in the past week?", all it has to do is run the SQL function. If the question was "Did my credit card get approved?", it only needs to run a semantic search. However, for complex queries such as "Summarize all important emails from the past week", it first needs to run the SQL function, then semantic search for "important", and summarize. I am not sure how GPT can break it down into "retrieve emails from SQL database for the past week" and "Run semantic search to look for important emails".

I have tried running test runs with chat gpt with a prompt along the lines of "If you can't answer the question based on the given columns and their descriptions in the table, return the entire table" to see if it can figure out when to run a SQL query and when not to. But the results aren't great. And I imagine this would be even harder when all of this is integrated and it has to figure out that it needs to do things sequentially. Any help is appreciated.

0

There are 0 answers