Skip to main content

LlmClient

Struct LlmClient 

Source
pub struct LlmClient { /* private fields */ }
Expand description

A configured LLM client ready to issue requests.

Built once per process from LlmConfig; complete_json is the only entry point the analyzer uses.

Fields are pub(crate) so the test submodules can construct clients with a non-default retry config (the production default sleeps 1s between attempts, which would make the retry tests take seconds). They are not part of the public API.

Implementations§

Source§

impl LlmClient

Source

pub fn model(&self) -> &str

The model this client asks for.

An accessor rather than a second copy on the caller: the cache key is computed from the model, and a struct holding its own model string is exactly what lets a request go to one model while the key names another.

Source

pub fn endpoint(&self) -> &str

The base URL this client talks to. For display - doctor and the failover report name the endpoint a provider used.

Source

pub fn temperature(&self) -> Option<f32>

The sampling temperature, or None when none is sent. Part of the cache key, for the same reason Self::model is - and None has to key differently from any value, because the answers genuinely differ.

Source

pub fn request_identity(&self) -> &str

Every HTTP request option that can change the answer while the endpoint and model stay the same.

Header names are canonicalised to lower case because HTTP compares them case-insensitively. Values remain exact: an arbitrary header can select a tenant, model route or feature variant, and drep cannot infer from its name whether changing it changes the answer. The returned digest is fed into the cache hash and is never logged.

Source

pub fn protocol(&self) -> ApiProtocol

The wire protocol this client speaks. For display, and for the cache key: the same model at the same endpoint over two protocols is two requests.

Source

pub fn new(cfg: &LlmConfig) -> Result<Self, LlmError>

Build a client from a validated LlmConfig.

Returns LlmError::NotConfigured when the config does not name an endpoint, a model, or has enabled = false. We do not default an endpoint - “LLM was disabled” and “LLM is enabled but misconfigured” are both fatal here, and inventing a value would mask a broken install.

Source

pub async fn complete_json( &self, system_prompt: &str, user_content: &str, ) -> Result<Extracted, LlmError>

Send one prompt and return the extracted JSON.

Concatenates ContentBlock::Text blocks in arrival order; other block variants are ignored. An empty response body is retried as a transport failure and, if it keeps coming back empty, surfaces as LlmError::Transport - see run_one_query for why “the model returned nothing” is not the deterministic outcome it looks like.

A non-empty body that yields no JSON at all is retried up to NO_JSON_ATTEMPTS times and then becomes LlmError::Unparseable, carrying an excerpt of what actually came back. A body that parsed only after brace-balancing (Extracted::Truncated) is returned immediately and never retried - that is the genuinely deterministic case, and the one the “never retry” rule was written for.

Trait Implementations§

Source§

impl Debug for LlmClient

Hand-written so the API key cannot reach a log.

A derived Debug prints every field, so any {:?}, dbg! or tracing line touching the client would emit a live credential.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more