Skip to main content

ModelService

Trait ModelService 

Source
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§

Source

fn list_models(&self) -> Vec<ModelInfo>

全网模型清单(聚合缓存)。

Source

fn model_info(&self, model_id: &str) -> Option<ModelInfo>

按 model_id 查询模型信息。

Source

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,

文本生成。

Source

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 推送,完成后关闭通道。

Source

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)。

Source

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".

Implementors§