From d48aa4f0bce28159b6c5ee6bd0085a7f5a82e962 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 15 Nov 2026 15:43:07 +0100 Subject: 0.5.0: visible step counter, one client per turn, docs corrected Also fixes a 32-bit-only rlim_t mismatch found by building the target. --- src/provider.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/provider.rs') diff --git a/src/provider.rs b/src/provider.rs index b45282e..1b9e220 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -196,12 +196,35 @@ fn explain(status: u16, message: &str) -> String { message.to_string() } +/// One client per turn: rebuilding it per step pays a TLS handshake on every +/// request, which is noticeable on an i686 core. +pub fn agent() -> ureq::Agent { + ureq::Agent::config_builder() + .http_status_as_error(false) + .timeout_connect(Some(Duration::from_secs(10))) + .timeout_recv_response(Some(Duration::from_secs(180))) + .timeout_per_read(Some(Duration::from_secs(180))) + .build() + .into() +} + pub fn chat( cfg: &Config, messages: &[Value], tools: &[Value], cancel: &AtomicBool, sink: &mut dyn Sink, +) -> Result { + chat_with(&agent(), cfg, messages, tools, cancel, sink) +} + +pub fn chat_with( + agent: &ureq::Agent, + cfg: &Config, + messages: &[Value], + tools: &[Value], + cancel: &AtomicBool, + sink: &mut dyn Sink, ) -> Result { // serde_json::Value orders objects by key, so the serialised bytes are // stable for the same input. That is what keeps the provider's prompt cache @@ -217,14 +240,6 @@ pub fn chat( } let bytes = serde_json::to_vec(&body).map_err(|e| Error::Transport(e.to_string()))?; - let agent: ureq::Agent = ureq::Agent::config_builder() - .http_status_as_error(false) - .timeout_connect(Some(Duration::from_secs(10))) - .timeout_recv_response(Some(Duration::from_secs(180))) - .timeout_per_read(Some(Duration::from_secs(180))) - .build() - .into(); - let started = Instant::now(); let mut resp = { let mut attempt = 0usize; -- cgit v1.2.3