Chat Playground unable to understand different non-standard date formats

Fatima Masood 20 Reputation points
2024-09-02T09:39:57.5233333+00:00

hi guys, I'm currently using azure's chat playground to build a chatbot to chat with my data.

i indexed a table from my db (which is on sql server) with 12 columns. one of the columns is called DATE, which is in the date (yyyy-mm-dd) format. the issue is whenever i ask my chatbot a question related to a date which is not in that format, say i ask it: 'what's the _______ on 21st August 2024?', it gives me a response like:

"Based on the retrieved documents, there are no records of -- data for 21st August 2024. Therefore, there are no -- -- available for that date."

but when I ask it with the format "yyyy-mm-dd", it gives me the correct answer. and after that query, if i ask the same question again ( 'what's the _______ on 21st August 2024?'), it gives me the correct response.

i have already specified in the prompt/system message to check the format of the date and convert it to DATE and then check the db, but sometimes it gives me responses like "There is only data till 8th March 2024", which, is not true.

This is the part of the prompt where I ask it to change the format of the date: Your task is to retrieve all relevant data from this table based on user queries.

These are the steps you need to perform, in this order:

Step 1: When a user asks about a specific date, convert it to the yyyy-mm-dd or the DATE format before searching the table. This includes:

  • Dates in numeric format (e.g., 21 09 2024 should be converted to 2024-09-21).
  • Dates in words, including ordinal numbers and full month names (e.g., 21st September 2024 should be converted to 2024-09-21, August 21st, 2024 should be converted to 2024-08-21).

For example, if a user asks for the machine names running on 16th September 2024, convert 16th September 2024 to 2024-09-16

Always perform this step first. If a user doesn't ask a question with the date, then start from step 2.

Step 2: Search the database/index for the relevant information.

Step 3: Return the results to the user.

is there any way to fix this or check how the model is preparing its responses. any help would be appreciated.

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,916 questions
{count} votes

Accepted answer
  1. navba-MSFT 23,625 Reputation points Microsoft Employee
    2024-09-03T04:13:18.2166667+00:00

    @Fatima Masood Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    .

    • Which GPT model version are you using ?
    • Could you please review the system prompt again and ensure that you clearly call out the date format that you want to be considered ?
    • Eventually, after testing, are you planning to call the Azure OpenAI from an application? If Yes, Ensure that you have a Date Parsing Logic, which is robust enough to handle various date formats. You might want to use a library like dateutil in Python, which can parse dates in different formats. For example:
    import re
    
    from dateutil import parser
    
    def preprocess_date(input_text):
    
        # Regular expression to find dates in various formats
    
        date_patterns = [
    
            r'\b\d{1,2}(st|nd|rd|th)?\s+\w+\s+\d{4}\b',  # e.g., 21st August 2024
    
            r'\b\w+\s+\d{1,2}(st|nd|rd|th)?,\s+\d{4}\b',  # e.g., August 21st, 2024
    
            r'\b\d{1,2}/\d{1,2}/\d{4}\b',  # e.g., 21/08/2024
    
            r'\b\d{4}-\d{2}-\d{2}\b'  # e.g., 2024-08-21
    
        ]
    
        
    
        for pattern in date_patterns:
    
            match = re.search(pattern, input_text)
    
            if match:
    
                date_str = match.group()
    
                try:
    
                    # Parse the date and convert to yyyy-mm-dd format
    
                    date_obj = parser.parse(date_str)
    
                    formatted_date = date_obj.strftime('%Y-%m-%d')
    
                    input_text = input_text.replace(date_str, formatted_date)
    
                except ValueError:
    
                    continue
    
        return input_text
    
    # Example usage
    
    user_input = "What's the data for 21st August 2024?"
    
    processed_input = preprocess_date(user_input)
    
    print(processed_input)  # Output: What's the data for 2024-08-21?
    

    Hope this helps.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.