refactor(routines): translate prompt input keys to english to reduce language switch penalty

This commit is contained in:
Piotr Oleszczyk 2026-03-03 20:24:56 +01:00
parent 9574c91be1
commit 28fb74b9bf

View file

@ -203,16 +203,16 @@ def _build_skin_context(session: Session) -> str:
) )
).first() ).first()
if snapshot is None: if snapshot is None:
return "STAN SKÓRY: brak danych\n" return "SKIN CONDITION: no data\n"
ev = _ev ev = _ev
return ( return (
f"STAN SKÓRY (snapshot z {snapshot.snapshot_date}):\n" f"SKIN CONDITION (snapshot from {snapshot.snapshot_date}):\n"
f" Ogólny stan: {ev(snapshot.overall_state)}\n" f" Overall state: {ev(snapshot.overall_state)}\n"
f" Nawilżenie: {snapshot.hydration_level}/5\n" f" Hydration: {snapshot.hydration_level}/5\n"
f" Bariera: {ev(snapshot.barrier_state)}\n" f" Barrier: {ev(snapshot.barrier_state)}\n"
f" Aktywne problemy: {', '.join(ev(c) for c in (snapshot.active_concerns or []))}\n" f" Active concerns: {', '.join(ev(c) for c in (snapshot.active_concerns or []))}\n"
f" Priorytety: {', '.join(snapshot.priorities or [])}\n" f" Priorities: {', '.join(snapshot.priorities or [])}\n"
f" Uwagi: {snapshot.notes or 'brak'}\n" f" Notes: {snapshot.notes or 'none'}\n"
) )
@ -223,8 +223,8 @@ def _build_grooming_context(
select(GroomingSchedule).order_by(col(GroomingSchedule.day_of_week)) select(GroomingSchedule).order_by(col(GroomingSchedule.day_of_week))
).all() ).all()
if not entries: if not entries:
return "HARMONOGRAM PIELĘGNACJI: brak\n" return "GROOMING SCHEDULE: none\n"
lines = ["HARMONOGRAM PIELĘGNACJI:"] lines = ["GROOMING SCHEDULE:"]
for e in entries: for e in entries:
if weekdays is not None and e.day_of_week not in weekdays: if weekdays is not None and e.day_of_week not in weekdays:
continue continue
@ -235,7 +235,7 @@ def _build_grooming_context(
f" {day_name}: {_ev(e.action)}" + (f" ({e.notes})" if e.notes else "") f" {day_name}: {_ev(e.action)}" + (f" ({e.notes})" if e.notes else "")
) )
if len(lines) == 1: if len(lines) == 1:
lines.append(" (brak wpisów dla podanych dni)") lines.append(" (no entries for specified days)")
return "\n".join(lines) + "\n" return "\n".join(lines) + "\n"
@ -247,8 +247,8 @@ def _build_recent_history(session: Session) -> str:
.order_by(col(Routine.routine_date).desc()) .order_by(col(Routine.routine_date).desc())
).all() ).all()
if not routines: if not routines:
return "OSTATNIE RUTYNY: brak\n" return "RECENT ROUTINES: none\n"
lines = ["OSTATNIE RUTYNY:"] lines = ["RECENT ROUTINES:"]
for r in routines: for r in routines:
steps = session.exec( steps = session.exec(
select(RoutineStep) select(RoutineStep)
@ -302,7 +302,7 @@ def _build_products_context(
if pid: if pid:
recent_usage_counts[pid] = recent_usage_counts.get(pid, 0) + 1 recent_usage_counts[pid] = recent_usage_counts.get(pid, 0) + 1
lines = ["DOSTĘPNE PRODUKTY:"] lines = ["AVAILABLE PRODUCTS:"]
for p in products: for p in products:
if p.is_medication and not _is_minoxidil_product(p): if p.is_medication and not _is_minoxidil_product(p):
continue continue
@ -364,9 +364,9 @@ def _build_products_context(
def _build_objectives_context(include_minoxidil_beard: bool) -> str: def _build_objectives_context(include_minoxidil_beard: bool) -> str:
if include_minoxidil_beard: if include_minoxidil_beard:
return ( return (
"CELE UŻYTKOWNIKA:\n" "USER OBJECTIVES:\n"
" - Priorytet: poprawa gęstości brody i wąsów\n" " - Priority: improve beard and mustache density\n"
" - Jeśli dostępny produkt z minoksydylem, uwzględnij go zgodnie z zasadami bezpieczeństwa\n" " - If a product with minoxidil is available, include it adhering strictly to safety rules\n"
) )
return "" return ""
@ -374,8 +374,8 @@ def _build_objectives_context(include_minoxidil_beard: bool) -> str:
def _build_day_context(leaving_home: Optional[bool]) -> str: def _build_day_context(leaving_home: Optional[bool]) -> str:
if leaving_home is None: if leaving_home is None:
return "" return ""
val = "tak" if leaving_home else "nie" val = "yes" if leaving_home else "no"
return f"KONTEKST DNIA:\n Wyjście z domu: {val}\n" return f"DAY CONTEXT:\n Leaving home: {val}\n"
_ROUTINES_SYSTEM_PROMPT = """\ _ROUTINES_SYSTEM_PROMPT = """\
@ -503,13 +503,13 @@ def suggest_routine(
) )
objectives_ctx = _build_objectives_context(data.include_minoxidil_beard) objectives_ctx = _build_objectives_context(data.include_minoxidil_beard)
notes_line = f"\nKONTEKST OD UŻYTKOWNIKA: {data.notes}\n" if data.notes else "" notes_line = f"\nUSER CONTEXT: {data.notes}\n" if data.notes else ""
day_name = _DAY_NAMES[weekday] day_name = _DAY_NAMES[weekday]
prompt = ( prompt = (
f"Zaproponuj rutynę pielęgnacyjną {data.part_of_day.value.upper()} " f"Zaproponuj rutynę pielęgnacyjną {data.part_of_day.value.upper()} "
f"na {data.routine_date} ({day_name}).\n\n" f"na {data.routine_date} ({day_name}).\n\n"
"DANE WEJŚCIOWE:\n" "INPUT DATA:\n"
f"{skin_ctx}\n{grooming_ctx}\n{history_ctx}\n{day_ctx}\n{products_ctx}\n{objectives_ctx}" f"{skin_ctx}\n{grooming_ctx}\n{history_ctx}\n{day_ctx}\n{products_ctx}\n{objectives_ctx}"
f"{notes_line}\n" f"{notes_line}\n"
"Zwróć JSON zgodny ze schematem." "Zwróć JSON zgodny ze schematem."
@ -578,16 +578,16 @@ def suggest_batch(
date_range_lines.append(f" {d} ({_DAY_NAMES[d.weekday()]})") date_range_lines.append(f" {d} ({_DAY_NAMES[d.weekday()]})")
dates_str = "\n".join(date_range_lines) dates_str = "\n".join(date_range_lines)
notes_line = f"\nKONTEKST OD UŻYTKOWNIKA: {data.notes}\n" if data.notes else "" notes_line = f"\nUSER CONTEXT: {data.notes}\n" if data.notes else ""
minimize_line = ( minimize_line = (
"\nOGRANICZENIA:\n - Minimalizuj liczbę unikalnych produktów (używaj tych samych produktów wielokrotnie)\n" "\nCONSTRAINTS:\n - Minimize number of unique products (reuse the same products multiple times)\n"
if data.minimize_products if data.minimize_products
else "" else ""
) )
prompt = ( prompt = (
f"Zaproponuj plan pielęgnacji AM + PM dla każdego dnia z zakresu:\n{dates_str}\n\n" f"Zaproponuj plan pielęgnacji AM + PM dla każdego dnia z zakresu:\n{dates_str}\n\n"
"DANE WEJŚCIOWE:\n" "INPUT DATA:\n"
f"{skin_ctx}\n{grooming_ctx}\n{history_ctx}\n{products_ctx}\n{objectives_ctx}" f"{skin_ctx}\n{grooming_ctx}\n{history_ctx}\n{products_ctx}\n{objectives_ctx}"
f"{notes_line}{minimize_line}" f"{notes_line}{minimize_line}"
"\nZwróć JSON zgodny ze schematem." "\nZwróć JSON zgodny ze schematem."