Function calling: OpenAi guesses on current date even if told not to

Model: “gpt-4-0125-preview”

I’m experimenting with function calling and I have defined a couple of functions:

  1. GetCurrentDateTime returns the current date / time in RFC3339 format
  2. GetPricesForMeteringPoint takes two parameters, one is the date to return prices for

In the system prompt I have included this information “Don’t guess what date it is today. Call a function to get the current date / time.”

The problem is that sometimes it calls the function to get the current date / time, but sometimes it just guesses a date. I have set Temperature to 0.0 for testing this.

Run 1 (correctly calling GetCurrentDateTime):

Q: What are my prices for grid rent?
Thinking…
GetChatCompletionsAsync completed in 5.1556814s. PromptTokens=1101 CompletionTokens=37 TotalTokens=1138.

A: To provide you with accurate information about your grid rent prices, I need the unique identifier for your electricity metering point. Could you please provide me with your metering point ID?

Q: X
Thinking…
GetChatCompletionsAsync completed in 3.0439931s. PromptTokens=1111 CompletionTokens=14 TotalTokens=1125.

[ Calling function GetCurrentDateTime() ]
[ Adding the result from the function call (20 bytes) to the chat context. ]
Thinking…
GetChatCompletionsAsync completed in 5.8911798s. PromptTokens=1129 CompletionTokens=35 TotalTokens=1164.

[ Calling function GetPricesForMeteringPoint(“X”, “2024-03-06”) ]
[ Adding the result from the function call (29138 bytes) to the chat context. ]
Thinking…
GetChatCompletionsAsync completed in 27.4985586s. PromptTokens=9693 CompletionTokens=237 TotalTokens=9930.

Run 2: (guessing date):

Q: What are my prices for grid rent?
Thinking…
GetChatCompletionsAsync completed in 6.5411176s. PromptTokens=1101 CompletionTokens=37 TotalTokens=1138.

A: To provide you with accurate information about your grid rent prices, I need the unique identifier for your electricity metering point. Could you please provide me with your metering point ID?

Q: X
Thinking…
GetChatCompletionsAsync completed in 5.1242311s. PromptTokens=1111 CompletionTokens=35 TotalTokens=1146.

[ Calling function GetPricesForMeteringPoint(“X”, “2023-04-14”) ]
[ Adding the result from the function call (29020 bytes) to the chat context. ]
Thinking…
GetChatCompletionsAsync completed in 50.6275093s. PromptTokens=9621 CompletionTokens=467 TotalTokens=10088.

How can I get it to always call GetCurrentDateTime and avoid the guessing?

I would recommend :

  • Avoid using “negative sentences” in your prompt :
    Instead of saying “Don’t guess what date it is today. Call a function to get the current date / time.” => “Only call a tool when you are 100% sure you need to call it and have the required parameters to call it.”

  • Update you GetPricesForMeteringPoint method to to default to today’s date if no date is specified (or remove completely the date param from GetPricesForMeteringPoint if you always want the method to use the current date)

def GetPricesForMeteringPoint(X, date=None): 
    if date is None:
        date = GetCurrentDateTime()
  • Modify the json of the GetPricesForMeteringPoint tool to make it more understandable for the assistant how he should use it and when.
2 Likes

It seems like it would be less tokens and less work to just inject the session start time and date and the current time and date into the system message. And far less tokens than to specify a function all the time and then run a second call only adding that time.

This will also help when you offer a knowledge cutoff date in knowing when something is impossible to answer.

Prior:

2 Likes

Thanks! Inserting current date / time in the system prompt worked very well.

I’m experiencing the same problem (calling my function for the current date and time) even with the latest GPT-4o. Are you injecting the date & time with every request or just at the beginning of the session? In my case, the conversation can be long, and in certain situations, the model has to know the current date & time (time is important too).