def create_thread():
config = read_config()
thread_id = config.get('thread_id')
if not thread_id:
thread = client.beta.threads.create()
thread_id = thread.id
config['thread_id'] = thread_id
write_config(config)
return thread_id
def add_user_message(content):
config = read_config()
thread_id = config.get('thread_id')
create_thread()
client.beta.threads.messages.create(
thread_id=thread_id,
role="user",
content=content
)
def initiate_run(assistant_id):
config = read_config()
thread_id = config.get('thread_id')
create_thread()
return client.beta.threads.runs.create(
thread_id=thread_id,
assistant_id=assistant_id,
instructions="If a message is sent in english, translate it into farsi, if its sent in farsi, translate it to english."
)
def wait_for_run_completion(run_id):
config = read_config()
thread_id = config.get('thread_id')
while True:
run_status = client.beta.threads.runs.retrieve(thread_id=thread_id, run_id=run_id)
if run_status.status == "completed":
break
time.sleep(1)
def get_latest_assistant_message():
config = read_config()
thread_id = config.get('thread_id')
create_thread()
response = client.beta.threads.messages.list(thread_id=thread_id, limit=1, order='desc')
messages = response.data
for message in messages:
if message.role == "assistant":
return message.content[0].text.value
return "No response from the assistant."
the AI doesn't transalte anyhthing - it doesn't follow thje set instructions why is this