Hello Deepankar,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are using the GPT-4.0 model with Azure AI Foundry and it is not connecting to the internet and is returning the wrong date and time.
By default, Azure AI Foundry does not have real-time access to the internet or the current date. However, it can be integrated with external APIs or tools to retrieve real-time data if configured accordingly. Do not rely on GPT-4.0 to infer dates, inject them explicitly since that's a common limitation.
You can do the followings to fully implement your Azure Foundry:
- Use Azure Function to get current date by creating an Azure Function that returns the current date and time in ISO format.
https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-pythonimport datetime import azure.functions as func def main(req: func.HttpRequest) -> func.HttpResponse: now = datetime.datetime.now(datetime.timezone.utc) return func.HttpResponse(now.isoformat())
- In your app logic (e.g., Python or Node.js), fetch the date from the Azure Function and prepend it to the user prompt:
https://learn.microsoft.com/en-us/training/modules/apply-prompt-engineering-azure-openai/prompt = f"Today is {current_date}. User: {user_input}"
- Use a library like Chrono (JavaScript) or dateparser (Python) to convert natural language dates into actual dates before sending to GPT.
https://github.com/sisyphsu/dateparserimport dateparser parsed_date = dateparser.parse("next Monday", settings={'RELATIVE_BASE': datetime.now()})
- Make sure the server and user time zones are aligned. Use
pytz
orzoneinfo
to convert times.from pytz import timezone manila_time = datetime.now(timezone('Asia/Manila'))
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.