Spaces:
Sleeping
Sleeping
Update alz_companion/agent.py
Browse files- alz_companion/agent.py +19 -5
alz_companion/agent.py
CHANGED
|
@@ -136,12 +136,26 @@ def detect_tags_from_query(query: str, behavior_options: list, emotion_options:
|
|
| 136 |
if start_brace != -1 and end_brace != -1 and end_brace > start_brace:
|
| 137 |
json_str = response_str[start_brace : end_brace + 1]
|
| 138 |
result = json.loads(json_str)
|
| 139 |
-
|
|
|
|
| 140 |
# Safely process the results from the LLM
|
| 141 |
-
|
| 142 |
-
result_dict["
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
# --- END OF ROBUST LOGIC ---
|
| 146 |
|
| 147 |
return result_dict
|
|
|
|
| 136 |
if start_brace != -1 and end_brace != -1 and end_brace > start_brace:
|
| 137 |
json_str = response_str[start_brace : end_brace + 1]
|
| 138 |
result = json.loads(json_str)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
# Safely process the results from the LLM
|
| 142 |
+
behaviors = result.get("detected_behaviors")
|
| 143 |
+
result_dict["detected_behaviors"] = [b for b in behaviors if b in behavior_options] if behaviors else []
|
| 144 |
+
|
| 145 |
+
emotion = result.get("detected_emotion")
|
| 146 |
+
result_dict["detected_emotion"] = emotion if emotion in emotion_options else "None"
|
| 147 |
+
|
| 148 |
+
topic = result.get("detected_topic")
|
| 149 |
+
result_dict["detected_topic"] = topic if topic in topic_options else "None"
|
| 150 |
+
|
| 151 |
+
contexts = result.get("detected_contexts") # This could be None
|
| 152 |
+
result_dict["detected_contexts"] = [c for c in contexts if c in context_options] if contexts else [] # Check if contexts is not None
|
| 153 |
+
|
| 154 |
+
# old code
|
| 155 |
+
# result_dict["detected_behaviors"] = [b for b in result.get("detected_behaviors", []) if b in behavior_options]
|
| 156 |
+
# result_dict["detected_emotion"] = result.get("detected_emotion") if result.get("detected_emotion") in emotion_options else "None"
|
| 157 |
+
# result_dict["detected_topic"] = result.get("detected_topic") if result.get("detected_topic") in topic_options else "None"
|
| 158 |
+
# result_dict["detected_contexts"] = [c for c in result.get("detected_contexts", []) if c in context_options]
|
| 159 |
# --- END OF ROBUST LOGIC ---
|
| 160 |
|
| 161 |
return result_dict
|