I was going to respond back here once I had it figured out for myself, but although I am getting closer I feel like every time I test a new use case I find something it fails at. My general approach has been refined to be the following steps now (thanks for the advice @joao.b and @CreatiCode!):
- Ask gpt to analyze the given input prompt for metadata that I then use to query my database. The current iteration of my prompt for this is:
const prompt = `Today is ${today} and timezone is ${tz}. Analyze the question and return a json object only, with structure:
{
"action": "ADD EVENT","REMIND","TODO","MODIFY EVENT","DELETE EVENT","CANCEL EVENT","COPY EVENT","FIND EVENT", or "UNKNOWN"
"isoDates": [],
"newIsoDates": [],
"subject": string,
"isFutureEvents": true/false,
"isPastEvents": true/false
}
List every possible date in the range implied by the question needed to find the referenced event(s), or an empty array.
Question about new or existing calendar events: ${input}`
I find I am constantly tweaking this text as I try new use cases and find things it doesn’t handle well.
- Embed the analyzed “subject” terms and query Pinecone for semantic search. At the same time, construct a query into my own regular DB using the dates and timeframes from the output of step 1, and perform a keyword search through each event returned.
- Once I have a list of possible events from step 2, run another gpt chat completion with the following prompt:
const prompt = `You are a helpful calendar assistant, and you format dates like MMM DD, YYYY, and today is ${today}, and use relative dates/times in your answer if applicable. Respond in json format { "response": text, "eventIds": [] }. You have already done a search for calendar events finding these:\n${occurrences}\nQuestion: ${input}`
- Return the response text to the user, and display the list of events from step 2 as well.
While it is starting to get more things right, I feel like there are too many times where it is flat out wrong (or sometimes makes up events out of thin air). Reducing the input calendar events to the final question where they are already pre-filtered by date or keyword has helped the most, although the trade-off is my responses come back after like 8 seconds which I feel is too long. Each gpt or embed call is averaging about 2 seconds, and then the queries to my own database is another few seconds - so it all adds up. I have doubts this is feasible as production functionality, but I am forging ahead regardless trying to solve each problem as it comes. When I do release to my users, I think I will need to caveat with “beta” and set expectations so that users don’t expect this to work great every time (and if it doesn’t work every time, who would want to use it??).
@pchan, my final prompt for your scenario works as expected:
You are a helpful calendar assistant, and you format dates like MMM DD, YYYY, and today is 2023-04-23T20:09:49.850+00:00, and use relative dates/times in your answer if applicable. Respond in json format { "response": text, "eventIds": [] }. You have already done a search for calendar events finding these:
Meet with Sam on 2023-04-25T00:00:00 with id 2023-04-25T00:00:00::bcf2a650-e039-11ed-b4fb-9530538bff0c, Tomatos on 2023-04-29T00:00:00 with id 2023-04-29T00:00:00::09bf7c40-e154-11ed-9639-47da7ae1cd1c
Question: What’s on my calendar for next week?
response:
{
"response": "You have 2 events next week:\n- Meet with Sam on Apr 25, 2023\n- Tomatos on Apr 29, 2023",
"eventIds": [
"2023-04-25T00:00:00::bcf2a650-e039-11ed-b4fb-9530538bff0c",
"2023-04-29T00:00:00::09bf7c40-e154-11ed-9639-47da7ae1cd1c"
]
}
Also note, I have not even looked at optimizing my calls for tokens/cost yet, so not even sure all this will be cost effective once it is working consistently enough. One step at a time!