Chatgpt not able to get answer if question include "it"

chatgpt not able to get answer if question include "it " with given below code.
can anyone fix the issue or share correct code ?

User: Who won the world series in 2020?
ChatGPT: The Los Angeles Dodgers won the World Series in 2020.
User: Where was it played?
ChatGPT: Can you please clarify what you are referring to by “it”? Are you asking where a specific event or game was played? If so, please provide more details so that I can assist you further.

import openai

openai.api_key = ‘<API_KEY>’
model_id = ‘gpt-3.5-turbo’

def ChatGPT_conversation(conversation):
response = openai.ChatCompletion.create(
# api_usage = response[‘usage’]
# print(‘Total token consumed: {0}’.format(api_usage[‘total_tokens’]))
# stop means complete
# print(response[‘choices’][0].finish_reason)
# print(response[‘choices’][0].index)
conversation.append({‘role’: response.choices[0].message.role, ‘content’: response.choices[0].message.content})
return conversation

conversation =
conversation.append({‘role’: ‘system’, ‘content’: ‘How may I help you?’})
conversation = ChatGPT_conversation(conversation)
print(‘{0}: {1}\n’.format(conversation[-1][‘role’].strip(), conversation[-1][‘content’].strip()))

while True:
prompt = input(‘User:’)
conversation.append({‘role’: ‘user’, ‘content’: prompt})
conversation = ChatGPT_conversation(conversation)
print(‘{0}: {1}\n’.format(conversation[-1][‘role’].strip(), conversation[-1][‘content’].strip()))

I bet if you do a pretty print (to JSON) of the request you’re sending you’ll discover you have a bug where the past history is not being sent the way you think it is. The AI will definitely be able to know what “it” means if you’re genuinely sending the full chat history.


@wclayf i have tried to fix the issue according to you . that way i fixed the bugs. thank you so much.


Good to hear. Hope you stick around. We’ve got a great community growing here.

1 Like