pub trait ModelService: Send + Sync {
// Required methods
fn list_models(&self) -> Vec<ModelInfo>;
fn model_info(&self, model_id: &str) -> Option<ModelInfo>;
fn chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelChatResponse, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stream_chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
tx: Sender<ModelStreamChunk>,
) -> Pin<Box<dyn Future<Output = Result<(), ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn embedding<'life0, 'async_trait>(
&'life0 self,
req: ModelEmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelEmbeddingResponse, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn similarity<'life0, 'async_trait>(
&'life0 self,
req: ModelSimilarityRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelSimilarityResponse, ModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
宿主统一模型服务:消费者(内置组件经 PluginHandle、第三方插件经 host/model.*) 通过本接口获取模型清单、按 model_id 调用模型。
实现(宿主 ModelManager)负责聚合各提供方清单并按 model_id 前缀路由。
Required Methods§
Sourcefn list_models(&self) -> Vec<ModelInfo>
fn list_models(&self) -> Vec<ModelInfo>
全网模型清单(聚合缓存)。
Sourcefn model_info(&self, model_id: &str) -> Option<ModelInfo>
fn model_info(&self, model_id: &str) -> Option<ModelInfo>
按 model_id 查询模型信息。
Sourcefn chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelChatResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelChatResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
文本生成。
Sourcefn stream_chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
tx: Sender<ModelStreamChunk>,
) -> Pin<Box<dyn Future<Output = Result<(), ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stream_chat<'life0, 'async_trait>(
&'life0 self,
req: ModelChatRequest,
tx: Sender<ModelStreamChunk>,
) -> Pin<Box<dyn Future<Output = Result<(), ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
流式文本生成:增量经 tx 推送,完成后关闭通道。
Sourcefn embedding<'life0, 'async_trait>(
&'life0 self,
req: ModelEmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelEmbeddingResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn embedding<'life0, 'async_trait>(
&'life0 self,
req: ModelEmbeddingRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelEmbeddingResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
文本向量化(task_type 必填,宿主对缺失/未知值返回 InvalidRequest)。
Sourcefn similarity<'life0, 'async_trait>(
&'life0 self,
req: ModelSimilarityRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelSimilarityResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn similarity<'life0, 'async_trait>(
&'life0 self,
req: ModelSimilarityRequest,
) -> Pin<Box<dyn Future<Output = Result<ModelSimilarityResponse, ModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
查询向量与多个目标向量的相似度(按模型元数据公式计算,并行加速)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".