@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.