use std::marker::PhantomData; use axum::response::{IntoResponse, Response}; use bytes::Bytes; use litellm_host::protocol::Protocol; use crate::Error; pub trait ResponseEncoder: Send + Sync { type Protocol: Protocol; fn encode_response( &self, response: ::Response, ) -> Result::Error>; } pub trait StreamEncoder: ResponseEncoder + 'static { fn encode_stream_head( &self, head: ::StreamHead, ) -> Result, ::Error>; fn encode_chunk( &self, chunk: ::Chunk, ) -> Result::Error>; fn encode_stream_error(&self, error: Error<::Error>) -> Bytes; } pub struct Unary { response: F, protocol: PhantomData P>, } impl Unary { pub fn new(response: F) -> Self { Self { response, protocol: PhantomData, } } } impl ResponseEncoder for Unary where P: Protocol, F: Fn(P::Response) -> R + Send + Sync, R: IntoResponse, { type Protocol = P; fn encode_response(&self, response: P::Response) -> Result { Ok((self.response)(response).into_response()) } }