Free chart summaries; password login off by default

- New analysis kind 'summary' (migration 0005): saving a chart queues a
  free 3-4 sentence summary written by SUMMARY_MODEL (default Sonnet
  5.5, about 1 cent; Haiku was tested too but chose weaker highlights).
  POST /v1/charts/{id}/summary returns it and re-queues a failed one.
- The chart page shows it in a "Röviden" card and polls until ready.
- PASSWORD_LOGIN (default false): register, login and password reset
  answer 403; only Google (later Apple, Facebook) logins remain.
- Prompt v2: Hungarian names for elements and modalities (an English
  "Fire" slipped into a summary); worker compare-models --summary.
- The worker also reads a lower-case openrouter_api_key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-16 17:12:17 +00:00
co-authored by Claude Opus 5.5
parent 269e3167e2
commit 450174c273
19 changed files with 339 additions and 38 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ impl Analyzer {
let db_err = |e: sqlx::Error| LlmError::Transient(format!("database: {e}"));
let gone = || LlmError::Permanent("the chart was deleted".into());
let text = match kind {
Kind::Natal => {
Kind::Natal | Kind::Summary => {
let (chart,): (Value,) = sqlx::query_as("SELECT result FROM charts WHERE id = $1")
.bind(job.chart_id)
.fetch_optional(&self.db)
+54 -6
View File
@@ -6,12 +6,14 @@
use serde_json::{Value, json};
/// Matches the backend's `ANALYSIS_PROMPT_VERSION` (part of the cache key).
pub const PROMPT_VERSION: &str = "v1";
pub const PROMPT_VERSION: &str = "v2";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Kind {
Natal,
Synastry,
/// A free teaser of a natal chart: a title and a few sentences.
Summary,
}
impl Kind {
@@ -19,6 +21,7 @@ impl Kind {
match s {
"natal" => Some(Kind::Natal),
"synastry" => Some(Kind::Synastry),
"summary" => Some(Kind::Summary),
_ => None,
}
}
@@ -56,11 +59,23 @@ fn sections(kind: Kind) -> &'static [(&'static str, &'static str)] {
match kind {
Kind::Natal => &NATAL_SECTIONS,
Kind::Synastry => &SYNASTRY_SECTIONS,
Kind::Summary => &[],
}
}
/// The JSON schema of the answer (strict mode: every property required).
pub fn schema(kind: Kind) -> Value {
if kind == Kind::Summary {
return json!({
"type": "object",
"additionalProperties": false,
"required": ["title", "summary"],
"properties": {
"title": {"type": "string", "description": "Short, evocative title for this chart (at most 6 words)"},
"summary": {"type": "string", "description": "3-4 sentences, 60-100 words, one paragraph"}
}
});
}
let mut props = serde_json::Map::new();
for (key, about) in sections(kind) {
props.insert(
@@ -101,6 +116,8 @@ Use the usual Hungarian astrological terms:
- planets and points: Nap, Hold, Merkúr, Vénusz, Mars, Jupiter, Szaturnusz, Uránusz, Neptunusz, Plútó, Chiron (Kiron), \
Észak-Holdcsomópont, Dél-Holdcsomópont, Lilith (Fekete Hold), Aszcendens, Descendens, Medium Coeli (MC), Imum Coeli (IC), Szerencsepont;
- aspects: együttállás (konjunkció), szextil, kvadrát (négyzet), trigon, szembenállás (oppozíció);
- elements and modalities: tűz, föld, levegő, víz (\"tűz elem\", \"a föld hiánya\"); kardinális, fix, változó;
Never leave English words (e.g. fire, earth, air, water) in the Hungarian text.
- other: \"a 3. házban\", \"a horoszkóp uralkodója\", retrográd, uralom (domicilium), száműzetés, exaltáció, esés, nappali/éjszakai horoszkóp.";
fn language_name(language: &str) -> &'static str {
@@ -116,6 +133,10 @@ fn rules(kind: Kind, language: &str) -> String {
"a personal natal chart interpretation",
"Speak to the owner of the chart directly, in the informal second person singular (in Hungarian: tegező forma, \"te\").",
),
Kind::Summary => (
"a short free summary of a natal chart (a teaser shown before the detailed, paid analysis)",
"Speak to the owner of the chart directly, in the informal second person singular (in Hungarian: tegező forma, \"te\").",
),
Kind::Synastry => (
"a relationship (synastry) interpretation for two people",
"Write for both people at once, in the informal second person plural (in Hungarian: \"ti\", \"kettőtök\"). \
@@ -139,9 +160,16 @@ Give the most weight to the Sun, Moon, Ascendant, chart ruler, tight aspects (or
and no medical, legal or financial advice.
- Avoid generic horoscope clichés and filler: every paragraph must say something specific to this chart.
- Texts are plain paragraphs separated by a blank line, without headings or lists inside; **bold** may be used sparingly.
- Length: each section 2-4 paragraphs (about 150-250 words); the whole analysis about 1300-1800 words.
- {length}
- Answer with a single JSON object that matches the given schema, and nothing else.",
lang = language_name(language),
length = match kind {
Kind::Summary => "Length: one paragraph of 3-4 sentences (60-100 words). Pick the Sun, Moon and Ascendant \
(if the birth time is known) and the single most striking feature of the chart (a very tight aspect, \
a stellium, a strong element emphasis or gap). It must be complete in itself and specific to this chart: \
no sales talk, and do not mention a longer analysis.",
_ => "Length: each section 2-4 paragraphs (about 150-250 words); the whole analysis about 1300-1800 words.",
},
);
if language == "hu" {
text.push_str("\n\n");
@@ -153,17 +181,22 @@ and no medical, legal or financial advice.
pub fn build(kind: Kind, language: &str, chart_text: &str) -> Prompt {
let mut user = String::from("Chart data:\n\n");
user.push_str(chart_text);
user.push_str("\nSections to write, in this order:\n");
for (key, about) in sections(kind) {
user.push_str(&format!("- {key}: {about}\n"));
if kind == Kind::Summary {
user.push_str("\nWrite the short summary now.");
} else {
user.push_str("\nSections to write, in this order:\n");
for (key, about) in sections(kind) {
user.push_str(&format!("- {key}: {about}\n"));
}
user.push_str("\nWrite the analysis now.");
}
user.push_str("\nWrite the analysis now.");
Prompt {
system: rules(kind, language),
user,
schema_name: match kind {
Kind::Natal => "natal_analysis",
Kind::Synastry => "synastry_analysis",
Kind::Summary => "chart_summary",
},
schema: schema(kind),
}
@@ -242,6 +275,9 @@ pub fn to_markdown(kind: Kind, language: &str, content: &Value) -> String {
};
let mut md =
format!("# {}\n\n_{}_\n\n", content["title"].as_str().unwrap_or(""), content["summary"].as_str().unwrap_or(""));
if kind == Kind::Summary {
return md;
}
for (key, _) in sections(kind) {
let s = &content["sections"][*key];
md.push_str(&format!("## {}\n\n{}\n\n", s["title"].as_str().unwrap_or(key), s["body"].as_str().unwrap_or("")));
@@ -261,6 +297,18 @@ pub fn to_markdown(kind: Kind, language: &str, content: &Value) -> String {
mod tests {
use super::*;
#[test]
fn summary_prompt_is_short() {
let p = build(Kind::Summary, "hu", "SUN: Cancer");
assert_eq!(p.schema_name, "chart_summary");
assert!(p.system.contains("3-4 sentences") && p.system.contains("tegező"));
assert!(!p.user.contains("Sections to write"));
assert_eq!(validate(&p.schema, &json!({"title": "Érzékeny mag", "summary": "Rövid szöveg."})), Ok(()));
assert!(validate(&p.schema, &json!({"title": "Érzékeny mag"})).is_err());
let md = to_markdown(Kind::Summary, "hu", &json!({"title": "Cím", "summary": "Szöveg."}));
assert_eq!(md, "# Cím\n\n_Szöveg._\n\n");
}
#[test]
fn validate_rejects_placeholder_titles() {
let schema = schema(Kind::Synastry);
+6 -3
View File
@@ -7,7 +7,8 @@
//! ```
//!
//! `--chart` is a horoscope-api `/v1/natal` response; `--synastry FILE` (instead
//! of `--chart`) takes a `/v1/synastry` response for a relationship analysis. The models get shuffled
//! of `--chart`) takes a `/v1/synastry` response for a relationship analysis;
//! `--summary` with `--chart` writes the short free summary instead. The models get shuffled
//! letters: `A.md`, `B.md`, ... hold the analyses, `key.json` tells which
//! letter is which model (with tokens, cost and time). The output on the
//! console does not reveal the mapping.
@@ -31,14 +32,15 @@ struct Args {
}
fn parse(args: Vec<String>) -> anyhow::Result<Args> {
let (mut chart, mut synastry, mut models, mut language, mut out) =
(None, None, Vec::new(), "hu".to_owned(), None);
let (mut chart, mut synastry, mut models, mut language, mut out) = (None, None, Vec::new(), "hu".to_owned(), None);
let mut summary = false;
let mut it = args.into_iter();
while let Some(flag) = it.next() {
let mut value = || it.next().with_context(|| format!("{flag} needs a value"));
match flag.as_str() {
"--chart" => chart = Some(PathBuf::from(value()?)),
"--synastry" => synastry = Some(PathBuf::from(value()?)),
"--summary" => summary = true,
"--models" => models = value()?.split(',').map(|m| m.trim().to_owned()).filter(|m| !m.is_empty()).collect(),
"--language" => language = value()?,
"--out" => out = Some(PathBuf::from(value()?)),
@@ -46,6 +48,7 @@ fn parse(args: Vec<String>) -> anyhow::Result<Args> {
}
}
let (input, kind) = match (chart, synastry) {
(Some(c), None) if summary => (c, prompt::Kind::Summary),
(Some(c), None) => (c, prompt::Kind::Natal),
(None, Some(s)) => (s, prompt::Kind::Synastry),
_ => bail!("give either --chart or --synastry"),
+2 -1
View File
@@ -50,7 +50,8 @@ 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"),
// The lower-case name is accepted too (as written in some secrets files).
openrouter_api_key: var("OPENROUTER_API_KEY").or_else(|| 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"),