Questions about relationship analyses too
- The answer sees both charts and the comparison; both people see the questions - Heading, hint and example question per analysis kind Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -51,8 +51,9 @@ impl Analyzer {
|
||||
|
||||
async fn question_prompt(&self, job: &QuestionJob) -> Result<prompt::Prompt, LlmError> {
|
||||
let db_err = |e: sqlx::Error| LlmError::Transient(format!("database: {e}"));
|
||||
let (kind, chart_id, forecast_id, content): (String, Option<Uuid>, Option<Uuid>, Option<Value>) =
|
||||
sqlx::query_as("SELECT kind, chart_id, forecast_id, content FROM analyses WHERE id = $1")
|
||||
type Row = (String, Option<Uuid>, Option<Uuid>, Option<Uuid>, Option<Value>);
|
||||
let (kind, chart_id, synastry_id, forecast_id, content): Row =
|
||||
sqlx::query_as("SELECT kind, chart_id, synastry_id, forecast_id, content FROM analyses WHERE id = $1")
|
||||
.bind(job.analysis_id)
|
||||
.fetch_optional(&self.db)
|
||||
.await
|
||||
@@ -62,6 +63,7 @@ impl Analyzer {
|
||||
let content = content.ok_or_else(|| LlmError::Permanent("the analysis has no text".into()))?;
|
||||
let chart_text = match kind {
|
||||
Kind::Forecast => self.forecast_text(forecast_id).await?,
|
||||
Kind::Synastry => self.synastry_text(synastry_id).await?,
|
||||
_ => self.natal_text(chart_id).await?,
|
||||
};
|
||||
let analysis = prompt::to_markdown(kind, &job.language, &content);
|
||||
|
||||
@@ -828,4 +828,55 @@ mod analyses {
|
||||
sqlx::query_scalar("SELECT status FROM analyses WHERE id = $1").bind(id).fetch_one(&db).await.unwrap();
|
||||
assert_eq!(status, "done");
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn answers_a_question_about_a_relationship_with_both_charts(db: PgPool) {
|
||||
let s = setup(&db).await;
|
||||
let response = fixture("synastry-response.json");
|
||||
let (chart2, synastry, analysis) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7());
|
||||
sqlx::query(
|
||||
"INSERT INTO charts (id, owner_id, label, is_primary, kind, birth_data, result, chart_hash) \
|
||||
VALUES ($1, $2, 'Partner', false, 'person', '{}', $3, 'hash2')",
|
||||
)
|
||||
.bind(chart2)
|
||||
.bind(s.user)
|
||||
.bind(&response["person2"])
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query(
|
||||
"INSERT INTO synastries (id, owner_id, chart1_id, chart2_id, result, synastry_hash) \
|
||||
VALUES ($1, $2, $3, $4, $5, 'sh')",
|
||||
)
|
||||
.bind(synastry)
|
||||
.bind(s.user)
|
||||
.bind(s.chart)
|
||||
.bind(chart2)
|
||||
.bind(&response)
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query(
|
||||
"INSERT INTO analyses (id, kind, synastry_id, requested_by, language, model, prompt_version, cache_key, \
|
||||
status, content) VALUES ($1, 'synastry', $2, $3, 'hu', 'test/model', 'v1', 'k', 'done', $4)",
|
||||
)
|
||||
.bind(analysis)
|
||||
.bind(synastry)
|
||||
.bind(s.user)
|
||||
.bind(content(Kind::Synastry))
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
let id = ask(&db, analysis, s.user, "Mire figyeljünk egy vitában?", "pending", None).await;
|
||||
let (fake, url) = fake_openrouter(vec![reply(&json!({"answer": "Arra, hogy..."}))]).await;
|
||||
let a = analyzer(&db, &url);
|
||||
assert!(answer_once(&a).await);
|
||||
let status: String =
|
||||
sqlx::query_scalar("SELECT status FROM questions WHERE id = $1").bind(id).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("Képletadatok:\n\nSYNASTRY") && user.contains("Person 2"), "both charts");
|
||||
assert!(!user.contains("Szeged") && !user.contains("Pécs"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user