kindly-Help, facing issue in Assistant API function calling, not getting response

Hi I have started learning about Chat GPT APIs recently and I am very new in this, Currently I am trying 1 example where the issue is I am not getting the response from assistant rather inspite of sending the response ,assistant is asking the question again and again. I am attaching the code below ,can kindly someone let me know where I am going wrong.
If you see the o/p you can see that in message stack no response is there oly the same question is being asked, I faced similar issue with another function calling scenario as well , any help is appreciable.TIA.
Attached the screenshots


def president_home_state(president,state_options):
president str = The string name of a US President
state_options list[str] = A list of potential states that the President was born in, with one of them being correct!

    response str = The response the user chose as the correct birthplace state.

print("Hello! Let's test your knowledge of the home states of US Presidents!")
print(f"In what state was this president born: {president}\n")

for num,option in enumerate(state_options):
    print(f"Definition #{num} is: {option}")

num_choice = input("What is your choice? (Return the single number option)")

return state_options[int(num_choice)]

function_json = {'type':'function',
            'name': 'president_home_state',
                      "president": {'type':'string','description':"The name of a random US President"},
                                    'description':"A Python list of strings of US States, where one of the states is the birthplace state of the US President."}
                'required' : ["president","state_options"]


from openai import OpenAI
import time
client = OpenAI(
api_key=“key”, # Replace with your actual OpenAI API key

assistant = client.beta.assistants.create(
name=‘US Presidents Quiz Bot’,
instructions=“You help create a quiz where you give a US President and a list of birthplace states, where only one is the correct birthplace state of the president. Later you check if answers returned are correct.”,

run = client.beta.threads.runs.create(,

import time

def wait_on_run(run, thread):
while run.status == “queued” or run.status == “in_progress”:
run = client.beta.threads.runs.retrieve(,,
return run

run = wait_on_run(run,thread)


printing run status showing requires_action


import json

Extract single tool call

tool_call = run.required_action.submit_tool_outputs.tool_calls[0]
name =
arguments = json.loads(tool_call.function.arguments)

print(“Function Name:”, name)
print(“Function Arguments:”)
Function Name: president_home_state Function Arguments:

{‘president’: ‘Barack Obama’, ‘state_options’: [‘Hawaii’, ‘California’, ‘Texas’, ‘Florida’]}

response = president_home_state(arguments[‘president’],arguments[‘state_options’])

on calling the function i was asked with prompt ,
Hello! Let’s test your knowledge of the home states of US Presidents! In what state was this president born: Barack Obama Definition #0 is: Hawaii Definition #1 is: California Definition #2 is: Texas Definition #3 is: Florida

What is your choice? (Return the single number option) 1





run = client.beta.threads.runs.submit_tool_outputs(,,
“output”: json.dumps(response),

run = wait_on_run(run, thread)
#printing run status will show completed only

messages = client.beta.threads.messages.list(

for thread_message in messages:
Now I wil get the o/p again as

**Which state was Barack Obama born in? **
**A) Hawaii **
**B) California **
**C) Texas **
D) Florida