Skip to main content

LLMProvider

Trait LLMProvider 

Source
pub trait LLMProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn chat<'life0, 'async_trait>(
        &'life0 self,
        request: ChatCompletionRequest,
    ) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AgentError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

LLM Provider trait - 定义 LLM 提供商接口

这是一个核心抽象,定义了所有 LLM 提供商必须实现的最小接口。

§示例

use mofa_kernel::agent::types::{LLMProvider, ChatCompletionRequest, ChatCompletionResponse};

struct MyLLMProvider;

#[async_trait]
impl LLMProvider for MyLLMProvider {
    fn name(&self) -> &str { "my-llm" }

    async fn chat(&self, request: ChatCompletionRequest) -> AgentResult<ChatCompletionResponse> {
        // 实现 LLM 调用逻辑
    }
}

Required Methods§

Source

fn name(&self) -> &str

Get provider name

Source

fn chat<'life0, 'async_trait>( &'life0 self, request: ChatCompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<ChatCompletionResponse, AgentError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Complete a chat request

Implementors§