pub struct LLMClient { /* private fields */ }Expand description
LLM 客户端
提供高级 LLM 交互功能
§示例
ⓘ
use mofa_foundation::llm::{LLMClient, LLMConfig, ChatMessage};
// 创建客户端
let client = LLMClient::new(provider);
// 简单对话
let response = client
.chat()
.system("You are a helpful assistant.")
.user("Hello!")
.send()
.await?;
info!("{}", response.content().unwrap_or_default());Implementations§
Source§impl LLMClient
impl LLMClient
Sourcepub fn new(provider: Arc<dyn LLMProvider>) -> LLMClient
pub fn new(provider: Arc<dyn LLMProvider>) -> LLMClient
使用 Provider 创建客户端
Sourcepub fn with_config(
provider: Arc<dyn LLMProvider>,
config: LLMConfig,
) -> LLMClient
pub fn with_config( provider: Arc<dyn LLMProvider>, config: LLMConfig, ) -> LLMClient
使用配置创建客户端
Sourcepub fn provider(&self) -> &Arc<dyn LLMProvider>
pub fn provider(&self) -> &Arc<dyn LLMProvider>
获取 Provider
Sourcepub fn chat(&self) -> ChatRequestBuilder
pub fn chat(&self) -> ChatRequestBuilder
创建 Chat 请求构建器
Sourcepub async fn embed(
&self,
input: impl Into<String>,
) -> Result<Vec<f32>, LLMError>
pub async fn embed( &self, input: impl Into<String>, ) -> Result<Vec<f32>, LLMError>
创建 Embedding 请求
Auto Trait Implementations§
impl Freeze for LLMClient
impl !RefUnwindSafe for LLMClient
impl Send for LLMClient
impl Sync for LLMClient
impl Unpin for LLMClient
impl UnsafeUnpin for LLMClient
impl !UnwindSafe for LLMClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage