MCPcopy
hub / github.com/openai/openai-python / on

Method on

src/openai/resources/responses/responses.py:4413–4439  ·  view source on GitHub ↗

Adds the handler to the end of the handlers list for the given event type. No checks are made to see if the handler has already been added. Multiple calls passing the same combination of event type and handler will result in the handler being added, and called, multiple time

(
        self, event_type: str, handler: Callable[..., Any] | None = None
    )

Source from the content-addressed store, hash-verified

4411 log.warning("Failed to flush send queue after reconnect", exc_info=True)
4412
4413 def on(
4414 self, event_type: str, handler: Callable[..., Any] | None = None
4415 ) -> Union[ResponsesConnection, Callable[[Callable[..., Any]], Callable[..., Any]]]:
4416 """Adds the handler to the end of the handlers list for the given event type.
4417
4418 No checks are made to see if the handler has already been added. Multiple calls
4419 passing the same combination of event type and handler will result in the handler
4420 being added, and called, multiple times.
4421
4422 Can be used as a method (returns ``self`` for chaining)::
4423
4424 connection.on("response.audio.delta", my_handler)
4425
4426 Or as a decorator::
4427
4428 @connection.on("response.audio.delta")
4429 def my_handler(event): ...
4430 """
4431 if handler is not None:
4432 self._event_handler_registry.add(event_type, handler)
4433 return self
4434
4435 def decorator(fn: Callable[..., Any]) -> Callable[..., Any]:
4436 self._event_handler_registry.add(event_type, fn)
4437 return fn
4438
4439 return decorator
4440
4441 def off(self, event_type: str, handler: Callable[..., Any]) -> ResponsesConnection:
4442 """Remove a previously registered event handler."""

Callers

nothing calls this directly

Calls 1

addMethod · 0.80

Tested by

no test coverage detected