(
response_codec: Option<&Bound<'_, PyAny>>,
)
| 49 | } |
| 50 | |
| 51 | fn py_llm_response_codec( |
| 52 | response_codec: Option<&Bound<'_, PyAny>>, |
| 53 | ) -> Option<Arc<dyn LlmResponseCodec>> { |
| 54 | response_codec.and_then(|c| -> Option<Arc<dyn LlmResponseCodec>> { |
| 55 | if c.is_none() { |
| 56 | return None; |
| 57 | } |
| 58 | // Try to extract as a built-in codec first (avoids Python method dispatch overhead) |
| 59 | if let Ok(builtin) = c.extract::<pyo3::PyRef<'_, PyOpenAIChatCodec>>() { |
| 60 | return Some(builtin.inner_response_codec.clone()); |
| 61 | } |
| 62 | if let Ok(builtin) = c.extract::<pyo3::PyRef<'_, PyOpenAIResponsesCodec>>() { |
| 63 | return Some(builtin.inner_response_codec.clone()); |
| 64 | } |
| 65 | if let Ok(builtin) = c.extract::<pyo3::PyRef<'_, PyAnthropicMessagesCodec>>() { |
| 66 | return Some(builtin.inner_response_codec.clone()); |
| 67 | } |
| 68 | // Fall back to wrapping the Python object as a custom response codec |
| 69 | Some(Arc::new(py_callable::PyLlmResponseCodecWrapper { |
| 70 | py_codec: c.clone().unbind(), |
| 71 | })) |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | fn py_annotated_llm_response( |
| 76 | annotated_response: Option<&Bound<'_, PyAny>>, |
no outgoing calls
no test coverage detected