This commit is contained in:
Timothy Jaeryang Baek
2025-08-21 04:40:08 +04:00
parent d720e027ad
commit 66f00ce4bf

View File

@@ -39,40 +39,43 @@ def prompt_variables_template(template: str, variables: dict[str, str]) -> str:
def prompt_template(template: str, user: Optional[Any] = None) -> str: def prompt_template(template: str, user: Optional[Any] = None) -> str:
if hasattr(user, "model_dump"):
user = user.model_dump()
USER_VARIABLES = {} USER_VARIABLES = {}
if isinstance(user, dict): if user:
birth_date = user.get("date_of_birth") if hasattr(user, "model_dump"):
age = None user = user.model_dump()
if birth_date: if isinstance(user, dict):
try: birth_date = user.get("date_of_birth")
# If birth_date is str, convert to datetime age = None
if isinstance(birth_date, str):
birth_date = datetime.strptime(birth_date, "%Y-%m-%d")
today = datetime.now() if birth_date:
age = ( try:
today.year # If birth_date is str, convert to datetime
- birth_date.year if isinstance(birth_date, str):
- ((today.month, today.day) < (birth_date.month, birth_date.day)) birth_date = datetime.strptime(birth_date, "%Y-%m-%d")
)
except Exception as e:
pass
USER_VARIABLES = { today = datetime.now()
"name": str(user.get("name")), age = (
"location": str(user.get("info", {}).get("location")), today.year
"bio": str(user.get("bio")), - birth_date.year
"gender": str(user.get("gender")), - (
"birth_date": str(birth_date), (today.month, today.day)
"age": str(age), < (birth_date.month, birth_date.day)
} )
)
except Exception as e:
pass
print(USER_VARIABLES) USER_VARIABLES = {
"name": str(user.get("name")),
"location": str(user.get("info", {}).get("location")),
"bio": str(user.get("bio")),
"gender": str(user.get("gender")),
"birth_date": str(birth_date),
"age": str(age),
}
# Get the current date # Get the current date
current_date = datetime.now() current_date = datetime.now()