Skip to main content

OutputHandler

Trait OutputHandler 

Source
pub trait OutputHandler<O>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn response_format(&self) -> Option<ResponseFormat>;
    fn parse_complete(
        &self,
        text: &str,
        ctx: &OutputContext,
    ) -> Result<O, Error>;
    fn parse_partial(&self, text: &str) -> Option<JsonValue>;

    // Provided methods
    fn validate_configuration(&self) -> Result<(), Error> { ... }
    fn wants_output(&self) -> bool { ... }
    fn typed_partial(&self, _value: &JsonValue) -> Option<O> { ... }
    fn parse_elements(&self, _text: &str) -> Option<Vec<JsonValue>> { ... }
    fn parse_typed_elements(&self, text: &str) -> Option<O> { ... }
    fn max_elements(&self) -> Option<usize> { ... }
}
Expand description

Implements an output strategy for output type O.

Implement this to add custom strategies; the built-in ones are exposed through Output.

Required Methods§

Source

fn response_format(&self) -> Option<ResponseFormat>

The response format sent to the model.

Source

fn parse_complete(&self, text: &str, ctx: &OutputContext) -> Result<O, Error>

Parses the complete text of the final step.

§Errors

Returns Error::NoObjectGenerated when the text does not satisfy the strategy.

Source

fn parse_partial(&self, text: &str) -> Option<JsonValue>

Parses partial text during streaming; None when nothing usable is available yet.

Provided Methods§

Source

fn validate_configuration(&self) -> Result<(), Error>

Validates strategy settings before a model request is made.

§Errors

Returns an invalid-argument error when settings are contradictory.

Source

fn wants_output(&self) -> bool

Whether the call must produce an output (false only for NoOutput).

Source

fn typed_partial(&self, _value: &JsonValue) -> Option<O>

Converts a partial JSON value into the typed output when it already satisfies the schema.

Source

fn parse_elements(&self, _text: &str) -> Option<Vec<JsonValue>>

Array strategies: the complete, validated elements contained in the partial text so far.

Source

fn parse_typed_elements(&self, text: &str) -> Option<O>

Returns completed typed array elements after schema validation.

Source

fn max_elements(&self) -> Option<usize>

Maximum number of elements an array stream may publish.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§