Hello - i try to answer a question about an excel-sheet using the following code. My problem is that the answer (YES or NO) seems to be randomly outputted - so when i run the program serveral times i have sometime YES as answer and sometime NO as answer…
How could this be?
Is my prompt not optimal or why is this not allways working?
import os
import sys
from dotenv import load_dotenv
from openai import OpenAI
path = os.path.abspath(os.path.dirname(sys.argv[0]))
fn = os.path.join(path, "gpp", "FILES", "env.env")
load_dotenv(fn)
CHATGPT_API_KEY = os.environ.get("CHATGPT_API_KEY")
client = OpenAI(api_key = CHATGPT_API_KEY)
fn = os.path.join(path, "gpp", "FILES", "test.xlsx")
file = client.files.create(
file=open(fn, "rb"),
purpose='assistants'
)
assistant = client.beta.assistants.create(
instructions="You are a machine learning researcher, answer questions about the data in the excel-sheet. Answer only with YES or NO and nothing else",
model="gpt-4o",
tools=[{"type": "code_interpreter"}],
tool_resources={
"code_interpreter": {
"file_ids": [file.id]
}
}
)
print(f"Preparing thread")
thread = client.beta.threads.create()
print(f"Preparing question")
results = client.beta.threads.messages.create(
thread_id = thread.id,
role = "user",
content = "Is Methylene Chlorid in the excel-sheet?"
)
print(f"Running for answer")
run = client.beta.threads.runs.create (
thread_id = thread.id,
assistant_id = assistant.id
)
while run.status not in ["completed", "failed"]:
run = client.beta.threads.runs.retrieve (
thread_id = thread.id,
run_id = run.id
)
if run.status == "completed":
results = client.beta.threads.messages.list(
thread_id=thread.id
)
print((results.data[0].content[0].text.value))