Skip to main content

oxicode_ai/providers/
trait_def.rs

1//! Provider trait definition
2
3use crate::error::ProviderError;
4use crate::{Context, Model, ProviderEvent, StreamOptions};
5use futures::Stream;
6use std::future::Future;
7use std::pin::Pin;
8
9/// Stream result type alias
10pub type StreamResult = Result<Pin<Box<dyn Stream<Item = ProviderEvent> + Send>>, ProviderError>;
11
12/// LLM provider trait
13///
14/// Implement this trait to add support for new LLM providers.
15pub trait Provider: Send + Sync + 'static {
16    /// Stream assistant message events
17    fn stream<'a>(
18        &'a self,
19        model: &'a Model,
20        context: &'a Context,
21        options: Option<StreamOptions>,
22    ) -> Pin<Box<dyn Future<Output = StreamResult> + Send + 'a>>;
23}