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§
Sourcefn response_format(&self) -> Option<ResponseFormat>
fn response_format(&self) -> Option<ResponseFormat>
The response format sent to the model.
Sourcefn parse_complete(&self, text: &str, ctx: &OutputContext) -> Result<O, Error>
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.
Sourcefn parse_partial(&self, text: &str) -> Option<JsonValue>
fn parse_partial(&self, text: &str) -> Option<JsonValue>
Parses partial text during streaming; None when nothing usable is
available yet.
Provided Methods§
Sourcefn validate_configuration(&self) -> Result<(), Error>
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.
Sourcefn wants_output(&self) -> bool
fn wants_output(&self) -> bool
Whether the call must produce an output (false only for NoOutput).
Sourcefn typed_partial(&self, _value: &JsonValue) -> Option<O>
fn typed_partial(&self, _value: &JsonValue) -> Option<O>
Converts a partial JSON value into the typed output when it already satisfies the schema.
Sourcefn parse_elements(&self, _text: &str) -> Option<Vec<JsonValue>>
fn parse_elements(&self, _text: &str) -> Option<Vec<JsonValue>>
Array strategies: the complete, validated elements contained in the partial text so far.
Sourcefn parse_typed_elements(&self, text: &str) -> Option<O>
fn parse_typed_elements(&self, text: &str) -> Option<O>
Returns completed typed array elements after schema validation.
Sourcefn max_elements(&self) -> Option<usize>
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".