GitHub

SocketService

API reference for SocketService.

Response streams over a WebSocket connection (Effect's OpenAiSocket): make builds it, and SocketService(create_response_stream) makes one of a function (a test double, say).

Functions

__init__

__init__(create_response_stream) -> None
ParameterTypeDescription
create_response_streamCallable[[W.CreateResponse], Effect[ResponseStream, AiError]]
def __init__(
    self,
    create_response_stream: Callable[[W.CreateResponse], Effect[ResponseStream, AiError]],
) -> None:
    self._create_response_stream = create_response_stream

create_response_stream

create_response_stream(options) -> Effect[ResponseStream, AiError]

A response stream for options, sent as a response.create message over the shared connection, one request at a time. Gives a placeholder 200 response at once, and the events, ending at a terminal event. The stream fails with an AiError: a NetworkError when the socket cannot be written or fails, or an error event's reason by its status (previous_response_not_found a 400).

ParameterTypeDescription
optionsW.CreateResponse

Returns Effect[ResponseStream, AiError]

def create_response_stream(self, options: W.CreateResponse) -> Effect[ResponseStream, AiError]:
    """A response stream for ``options``, sent as a ``response.create``
    message over the shared connection, one request at a time. Gives a
    placeholder 200 response at once, and the events, ending at a
    terminal event. The stream fails with an ``AiError``: a
    ``NetworkError`` when the socket cannot be written or fails, or an
    error event's reason by its status (``previous_response_not_found``
    a 400)."""
    return self._create_response_stream(options)