jmisak's picture
Upload folder using huggingface_hub
15b744c verified
raw
history blame contribute delete
784 Bytes
def apply_stimuli(persona, event):
drift = persona.get("segment_drift", {}).get("triggers", {})
state = persona.get("dynamic_state", {})
inertia = state.get("inertia", 0.5)
for key, raw_impact in drift.items():
if key == event["event"]:
try:
impact = float(raw_impact)
except ValueError:
continue # skip if impact isn't numeric
for trait, value in state.items():
if isinstance(value, (int, float)) and trait != "inertia":
updated = round(value + impact * (1 - inertia), 3)
state[trait] = max(0.0, min(1.0, updated)) # clamp between 0–1
state["last_updated"] = event.get("date", "unknown")
return persona