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 = AgentResult<ChatCompletionResponse>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: '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§
Sourcefn chat<'life0, 'async_trait>(
&'life0 self,
request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = AgentResult<ChatCompletionResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn chat<'life0, 'async_trait>(
&'life0 self,
request: ChatCompletionRequest,
) -> Pin<Box<dyn Future<Output = AgentResult<ChatCompletionResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Complete a chat request