pub trait RawAdapter: Send + Sync {
// Required methods
fn build_request(
&self,
request: &ChatRequest,
mode: CallMode,
) -> Result<RawRequest, LlmError>;
fn execute_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
client: &'life1 dyn HttpClient,
request: RawRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn capabilities(&self) -> Capabilities;
fn info(&self) -> ProviderInfo;
// Provided methods
fn parse_sse_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
_client: &'life1 dyn HttpClient,
_request: RawRequest,
_response: HttpResponse,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn parse_response(&self, _body: &[u8]) -> Result<ChatResponse, LlmError> { ... }
fn supported_modes(&self) -> &[CallMode] { ... }
}Expand description
Low-level adapter trait.
Implement this to get full LlmProvider functionality,
wrapped automatically by GenericProvider.
Implementors must provide:
build_request- Build HTTP requestexecute_stream- Required to implement, butGenericProviderdoes not call it; it is the hook for adapters that own the whole send-and-parse flowparse_sse_stream- Parse SSE from a pre-fetched response. Override this for streaming to work: the default returns an error, and it is this methodGenericProvidercalls.capabilities- Declare capabilitiesinfo- Provide info
Optional:
parse_response- Parse non-streaming response (default returns an error).chat()only falls back to streaming whensupported_modes()omitsCallMode::Once— since that is not the default, an adapter that does not implementparse_responsemust also narrowsupported_modes, orchat()will return the default error.
Note: the adapter is fully responsible for stream parsing, including SSE frame parsing and incremental tool call assembly. GenericProvider does not get involved in stream details.
Required Methods§
Sourcefn build_request(
&self,
request: &ChatRequest,
mode: CallMode,
) -> Result<RawRequest, LlmError>
fn build_request( &self, request: &ChatRequest, mode: CallMode, ) -> Result<RawRequest, LlmError>
Build HTTP request.
Sourcefn execute_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
client: &'life1 dyn HttpClient,
request: RawRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn execute_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
client: &'life1 dyn HttpClient,
request: RawRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute streaming request, fully parse SSE response.
The implementor receives &dyn HttpClient and parses the stream protocol,
returning ChatStream. This gives the adapter full control,
suitable for different providers’ SSE format differences.
Typical implementation:
- Send request via
client.send(&request) - Check HTTP status code
- Parse SSE stream (according to provider’s protocol format)
- Incremental tool call assembly (if needed)
- Return ChatStream
Sourcefn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
Get capabilities.
Sourcefn info(&self) -> ProviderInfo
fn info(&self) -> ProviderInfo
Get info.
Provided Methods§
Sourcefn parse_sse_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
_client: &'life1 dyn HttpClient,
_request: RawRequest,
_response: HttpResponse,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn parse_sse_stream<'life0, 'life1, 'async_trait>(
&'life0 self,
_client: &'life1 dyn HttpClient,
_request: RawRequest,
_response: HttpResponse,
) -> Pin<Box<dyn Future<Output = Result<ChatStream, LlmError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Parse SSE stream from an already-received HTTP response.
This method is called by GenericProvider after a successful HTTP response (with retry logic applied). The adapter only needs to parse the SSE stream, not send the HTTP request.
Default implementation: returns an error. Adapters must override this —
GenericProvider calls it rather than execute_stream
once a response is in hand, so an unimplemented override surfaces as a
stream error rather than a silently re-sent request.
Sourcefn parse_response(&self, _body: &[u8]) -> Result<ChatResponse, LlmError>
fn parse_response(&self, _body: &[u8]) -> Result<ChatResponse, LlmError>
Parse non-streaming response.
Default: not supported. Override this if the adapter supports non-streaming mode.
Sourcefn supported_modes(&self) -> &[CallMode]
fn supported_modes(&self) -> &[CallMode]
Supported call modes.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".