Write text analyses with OpenRouter in the worker
- analysis job: claims pending analyses (SKIP LOCKED, NOTIFY wake-up), builds a compact chart text without birth data, asks OpenRouter with a strict JSON schema, validates and stores the answer, model used, tokens and cost; retries transient errors, refunds credits on final failure, requeues interrupted jobs - prompt v1 for natal and synastry analyses, Hungarian style guide - compare-models subcommand for blind model comparison - migration 0003: attempts, next_attempt_at, model_used, cost_usd, notify trigger, one refund per analysis - db: rebuild when migrations change - compose: worker reads OPENROUTER_API_KEY from .env.secrets Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -16,6 +16,15 @@ pub struct Config {
|
||||
pub poll_interval: Duration,
|
||||
/// After this many failed attempts an e-mail is marked as failed.
|
||||
pub max_email_attempts: i32,
|
||||
/// Unset: analyses stay pending.
|
||||
pub openrouter_api_key: Option<String>,
|
||||
pub openrouter_base_url: String,
|
||||
/// Frontend address, sent to OpenRouter as `HTTP-Referer`.
|
||||
pub public_base_url: Option<String>,
|
||||
/// Analyses written at the same time.
|
||||
pub analysis_concurrency: usize,
|
||||
/// After this many failed attempts an analysis fails and is refunded.
|
||||
pub max_analysis_attempts: i32,
|
||||
}
|
||||
|
||||
fn var(name: &str) -> Option<String> {
|
||||
@@ -41,6 +50,12 @@ impl Config {
|
||||
mail_from: mail_from.parse().with_context(|| format!("invalid MAIL_FROM '{mail_from}'"))?,
|
||||
poll_interval: Duration::from_secs(parsed("POLL_INTERVAL_SECS", 30)?),
|
||||
max_email_attempts: parsed("MAX_EMAIL_ATTEMPTS", 8)?,
|
||||
openrouter_api_key: var("OPENROUTER_API_KEY"),
|
||||
openrouter_base_url: var("OPENROUTER_BASE_URL")
|
||||
.unwrap_or_else(|| crate::analysis::openrouter::DEFAULT_BASE_URL.into()),
|
||||
public_base_url: var("PUBLIC_BASE_URL"),
|
||||
analysis_concurrency: parsed("ANALYSIS_CONCURRENCY", 4)?,
|
||||
max_analysis_attempts: parsed("MAX_ANALYSIS_ATTEMPTS", 3)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user