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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user