Questions about an analysis or forecast, answered by the model that wrote it
- 3 questions in every package, +5 questions add-on (1 000 Ft); question units, refund on failure - The answer sees the chart data, the analysis and earlier questions; at most 250 words - Editable question prompt (Promptok → Kérdés-válasz); admins regenerate answers - Package texts and FAQ updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
pub mod compact;
|
||||
pub mod openrouter;
|
||||
pub mod prompt;
|
||||
pub mod questions;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -98,6 +99,7 @@ impl Analyzer {
|
||||
Kind::Natal | Kind::Summary => self.natal_text(job.chart_id).await?,
|
||||
Kind::Synastry => self.synastry_text(job.synastry_id).await?,
|
||||
Kind::Forecast => self.forecast_text(job.forecast_id).await?,
|
||||
Kind::Question => return Err(LlmError::Permanent("a question is not an analysis".into())),
|
||||
};
|
||||
let (base, revision) = prompt::split_version(&job.prompt_version);
|
||||
if base != PROMPT_VERSION {
|
||||
@@ -180,6 +182,7 @@ impl Analyzer {
|
||||
Kind::Synastry => self.synastry_text(job.synastry_id).await?,
|
||||
Kind::Forecast => self.forecast_text(job.forecast_id).await?,
|
||||
Kind::Natal | Kind::Summary => self.natal_text(job.chart_id).await?,
|
||||
Kind::Question => return Err(LlmError::Permanent("a question has no test run".into())),
|
||||
};
|
||||
let built = prompt::build(kind, &job.language, &text, Some(&job.system));
|
||||
let mut c = self.llm.complete(&job.model, &built).await?;
|
||||
@@ -324,6 +327,13 @@ impl Analyzer {
|
||||
.bind(STUCK_AFTER_MINUTES)
|
||||
.execute(&self.db)
|
||||
.await?;
|
||||
sqlx::query(
|
||||
"UPDATE questions SET status = 'pending', error = 'interrupted', next_attempt_at = now() \
|
||||
WHERE status = 'running' AND started_at < now() - make_interval(mins => $1)",
|
||||
)
|
||||
.bind(STUCK_AFTER_MINUTES)
|
||||
.execute(&self.db)
|
||||
.await?;
|
||||
// A test run is not retried: the admin can start it again.
|
||||
sqlx::query(
|
||||
"UPDATE prompt_previews SET status = 'failed', error = 'interrupted', completed_at = now() \
|
||||
@@ -352,6 +362,16 @@ impl Analyzer {
|
||||
Ok(r) => tracing::info!(released = r.rows_affected(), "unfinished analyses put back in the queue"),
|
||||
Err(e) => tracing::error!(error = %e, "releasing unfinished analyses"),
|
||||
}
|
||||
let result = sqlx::query(
|
||||
"UPDATE questions SET status = 'pending', error = 'interrupted', next_attempt_at = now(), \
|
||||
attempts = greatest(attempts - 1, 0) WHERE id = ANY($1) AND status = 'running'",
|
||||
)
|
||||
.bind(&ids)
|
||||
.execute(&self.db)
|
||||
.await;
|
||||
if let Err(e) = result {
|
||||
tracing::error!(error = %e, "releasing unfinished questions");
|
||||
}
|
||||
let result = sqlx::query(
|
||||
"UPDATE prompt_previews SET status = 'failed', error = 'interrupted', completed_at = now() \
|
||||
WHERE id = ANY($1) AND status = 'running'",
|
||||
@@ -384,6 +404,22 @@ pub async fn run(analyzer: Arc<Analyzer>, poll: Duration, stop: watch::Receiver<
|
||||
}
|
||||
// Fill the free slots.
|
||||
while let Ok(permit) = slots.clone().try_acquire_owned() {
|
||||
// Questions first: someone is waiting for a short answer.
|
||||
match analyzer.claim_question().await {
|
||||
Ok(Some(job)) => {
|
||||
let analyzer = analyzer.clone();
|
||||
tasks.spawn(async move {
|
||||
analyzer.handle_question(job).await;
|
||||
drop(permit);
|
||||
});
|
||||
continue;
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => {
|
||||
tracing::error!(error = %e, "claiming a question");
|
||||
break;
|
||||
}
|
||||
}
|
||||
match analyzer.claim().await {
|
||||
Ok(Some(job)) => {
|
||||
let analyzer = analyzer.clone();
|
||||
|
||||
Reference in New Issue
Block a user