Skip to main content

decode_reply

Function decode_reply 

Source
pub fn decode_reply<W: Wire>(
    wire: &W,
    request: &Request<W>,
    mode: Mode,
    frames: impl IntoIterator<Item = W::Frame>,
) -> Result<Response<W>, ProviderError>
Expand description

One reply of wire to request, decoded from frames already in hand as a live call in mode would decode them: through the wire’s decoder, reassembler and fold, with no transport. A reply that arrives some other way, such as a batch result’s body (WireFrame::Bytes, unary) or a recorded stream, becomes an ordinary response. raw is what the wire’s reassembler rebuilds from the frames, and the request is the one sent, as Wire::encode took it.

use rig_core::completion::{CompletionRequest, CompletionResponse};
use rig_core::error::ProviderError;
use rig_core::providers::anthropic::wire::Messages;
use rig_core::wire::{Mode, WireFrame, decode_reply};

/// A batch result's body, as the reply to the `request` it answers.
fn batch_reply(
    wire: &Messages,
    request: &CompletionRequest,
    body: Vec<u8>,
) -> Result<CompletionResponse, ProviderError> {
    decode_reply(wire, request, Mode::Unary, [WireFrame::Bytes(body)])
}

§Errors

What the reply fails with when called live: a frame the decoder rejects, a provider error in the reply, or ProviderError::Truncated when the frames end before the provider ended the reply.