import json
from pathlib import Path
from agent_utils.llm_interface import call_llm
LOG_PATH = Path("logs/emotion_log.jsonl")
LOG_PATH.parent.mkdir(parents=True, exist_ok=True)
def log_emotion(entry: dict):
with open(LOG_PATH, "a") as f:
f.write(json.dumps(entry) + "\n")
def extract_latent_emotion(text: str) -> str:
prompt = f"""
You're a psychologist AI. Read the following message and infer any deeper, unspoken emotional states.
Message: "{text}"
Return one emotion word only (e.g., 'insecure', 'hopeful', 'ashamed').
"""
response = call_llm(prompt).strip().splitlines()[0]
return response
def save_emotion_log(log_data: list, path: str = "logs/emotion_summary.json"):
with open(path, "w") as f:
json.dump(log_data, f, indent=2)