Merge main into prod: worker room and time for reasoning models
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -8,8 +8,9 @@ use serde_json::{Value, json};
|
||||
use super::prompt::{Prompt, validate};
|
||||
|
||||
pub const DEFAULT_BASE_URL: &str = "https://openrouter.ai/api/v1";
|
||||
/// Room for reasoning tokens as well as the answer.
|
||||
const MAX_TOKENS: u32 = 16_000;
|
||||
/// Room for reasoning tokens as well as the answer: reasoning models (e.g.
|
||||
/// DeepSeek) think at length before answering. Only a cap, not a cost.
|
||||
const MAX_TOKENS: u32 = 32_000;
|
||||
|
||||
pub struct OpenRouter {
|
||||
http: reqwest::Client,
|
||||
@@ -143,7 +144,8 @@ fn error_message(body: &Value, fallback: &str) -> String {
|
||||
impl OpenRouter {
|
||||
pub fn new(base_url: &str, api_key: &str, referer: Option<String>) -> Self {
|
||||
let http = reqwest::Client::builder()
|
||||
.timeout(Duration::from_secs(300))
|
||||
// Reasoning models can take several minutes for a long analysis.
|
||||
.timeout(Duration::from_secs(600))
|
||||
.connect_timeout(Duration::from_secs(10))
|
||||
.build()
|
||||
.expect("HTTP client");
|
||||
@@ -203,8 +205,10 @@ impl OpenRouter {
|
||||
let content = extract_json(raw).ok_or_else(|| {
|
||||
LlmError::Transient(format!("answer is not JSON: {}", raw.chars().take(200).collect::<String>()))
|
||||
})?;
|
||||
validate(&prompt.schema, &content)
|
||||
.map_err(|e| LlmError::Transient(format!("answer does not match the schema: {e}")))?;
|
||||
validate(&prompt.schema, &content).map_err(|e| {
|
||||
tracing::warn!(model, answer = %raw.chars().take(500).collect::<String>(), "answer does not match the schema");
|
||||
LlmError::Transient(format!("answer does not match the schema: {e}"))
|
||||
})?;
|
||||
|
||||
let usage = &reply["usage"];
|
||||
let tokens = |key: &str| usage[key].as_i64().and_then(|n| i32::try_from(n).ok());
|
||||
|
||||
Reference in New Issue
Block a user