Comparisons (synastry) of the own chart and persons
/osszevetesek compares any two of the user's charts (own and persons); the person card and the person's chart page have "Összevetés velem". The comparison page shows a double wheel (first person inside with houses, second outside, aspects between them), the aspects by character, and tabs: paid relationship analysis (synastry unit), the cross aspect grid, house overlays, composite and the full aspect list. Correcting a person within the hour now deletes the user's own comparisons with them instead of being refused; still refused after a paid analysis or when someone else's comparison uses the chart. The relationship analysis prompt is editable on /admin/promptok too, and can be tried on one of the admin's comparisons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -45,7 +45,8 @@ pub struct Job {
|
||||
pub struct PreviewJob {
|
||||
pub id: Uuid,
|
||||
pub kind: String,
|
||||
pub chart_id: Uuid,
|
||||
pub chart_id: Option<Uuid>,
|
||||
pub synastry_id: Option<Uuid>,
|
||||
pub language: String,
|
||||
pub model: String,
|
||||
pub system: String,
|
||||
@@ -91,21 +92,9 @@ impl Analyzer {
|
||||
pub async fn prompt_for(&self, job: &Job) -> Result<Prompt, LlmError> {
|
||||
let kind = Kind::parse(&job.kind).ok_or_else(|| LlmError::Permanent(format!("unknown kind '{}'", job.kind)))?;
|
||||
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::Summary => self.natal_text(job.chart_id).await?,
|
||||
Kind::Synastry => {
|
||||
let (result, chart1, chart2): (Value, Value, Value) = sqlx::query_as(
|
||||
"SELECT s.result, c1.result, c2.result FROM synastries s \
|
||||
JOIN charts c1 ON c1.id = s.chart1_id JOIN charts c2 ON c2.id = s.chart2_id WHERE s.id = $1",
|
||||
)
|
||||
.bind(job.synastry_id)
|
||||
.fetch_optional(&self.db)
|
||||
.await
|
||||
.map_err(db_err)?
|
||||
.ok_or_else(gone)?;
|
||||
compact::synastry(&chart1, &chart2, &result)
|
||||
}
|
||||
Kind::Synastry => self.synastry_text(job.synastry_id).await?,
|
||||
};
|
||||
let (base, revision) = prompt::split_version(&job.prompt_version);
|
||||
if base != PROMPT_VERSION {
|
||||
@@ -135,13 +124,27 @@ impl Analyzer {
|
||||
Ok(compact::natal(&chart))
|
||||
}
|
||||
|
||||
/// The compact text of a stored synastry with its two charts.
|
||||
async fn synastry_text(&self, synastry_id: Option<Uuid>) -> Result<String, LlmError> {
|
||||
let (result, chart1, chart2): (Value, Value, Value) = sqlx::query_as(
|
||||
"SELECT s.result, c1.result, c2.result FROM synastries s \
|
||||
JOIN charts c1 ON c1.id = s.chart1_id JOIN charts c2 ON c2.id = s.chart2_id WHERE s.id = $1",
|
||||
)
|
||||
.bind(synastry_id)
|
||||
.fetch_optional(&self.db)
|
||||
.await
|
||||
.map_err(|e| LlmError::Transient(format!("database: {e}")))?
|
||||
.ok_or_else(|| LlmError::Permanent("the synastry was deleted".into()))?;
|
||||
Ok(compact::synastry(&chart1, &chart2, &result))
|
||||
}
|
||||
|
||||
/// Takes the oldest waiting prompt test run, if any.
|
||||
pub async fn claim_preview(&self) -> Result<Option<PreviewJob>, sqlx::Error> {
|
||||
let job: Option<PreviewJob> = sqlx::query_as(
|
||||
"UPDATE prompt_previews SET status = 'running', started_at = now() \
|
||||
WHERE id = (SELECT id FROM prompt_previews WHERE status = 'pending' \
|
||||
ORDER BY created_at LIMIT 1 FOR UPDATE SKIP LOCKED) \
|
||||
RETURNING id, kind, chart_id, language, model, system",
|
||||
RETURNING id, kind, chart_id, synastry_id, language, model, system",
|
||||
)
|
||||
.fetch_optional(&self.db)
|
||||
.await?;
|
||||
@@ -155,10 +158,12 @@ impl Analyzer {
|
||||
pub async fn handle_preview(&self, job: PreviewJob) {
|
||||
let started = Instant::now();
|
||||
let result = async {
|
||||
let kind = Kind::parse(&job.kind)
|
||||
.filter(|k| *k != Kind::Synastry)
|
||||
.ok_or_else(|| LlmError::Permanent(format!("unknown kind '{}'", job.kind)))?;
|
||||
let text = self.natal_text(Some(job.chart_id)).await?;
|
||||
let kind =
|
||||
Kind::parse(&job.kind).ok_or_else(|| LlmError::Permanent(format!("unknown kind '{}'", job.kind)))?;
|
||||
let text = match kind {
|
||||
Kind::Synastry => self.synastry_text(job.synastry_id).await?,
|
||||
_ => self.natal_text(job.chart_id).await?,
|
||||
};
|
||||
let built = prompt::build(kind, &job.language, &text, Some(&job.system));
|
||||
let mut c = self.llm.complete(&job.model, &built).await?;
|
||||
prompt::polish(&job.language, &mut c.content);
|
||||
|
||||
@@ -567,11 +567,31 @@ mod analyses {
|
||||
assert!(run_once(&a).await);
|
||||
assert_eq!(row(&db, id).await.0, "done");
|
||||
|
||||
{
|
||||
let requests = fake.requests.lock().unwrap();
|
||||
let user = requests[0]["messages"][1]["content"].as_str().unwrap();
|
||||
assert!(user.starts_with("Chart data:\n\nSYNASTRY") && user.contains("- attraction: "));
|
||||
assert!(requests[0]["messages"][0]["content"].as_str().unwrap().contains("Write in English."));
|
||||
assert!(!user.contains("Szeged") && !user.contains("Pécs"));
|
||||
}
|
||||
|
||||
// a prompt test run on the comparison
|
||||
sqlx::query(
|
||||
"INSERT INTO prompt_previews (id, kind, synastry_id, language, model, system, created_by) \
|
||||
VALUES ($1, 'synastry', $2, 'hu', 'test/model', 'Kapcsolati próba.', $3)",
|
||||
)
|
||||
.bind(Uuid::now_v7())
|
||||
.bind(synastry)
|
||||
.bind(s.user)
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
a.handle_preview(a.claim_preview().await.unwrap().expect("the preview")).await;
|
||||
let (status,): (String,) = sqlx::query_as("SELECT status FROM prompt_previews").fetch_one(&db).await.unwrap();
|
||||
assert_eq!(status, "done");
|
||||
let requests = fake.requests.lock().unwrap();
|
||||
let user = requests[0]["messages"][1]["content"].as_str().unwrap();
|
||||
assert!(user.starts_with("Chart data:\n\nSYNASTRY") && user.contains("- attraction: "));
|
||||
assert!(requests[0]["messages"][0]["content"].as_str().unwrap().contains("Write in English."));
|
||||
assert!(!user.contains("Szeged") && !user.contains("Pécs"));
|
||||
assert_eq!(requests[1]["messages"][0]["content"], "Kapcsolati próba.");
|
||||
assert!(requests[1]["messages"][1]["content"].as_str().unwrap().contains("SYNASTRY"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user