pub trait ResponseAdapter {
// Required methods
fn __str__(&self) -> String;
fn is_empty(&self) -> bool;
fn to_bound_py_object<'py>(
&self,
py: Python<'py>,
) -> Result<Bound<'py, PyAny>, TypeError>;
fn id(&self) -> &str;
fn to_message_num(&self) -> Result<Vec<MessageNum>, TypeError>;
fn usage<'py>(
&self,
py: Python<'py>,
) -> Result<Bound<'py, PyAny>, TypeError>;
fn get_content(&self) -> ResponseContent;
fn get_log_probs(&self) -> Vec<TokenLogProbs>;
fn structured_output<'py>(
&self,
py: Python<'py>,
output_type: Option<&Bound<'py, PyAny>>,
) -> Result<Bound<'py, PyAny>, TypeError>;
fn structured_output_value(&self) -> Option<Value>;
fn tool_call_output(&self) -> Option<Value>;
fn response_text(&self) -> String;
}Required Methods§
Sourcefn to_bound_py_object<'py>(
&self,
py: Python<'py>,
) -> Result<Bound<'py, PyAny>, TypeError>
fn to_bound_py_object<'py>( &self, py: Python<'py>, ) -> Result<Bound<'py, PyAny>, TypeError>
Converts the response to a Python object
Sourcefn to_message_num(&self) -> Result<Vec<MessageNum>, TypeError>
fn to_message_num(&self) -> Result<Vec<MessageNum>, TypeError>
Converts the response to a vector of MessageNum
fn usage<'py>(&self, py: Python<'py>) -> Result<Bound<'py, PyAny>, TypeError>
Sourcefn get_content(&self) -> ResponseContent
fn get_content(&self) -> ResponseContent
Retrieves the first content choice from the response
Sourcefn get_log_probs(&self) -> Vec<TokenLogProbs>
fn get_log_probs(&self) -> Vec<TokenLogProbs>
Retrieves the log probabilities from the response
Sourcefn structured_output<'py>(
&self,
py: Python<'py>,
output_type: Option<&Bound<'py, PyAny>>,
) -> Result<Bound<'py, PyAny>, TypeError>
fn structured_output<'py>( &self, py: Python<'py>, output_type: Option<&Bound<'py, PyAny>>, ) -> Result<Bound<'py, PyAny>, TypeError>
Returns the structured output of the response For all response types the flow is as follows:
- Check if the response has content (string/text)
- If no content, return Python None
- If content exists, check if an output_type/model is provided
- If output_type/model is provided, attempt to convert the content to that type
- If conversion fails, attempt to construct a generic Python object from the content
- If no output_type/model is provided, return the content as a generic Python object
§Arguments
py: The Python GIL tokenoutput_type: An optional Python type/model to convert the content into. This can be a pydantic model or any object that implements model_validate_json that can parse from a JSON string.
§Returns
Result<Bound<'py, PyAny>, TypeError>: The structured output as a Python object or an error
Sourcefn structured_output_value(&self) -> Option<Value>
fn structured_output_value(&self) -> Option<Value>
Returns the structured output value as a serde_json::Value
Sourcefn tool_call_output(&self) -> Option<Value>
fn tool_call_output(&self) -> Option<Value>
Returns any tool calls made in the response, if applicable
Sourcefn response_text(&self) -> String
fn response_text(&self) -> String
Returns the output text of the response if available