I don't get an argument correctly when calling a function

Hello, this is my first time developing an assistant bot and I ran into a problem. Perhaps I have already solved it before, but I did not find the answer. The problem is that I’ve created a function and I’m waiting for the “year” or “month” that the user will specify, and when I test, I get incorrect data. Here’s my query: What are the free days this month? But in the argument I get: year: 2023, month: April. When, like now, January 2024.
I created an assistant in the office and specified the function there:

  "name": "get_free_appointments",
  "parameters": {
    "type": "object",
    "properties": {
      "year": {
        "type": "integer",
        "description": "What year does the patient want to make an appointment for? If the patient does not specify the year, it means the current year. The specified year cannot be earlier than the current one. And the year cannot be more than 1 from the current year"
      "month": {
        "type": "integer",
        "description": "For which month the patient wants to make an appointment. If the patient does not specify the month, then the month is the current month. The specified month cannot be less than the current month. And no more than 2 from the current month"
    "required": []
  "description": "Get a list of available days to record."

Then I wrote code in python to test (I think there is no need to write all the code):

data = run.required_action.submit_tool_outputs.tool_calls[0]
if data.function.name == "get_free_appointments":
	funct_id = data.id
	arguments = data.function.arguments
	args = json.loads(arguments)
	year = int(args['year'])
	month = int(args['month'])
	run = client.beta.threads.runs.submit_tool_outputs(
				"tool_call_id": funct_id,
				"output": json.dumps({
					"days": get_days(year, month)

RequiredAction(submit_tool_outputs=RequiredActionSubmitToolOutputs(tool_calls=[RequiredActionFunctionToolCall(id=‘call_CqaiRkkqNO90EnisKWzxSdqc’, function=Function(arguments=‘{“year”:2023,“month”:4}’, name=‘get_free_appointments’), type=‘function’)]), type=‘submit_tool_outputs’)
I’m writing a request: “I want to make an appointment this month”
But for some reason, I get the wrong year and month.

I use model: gpt-4-1106-preview
Code interpreter: Off
Retrieval: On
Files: no

I had similar issues, The fix is use code interpreter to find the current date and use it in a system message, so all the other functions and tools knows about it.

I did a project recently that needs date input for travel planning. Here’s my code:


1 Like

You need to append the current date time in the instruction. If you created your Assistant in the dev site (https://platform.openai.com/assistants), unfortunately you cannot do that. What you can do is to retrieve the assistant, get the instructions and append the current date and time in the instructions when you create a run.

const myAssistant = await openai.beta.assistants.retrieve(
// myAssistant.instructions <-- this

const run = await openai.beta.threads.runs.create(
        assistant_id: "asst_abc123",
        instructions: `${myAssistant.instructions}\nToday is ${new Date()}.`, // Today
1 Like

Thank you for your reply. I’ll study and try your solution

1 Like

Thank you for your reply. I’ll study and try your solution