#What does annotations mean in the output of assistants API?

1 messages · Page 1 of 1 (latest)

astral sorrel
#
{
  "object": "list",
  "data": [
    {
      "created_at": 1696995451,
      "id": "msg_abc123",
      "object": "thread.message",
      "thread_id": "thread_abc123",
      "role": "user",
      "content": [{
        "type": "text",
        "text": {
          "value": "I need to solve the equation `3x + 11 = 14`. Can you help me?",
          "annotations": []
        }
          }],
        ...
rough valveBOT
#

Hi @astral sorrel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

In the output of the Assistants API, the annotations field within the content array of the message object provides additional information about the text in the message.

There are two types of annotations:

  1. file_citation: These are created by the retrieval tool and define references to a specific quote in a specific file that was uploaded and used by the Assistant to generate the response.

  2. file_path: These annotations are created by the code_interpreter tool and contain references to the files generated by the tool.

When annotations are present in the Message object, you'll see model-generated substrings in the text that you should replace with the annotations. These strings may look something like 【13†source】 or sandbox:/mnt/data/file.csv.

Here’s an example python code snippet that replaces these strings with information present in the annotations:

# 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}]')

For more details, you can refer to the OpenAI API documentation (https://platform.openai.com/docs/api-reference) and the OpenAI Assistants documentation (https://platform.openai.com/docs/assistants/how-it-works).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: