pub struct Client { /* private fields */ }Expand description
Top-level LLM client. Cheap to clone.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(provider: Arc<dyn LLMProvider>) -> Self
pub fn new(provider: Arc<dyn LLMProvider>) -> Self
Wrap any LLMProvider.
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Fluent builder.
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Build from env vars. Provider-namespaced with fallback:
COGNIS_OPENAI_API_KEY overrides COGNIS_API_KEY.
Sourcepub async fn invoke(&self, messages: Vec<Message>) -> Result<Message>
pub async fn invoke(&self, messages: Vec<Message>) -> Result<Message>
One-shot chat completion (no tools).
Sourcepub async fn stream(
&self,
messages: Vec<Message>,
) -> Result<RunnableStream<StreamChunk>>
pub async fn stream( &self, messages: Vec<Message>, ) -> Result<RunnableStream<StreamChunk>>
Streaming chat completion.
Sourcepub async fn invoke_with_tools(
&self,
messages: Vec<Message>,
tools: &[Arc<dyn Tool>],
) -> Result<Message>
pub async fn invoke_with_tools( &self, messages: Vec<Message>, tools: &[Arc<dyn Tool>], ) -> Result<Message>
Chat completion with tool definitions.
Sourcepub async fn chat(
&self,
messages: Vec<Message>,
opts: ChatOptions,
) -> Result<ChatResponse>
pub async fn chat( &self, messages: Vec<Message>, opts: ChatOptions, ) -> Result<ChatResponse>
Provider-level full chat completion (with all options).
Sourcepub fn provider(&self) -> &Arc<dyn LLMProvider> ⓘ
pub fn provider(&self) -> &Arc<dyn LLMProvider> ⓘ
Underlying provider.
Source§impl Client
impl Client
Sourcepub fn with_structured_output<T>(self) -> StructuredClient<T>
pub fn with_structured_output<T>(self) -> StructuredClient<T>
Coerce this client’s output to a typed value T.
T must derive JsonSchema (for prompt construction) and
Deserialize (for parsing). The returned value is itself a
Runnable<Vec<Message>, T>, so it composes with .pipe().
Trait Implementations§
Source§impl Runnable<Vec<Message>, Message> for Client
impl Runnable<Vec<Message>, Message> for Client
Source§fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
__arg2: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Vec<Message>,
__arg2: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Message>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
One-shot invocation. The hot path.
Source§fn batch<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<I>,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<Vec<O>, CognisError>> + Send + 'async_trait>>
fn batch<'life0, 'async_trait>( &'life0 self, inputs: Vec<I>, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<Vec<O>, CognisError>> + Send + 'async_trait>>
Run multiple inputs in parallel. Defaults to
buffer_unordered
honouring config.max_concurrency.Source§fn stream<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<RunnableStream<O>, CognisError>> + Send + 'async_trait>>
fn stream<'life0, 'async_trait>( &'life0 self, input: I, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<RunnableStream<O>, CognisError>> + Send + 'async_trait>>
Stream the final output (chunks of
O). Default emits one item via
invoke — non-streaming runnables are correct without override.Source§fn stream_events<'life0, 'async_trait>(
&'life0 self,
input: I,
config: RunnableConfig,
) -> Pin<Box<dyn Future<Output = Result<EventStream, CognisError>> + Send + 'async_trait>>
fn stream_events<'life0, 'async_trait>( &'life0 self, input: I, config: RunnableConfig, ) -> Pin<Box<dyn Future<Output = Result<EventStream, CognisError>> + Send + 'async_trait>>
Stream structured events. Default emits OnStart + OnEnd around an
invoke call. Graph engines override to surface per-node events.Source§fn input_schema(&self) -> Option<Value>
fn input_schema(&self) -> Option<Value>
JSON Schema for the input type, if known.
Source§fn output_schema(&self) -> Option<Value>
fn output_schema(&self) -> Option<Value>
JSON Schema for the output type, if known.
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, I, O> RunnableExt<I, O> for R
impl<R, I, O> RunnableExt<I, O> for R
Source§fn pipe<R2, O2>(self, next: R2) -> Pipe<Self, R2, I, O, O2>
fn pipe<R2, O2>(self, next: R2) -> Pipe<Self, R2, I, O, O2>
Pipe this runnable into another, building a
Pipe<Self, Next>.Source§fn with_retry(self, policy: RetryPolicy) -> Retry<Self, I, O>where
I: Clone,
fn with_retry(self, policy: RetryPolicy) -> Retry<Self, I, O>where
I: Clone,
Wrap with a retry policy.
Source§fn with_max_retries(self, attempts: u32) -> Retry<Self, I, O>where
I: Clone,
fn with_max_retries(self, attempts: u32) -> Retry<Self, I, O>where
I: Clone,
Shortcut: retry with default policy and N attempts.
Source§fn with_timeout(self, duration: Duration) -> Timeout<Self, I, O>
fn with_timeout(self, duration: Duration) -> Timeout<Self, I, O>
Wrap with a per-call timeout.
Source§fn with_fallback<F>(self, fallback: F) -> Fallback<Self, F, I, O>
fn with_fallback<F>(self, fallback: F) -> Fallback<Self, F, I, O>
Wrap with a fallback runnable.
Source§fn with_memory_cache<K, F>(
self,
key_fn: F,
) -> Cache<Self, I, O, K, MemoryCache<K, O>>
fn with_memory_cache<K, F>( self, key_fn: F, ) -> Cache<Self, I, O, K, MemoryCache<K, O>>
Wrap with an in-memory cache keyed by
key_fn(&I).