use async_trait::async_trait;
use ferrum_types::{EngineConfig, InferenceRequest, InferenceResponse, Result, StreamChunk};
use futures::Stream;
use std::pin::Pin;
#[async_trait]
pub trait InferenceEngine: Send + Sync {
async fn infer(&self, request: InferenceRequest) -> Result<InferenceResponse>;
async fn infer_stream(
&self,
request: InferenceRequest,
) -> Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>;
async fn status(&self) -> ferrum_types::EngineStatus;
async fn shutdown(&self) -> Result<()>;
fn config(&self) -> &EngineConfig;
fn metrics(&self) -> ferrum_types::EngineMetrics;
async fn health_check(&self) -> ferrum_types::HealthStatus;
async fn embed_text(&self, _text: &str) -> Result<Vec<f32>> {
Err(ferrum_types::FerrumError::model(
"This engine does not support text embedding",
))
}
async fn embed_image(&self, _image: &str) -> Result<Vec<f32>> {
Err(ferrum_types::FerrumError::model(
"This engine does not support image embedding",
))
}
fn embedding_dim(&self) -> usize {
0
}
async fn transcribe_file(&self, _path: &str, _language: Option<&str>) -> Result<String> {
Err(ferrum_types::FerrumError::model(
"This engine does not support audio transcription",
))
}
async fn transcribe_bytes(&self, _data: &[u8], _language: Option<&str>) -> Result<String> {
Err(ferrum_types::FerrumError::model(
"This engine does not support audio transcription",
))
}
}
#[async_trait]
pub trait AdvancedInferenceEngine: InferenceEngine {
async fn infer_batch(
&self,
requests: Vec<InferenceRequest>,
) -> Result<Vec<Result<InferenceResponse>>>;
async fn infer_speculative(
&self,
request: InferenceRequest,
speculation_config: ferrum_types::SpeculationConfig,
) -> Result<InferenceResponse>;
async fn warmup(
&mut self,
warmup_requests: Vec<InferenceRequest>,
) -> Result<ferrum_types::WarmupResult>;
async fn reconfigure(&mut self, config: EngineConfig) -> Result<()>;
async fn diagnostics(&self) -> ferrum_types::DiagnosticsReport;
async fn export_state(&self) -> Result<ferrum_types::EngineState>;
async fn import_state(&mut self, state: ferrum_types::EngineState) -> Result<()>;
}
pub type SpeculationConfig = ferrum_types::SpeculationConfig;
pub type HardwareConstraints = ferrum_types::HardwareConstraints;
pub type RequestCharacteristics = ferrum_types::RequestCharacteristics;
pub type LatencyRequirements = ferrum_types::LatencyRequirements;