Remove Annotations In Streaming Event

Is there a way I can remove Annotations in a streaming event so they never print out in the response?

For example, I have an Assistant up and I’m using Flask websockets. Currently this is my implementation of the stream:

    event_handler = EventHandler()

        tool_choice={"type": "file_search"},
    ) as stream:
        for text in stream.text_deltas:

The event handler Class has a method - on_text_delta()

def on_text_delta(delta, snapshot):

    config.socketio.emit('assistant_message', {'text': delta.value}

I’m emitting the value of the TextDelta, but when debugging and printing out the TextDelta stream, I see this:

TextDelta(annotations=None, value=' blank')

TextDelta(annotations=None, value=' on')

TextDelta(annotations=None, value=' the')

TextDelta(annotations=None, value=' form')

TextDelta(annotations=[FileCitationDeltaAnnotation(index=0, type='file_citation', end_index=234, file_citation=FileCitation(file_id='file-xxxxxxxxxxxxx', quote=''), start_index=222, text='【4:1†source】')], value='【4:1†source】')

TextDelta(annotations=None, value='.')

I believe the delta.value is printing out value='【4:1†source】

Is there anywhere to remove this while streaming?

1 Like

Figuring this out. Can run a regex on the delta.value during streaming through the socket emit

Thanks to a bit of insight from this post I was able to use a check in the on_text_delta method of the event handler to discard the annotations during the stream. I just checked for the existence of the annotations prop in the delta object and returned instead of passing it through to my interface