pub struct OpenRouterChatClient { /* private fields */ }Expand description
Process-wide OpenRouter chat client. Holds the model name so that callers
only thread the per-item prompt/schema/input through Self::complete.
Implementations§
Source§impl OpenRouterChatClient
impl OpenRouterChatClient
Sourcepub fn new(
api_key: SecretBox<String>,
model: String,
timeout_secs: u64,
) -> Result<Self, AppError>
pub fn new( api_key: SecretBox<String>, model: String, timeout_secs: u64, ) -> Result<Self, AppError>
Builds a chat client bound to model, applying timeout_secs as the
total per-request budget (wired from --openrouter-timeout). A value of
0 falls back to DEFAULT_TIMEOUT_SECS so a missing or zero flag never
degrades into reqwest`’s immediate-timeout behaviour.
Sourcepub async fn complete(
&self,
system_prompt: &str,
input_text: &str,
schema_str: &str,
max_tokens: Option<u32>,
) -> Result<ChatCompletion, ChatError>
pub async fn complete( &self, system_prompt: &str, input_text: &str, schema_str: &str, max_tokens: Option<u32>, ) -> Result<ChatCompletion, ChatError>
Runs a single structured-output completion, transparently growing
max_tokens and re-issuing the request when the model truncates its
output (GAP-SG-70).
schema_str is the JSON Schema (as a string) the model must honour
under strict: true. When input_text is empty only the system
message is sent. max_tokens seeds the first attempt; None lets the
provider apply its own default.
Returns ChatCompletion on success or ChatError on failure; both
carry finish_reason/token diagnostics when a response was decoded.
§Errors
Returns ChatError when: the schema is invalid JSON; the HTTP
request fails or exhausts retries; the provider returns a permanent
error (401/400/404, or a structured error object in a 2xx body); the
response carries no usable content; the content cannot be parsed as
JSON even after repair; the parsed JSON is not an object; or the
response is truncated (finish_reason: "length") after
crate::constants::ENRICH_MAX_LENGTH_RETRIES max_tokens growth
attempts are exhausted.
Auto Trait Implementations§
impl !RefUnwindSafe for OpenRouterChatClient
impl !UnwindSafe for OpenRouterChatClient
impl Freeze for OpenRouterChatClient
impl Send for OpenRouterChatClient
impl Sync for OpenRouterChatClient
impl Unpin for OpenRouterChatClient
impl UnsafeUnpin for OpenRouterChatClient
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
impl<T> ErasedDestructor for Twhere
T: 'static,
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>
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>
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