| 16 | /// Trait that every LLM provider must implement. |
| 17 | #[async_trait::async_trait] |
| 18 | pub trait Provider: Send + Sync { |
| 19 | /// Perform a non-streaming chat completion. |
| 20 | async fn chat_completion( |
| 21 | &self, |
| 22 | request: &ChatCompletionRequest, |
| 23 | params: &ModelParams, |
| 24 | ) -> Result<ChatCompletionResponse, AppError>; |
| 25 | |
| 26 | /// Perform a streaming chat completion, returning an SSE byte stream. |
| 27 | async fn chat_completion_stream( |
| 28 | &self, |
| 29 | request: &ChatCompletionRequest, |
| 30 | params: &ModelParams, |
| 31 | ) -> Result<ByteStream, AppError>; |
| 32 | |
| 33 | /// Perform an embedding request. |
| 34 | async fn embedding( |
| 35 | &self, |
| 36 | request: &EmbeddingRequest, |
| 37 | params: &ModelParams, |
| 38 | ) -> Result<EmbeddingResponse, AppError>; |
| 39 | } |
| 40 | |
| 41 | /// Resolve the correct provider implementation for a given provider name. |
| 42 | pub fn resolve_provider(provider_name: &str) -> Result<Box<dyn Provider>, AppError> { |
nothing calls this directly
no outgoing calls
no test coverage detected