Skip to main content

When using the Conversation with Assistant ChatGPT action with retrieval turned on, the response often contains annotations that are illegible, e.g. 【13†source】.

 

According to Open AI’s docs, there is a way to convert them to legible text in the annotations. But to see them, there’s a python code snippet they recommend:

 

# Retrieve the message object
message = client.beta.threads.messages.retrieve(
  thread_id="...",
  message_id="..."
)

# Extract the message content
message_content = message.contentm0].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' n{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)

 

Now, I’m not a coder (though ChatGPT helps me with any coding work I might come across). My question specifically within Zapier is: is there a way to use the above information (taken from the documentation here) to convert the illegible annotations to readable text annotations in our responses?