How to correctly process time references like "tomorrow"?


I have created different assistants with custom functions, which I use with my local python script to process and forward to a booking service via API.
The assistant and the function calling all works well. The major problem I have is with time statements like “book an appointment for tomorrow at 1 o’clock”. the time of 1 PM is always understood. The problem lies with “tomorrow” or anything abstract like today, next Monday, whatever. Inherently, the GPT does not have this data in its training model and it does not have access to real time data.

has anyone found a way to correctly process user input for timings like this? I dont want to force the user to say “I want to book an appointment on Jan 5th, 2024 at 1 PM”. this is not intuitive or conversantional. Also, I dont want the user to receive a dumb link to be forwarded to and make the appointment there. this breaks the media in which the user is. it should be an end-to-end experience.

even GPT version 4 does not handle this in any accurate fashion.

any hints are appreciated.

You may have to code these specific things directly, and then weave them back into the prompt.

For example, you compute “tomorrow” as: + datetime.timedelta(days=1)

and then you format it to your satisfaction, then provide this in the prompt for the LLM to use.

I think I would first establish a knowledge of date formats employed, along with injection of session start and current time, and user locale and UTC offset.

Then you have to make understanding of dates clear.

Date formats - making their output and understanding predictable

There are multiple worldwide schemas of date that the language model may have been trained on, so discovering the day that comes after 08/08/2023 may be quite a difficult task to predict.

I would specify particular things the AI needs to know in system prompt description or in clear function parameter descriptions, such as the below prompt enhancement, which may be good to reinforce for any date-based AI application:

[Date input/output format]
Preferred: September 14, 2023
Compact: 14-Sep-2023
API: “09/14/2023”
Scheduling: “09/14/2023 14:30”

Having that, you can clean the multiple examples of time from your function that are ripe for confusion, and just concentrate on specifying where the date should come from that it will put in the function, and its use.

Understanding user’s ambigous dates

And then comes the logic: "Do you have any appointments available two weeks from now? It has to have a calendar, understand the starting and ending days of the week, be able to calculate date ranges, etc – all from prediction of the most likely word that should be output.

Functions for calculating common terms

Priming it with features it is lacking in mental abilities, a “print_calendar” function, a “days_between_dates” calculator, a “next week’s dates” function, etc can both enhance (and confuse) the AI.

(mostly cut and paste from a previous answer of mine, to show “has anyone found a way”)

Ok, instead of getting parts of the prompt and programming the logic into this myself, I tried injecting the current date at the very start of a thread as context information. first tests are promising. I need to integrate this into my final solution to see if it would still work, but it seems to be an elegant way to still leverage LLM capabilities without having to create custom logic and cover all possible use cases of what users may put into their prompts.