pub struct LlmClient { /* private fields */ }Expand description
LLM client supporting both OpenAI and Claude API formats.
Implementations§
Source§impl LlmClient
impl LlmClient
pub fn new(api_base: &str, api_key: &str) -> Result<Self>
Sourcepub async fn chat_completion(
&self,
model: &str,
messages: &[ChatMessage],
tools: Option<&[ToolDefinition]>,
temperature: Option<f64>,
) -> Result<ChatCompletionResponse>
pub async fn chat_completion( &self, model: &str, messages: &[ChatMessage], tools: Option<&[ToolDefinition]>, temperature: Option<f64>, ) -> Result<ChatCompletionResponse>
Non-streaming chat completion call (auto-routes based on model/api_base).
Sourcepub async fn chat_completion_stream(
&self,
model: &str,
messages: &[ChatMessage],
tools: Option<&[ToolDefinition]>,
temperature: Option<f64>,
event_sink: &mut dyn EventSink,
) -> Result<ChatCompletionResponse>
pub async fn chat_completion_stream( &self, model: &str, messages: &[ChatMessage], tools: Option<&[ToolDefinition]>, temperature: Option<f64>, event_sink: &mut dyn EventSink, ) -> Result<ChatCompletionResponse>
Streaming chat completion call (auto-routes based on model/api_base).
Sourcepub async fn embed(
&self,
model: &str,
texts: &[&str],
custom_url: Option<&str>,
custom_key: Option<&str>,
) -> Result<Vec<Vec<f32>>>
pub async fn embed( &self, model: &str, texts: &[&str], custom_url: Option<&str>, custom_key: Option<&str>, ) -> Result<Vec<Vec<f32>>>
Embed text(s) using OpenAI-compatible /embeddings API. Returns one embedding vector per input string. Used when memory_vector feature is enabled. If custom_url and custom_key are provided, use them instead of self.api_base/self.api_key.
Handles both OpenAI-standard format ({"data": [{"embedding": [...]}]})
and Dashscope native format ({"output": {"embeddings": [{"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 more