Skip to main content

oxi_ai/providers/
trait_def.rs

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