The response generator is an object; you should output the selected dictionary value to a new variable.
import os, openai
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_answer(question, triples="", flag=""):
if flag == "front":
user = f"{triples}\n{question}"
else:
user = f"{question}"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
max_tokens=100,
temperature=0,
messages=[
{"role": "system", "content": "You are a helpful AI assistant"},
{"role": "user", "content": user}
]
)
content = response["choices"][0]["message"]["content"]
return str(content).strip()
print(generate_answer("How big is a banana?"))
There is also no reason with the chat models to label your question as such or ask for an answer. You also should not end with whitespace, which I fixed above.