After using the provided code int the documentation for the Assistants API streaming function calling, If the model does not choose to call the function it does not print.
The reason is here
def on_event(self, event): # Retrieve events that are denoted with 'requires_action' # since these will have our tool_calls if event.event == 'thread.run.requires_action': run_id = event.data.id # Retrieve the run ID from the event data self.handle_requires_action(event.data, run_id)
However I don’t know how to make it answer in streaming without the function call.
extend your on_event function with other events related to text response like “thread.message.created”, “thread.message.in_progress”, “thread.message.delta”, “thread.message.completed”.
thread.message.delta will contain the text chunks as it is streamed, you want this.
thread.message.completed will contain the complete text response.
Thank you! Would you give me that chunk of code please? When I try to this it prints a duplicate.
InIn San San Francisco Francisco today today, the the current current temperature temperature is is 5757°F°F… The The probability probability of of rain rain is is 66%.%.
you probably have the same code already. as for the repeating texts, it is probably something with your streaming handler unrelated to the API. try to print to console the output when you receive the delta and see if it is repeating (most probably not).