Spaces:
Sleeping
Sleeping
ishaan-007 commited on
Commit ·
d3ed4ce
1
Parent(s): fef765c
refinement to handle NoneType error in phase 2
Browse files
tools.py
CHANGED
|
@@ -442,9 +442,9 @@ def label_topics_with_llm(run_key: str = "abstract") -> str:
|
|
| 442 |
# Batch call all models
|
| 443 |
# Truncate to 500 chars per sentence to fit within Groq's 12000 TPM limit
|
| 444 |
topics_json = json.dumps(list(map(lambda s: {"id": s["topic_id"], "sents": [sent[:500] + "..." for sent in s["nearest_sentences"][:2]]}, top)), indent=2)
|
| 445 |
-
res_a = chain_a.invoke({"topics_json": topics_json, "n": len(top)})
|
| 446 |
-
res_b = chain_b.invoke({"topics_json": topics_json, "n": len(top)})
|
| 447 |
-
res_c = chain_c.invoke({"topics_json": topics_json, "n": len(top)})
|
| 448 |
|
| 449 |
idx_a = {str(item["topic_id"]): item for item in res_a}
|
| 450 |
idx_b = {str(item["topic_id"]): item for item in res_b}
|
|
@@ -515,9 +515,9 @@ def consolidate_into_themes(run_key: str = "abstract", theme_map: str = "") -> s
|
|
| 515 |
chain_c = prompt | llm_c | parser
|
| 516 |
|
| 517 |
summary = json.dumps(list(map(lambda t: {"id": t["topic_id"], "lbl": t["label"]}, labelled)), indent=2)
|
| 518 |
-
raw_a = chain_a.invoke({"topics_json": summary})
|
| 519 |
-
raw_b = chain_b.invoke({"topics_json": summary})
|
| 520 |
-
raw_c = chain_c.invoke({"topics_json": summary})
|
| 521 |
|
| 522 |
# Simple comparison of first 2 themes generated
|
| 523 |
l_a = ", ".join(map(lambda x: x["theme_name"], raw_a[:2]))
|
|
@@ -1087,9 +1087,9 @@ def run_ai_council(run_key: str = "abstract") -> str:
|
|
| 1087 |
"n": len(top),
|
| 1088 |
}
|
| 1089 |
|
| 1090 |
-
results_a = chain_a.invoke(input_data)
|
| 1091 |
-
results_b = chain_b.invoke(input_data)
|
| 1092 |
-
results_c = chain_c.invoke(input_data)
|
| 1093 |
|
| 1094 |
idx_a = {str(r["cluster_id"]): r for r in results_a}
|
| 1095 |
idx_b = {str(r["cluster_id"]): r for r in results_b}
|
|
|
|
| 442 |
# Batch call all models
|
| 443 |
# Truncate to 500 chars per sentence to fit within Groq's 12000 TPM limit
|
| 444 |
topics_json = json.dumps(list(map(lambda s: {"id": s["topic_id"], "sents": [sent[:500] + "..." for sent in s["nearest_sentences"][:2]]}, top)), indent=2)
|
| 445 |
+
res_a = chain_a.invoke({"topics_json": topics_json, "n": len(top)}) or []
|
| 446 |
+
res_b = chain_b.invoke({"topics_json": topics_json, "n": len(top)}) or []
|
| 447 |
+
res_c = chain_c.invoke({"topics_json": topics_json, "n": len(top)}) or []
|
| 448 |
|
| 449 |
idx_a = {str(item["topic_id"]): item for item in res_a}
|
| 450 |
idx_b = {str(item["topic_id"]): item for item in res_b}
|
|
|
|
| 515 |
chain_c = prompt | llm_c | parser
|
| 516 |
|
| 517 |
summary = json.dumps(list(map(lambda t: {"id": t["topic_id"], "lbl": t["label"]}, labelled)), indent=2)
|
| 518 |
+
raw_a = chain_a.invoke({"topics_json": summary}) or []
|
| 519 |
+
raw_b = chain_b.invoke({"topics_json": summary}) or []
|
| 520 |
+
raw_c = chain_c.invoke({"topics_json": summary}) or []
|
| 521 |
|
| 522 |
# Simple comparison of first 2 themes generated
|
| 523 |
l_a = ", ".join(map(lambda x: x["theme_name"], raw_a[:2]))
|
|
|
|
| 1087 |
"n": len(top),
|
| 1088 |
}
|
| 1089 |
|
| 1090 |
+
results_a = chain_a.invoke(input_data) or []
|
| 1091 |
+
results_b = chain_b.invoke(input_data) or []
|
| 1092 |
+
results_c = chain_c.invoke(input_data) or []
|
| 1093 |
|
| 1094 |
idx_a = {str(r["cluster_id"]): r for r in results_a}
|
| 1095 |
idx_b = {str(r["cluster_id"]): r for r in results_b}
|