pub struct ResponsesWebSocketSession<T = Client> { /* private fields */ }target_family=wasm only.Expand description
A stateful OpenAI Responses WebSocket session.
This session keeps track of the most recent successful response.id so later
turns can automatically chain via previous_response_id unless the request
explicitly sets a different one.
Call ResponsesWebSocketSession::close when you are finished with the
session so the websocket can complete a close handshake cleanly.
Implementations§
Source§impl<T> ResponsesWebSocketSession<T>
impl<T> ResponsesWebSocketSession<T>
Sourcepub fn previous_response_id(&self) -> Option<&str>
pub fn previous_response_id(&self) -> Option<&str>
Returns the most recent successful response.id tracked by this session.
Sourcepub fn clear_previous_response_id(&mut self)
pub fn clear_previous_response_id(&mut self)
Clears the cached previous_response_id so the next turn starts a fresh chain.
Sourcepub async fn send(
&mut self,
completion_request: CompletionRequest,
) -> Result<(), CompletionError>
pub async fn send( &mut self, completion_request: CompletionRequest, ) -> Result<(), CompletionError>
Sends a response.create event for a Rig completion request.
Sourcepub async fn send_with_options(
&mut self,
completion_request: CompletionRequest,
options: ResponsesWebSocketCreateOptions,
) -> Result<(), CompletionError>
pub async fn send_with_options( &mut self, completion_request: CompletionRequest, options: ResponsesWebSocketCreateOptions, ) -> Result<(), CompletionError>
Sends a response.create event with explicit websocket-mode options.
Sourcepub async fn next_event(
&mut self,
) -> Result<ResponsesWebSocketEvent, CompletionError>
pub async fn next_event( &mut self, ) -> Result<ResponsesWebSocketEvent, CompletionError>
Reads the next server event for the current in-flight turn.
Sourcepub async fn warmup(
&mut self,
completion_request: CompletionRequest,
) -> Result<String, CompletionError>
pub async fn warmup( &mut self, completion_request: CompletionRequest, ) -> Result<String, CompletionError>
Sends a warmup turn (generate: false) and returns the resulting response ID.
Sourcepub async fn completion(
&mut self,
completion_request: CompletionRequest,
) -> Result<CompletionResponse<CompletionResponse>, CompletionError>
pub async fn completion( &mut self, completion_request: CompletionRequest, ) -> Result<CompletionResponse<CompletionResponse>, CompletionError>
Sends a completion turn and collects the final OpenAI response.
Sourcepub async fn close(&mut self) -> Result<(), CompletionError>
pub async fn close(&mut self) -> Result<(), CompletionError>
Closes the websocket connection.
Call this when you are finished with the session so the websocket can terminate with a clean close handshake.
Trait Implementations§
Auto Trait Implementations§
impl<T = Client> !Freeze for ResponsesWebSocketSession<T>
impl<T = Client> !RefUnwindSafe for ResponsesWebSocketSession<T>
impl<T> Send for ResponsesWebSocketSession<T>where
T: Send,
impl<T> Sync for ResponsesWebSocketSession<T>where
T: Sync,
impl<T> Unpin for ResponsesWebSocketSession<T>where
T: Unpin,
impl<T> UnsafeUnpin for ResponsesWebSocketSession<T>where
T: UnsafeUnpin,
impl<T = Client> !UnwindSafe for ResponsesWebSocketSession<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more