For getting assistant replies in python the API reference provides this code block
# Retrieve the message object
message = client.beta.threads.messages.retrieve(
thread_id="...",
message_id="..."
)
# Extract the message content
message_content = message.content[0].text
annotations = message_content.annotations
citations = []
# Iterate over the annotations and add footnotes
for index, annotation in enumerate(annotations):
# Replace the text with a footnote
message_content.value = message_content.value.replace(annotation.text, f' [{index}]')
# Gather citations based on annotation attributes
if (file_citation := getattr(annotation, 'file_citation', None)):
cited_file = client.files.retrieve(file_citation.file_id)
citations.append(f'[{index}] {file_citation.quote} from {cited_file.filename}')
elif (file_path := getattr(annotation, 'file_path', None)):
cited_file = client.files.retrieve(file_path.file_id)
citations.append(f'[{index}] Click <here> to download {cited_file.filename}')
# Note: File download functionality not implemented above for brevity
# Add footnotes to the end of the message before displaying to user
message_content.value += '\n' + '\n'.join(citations)
However there is no mention of the message_id
elsewhere in the api referenece. Where is this message_id gotten from?
Right now I am doing the following
# Send the user's message to the Assistant
openai_client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=user_speech
)
# Run the Assistant
run = openai_client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)
# Check the Run status periodically
run_status = run.status
while run_status == 'queued' or run_status == 'in_progress':
time.sleep(2) # Wait for a second before checking again
run = openai_client.beta.threads.runs.retrieve(
thread_id=thread.id,
run_id=run.id
)
print(run)
run_status = run.status
And then run
prints as
Run(id='run_D5cqIXLRKCQhIZFlvTE3LU1h', assistant_id='...', cancelled_at=None, completed_at=1702850787, created_at=1702850785, expires_at=None, failed_at=None, file_ids=[], instructions='...', last_error=None, metadata={}, model='gpt-4-1106-preview', object='thread.run', required_action=None, started_at=1702850785, status='completed', thread_id='thread_a7T2qb7tncYplbU5j6qHteKO', tools=[])
I thought initially the message_id
might be the id
provided in the run printout but that doesn’t seem to be the case.