Spaces:
Sleeping
Sleeping
Upload agent_orchestrator.py
Browse files
metadata_search/agent_orchestrator.py
CHANGED
|
@@ -281,6 +281,46 @@ def agent_chat_payload(body: dict[str, Any]) -> dict[str, Any]:
|
|
| 281 |
|
| 282 |
if discovery:
|
| 283 |
answer = _metadata_overview(search_results, search_query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
strategy = "metadata_overview"
|
| 285 |
document_ids: list[str] = []
|
| 286 |
picked_rows: list[dict[str, Any]] = []
|
|
|
|
| 281 |
|
| 282 |
if discovery:
|
| 283 |
answer = _metadata_overview(search_results, search_query)
|
| 284 |
+
|
| 285 |
+
# Add a concise semantic overview based only on publication titles.
|
| 286 |
+
# Keep the exact counts/distributions above deterministic.
|
| 287 |
+
titles = [
|
| 288 |
+
str(row.get("title") or "").strip()
|
| 289 |
+
for row in search_results
|
| 290 |
+
if str(row.get("title") or "").strip()
|
| 291 |
+
]
|
| 292 |
+
if titles:
|
| 293 |
+
title_context = "\n".join(
|
| 294 |
+
f"{index}. {title}"
|
| 295 |
+
for index, title in enumerate(titles, start=1)
|
| 296 |
+
)
|
| 297 |
+
topic_prompt = (
|
| 298 |
+
"Based ONLY on the publication titles provided, identify the main research topics "
|
| 299 |
+
"represented in these search results. Synthesize related titles into 3-5 concise "
|
| 300 |
+
"themes in one short paragraph. Do not discuss individual papers, do not infer "
|
| 301 |
+
"findings that are not stated in the titles, and do not repeat the year, journal, "
|
| 302 |
+
"or publication-type statistics. Begin exactly with 'Main research topics:'."
|
| 303 |
+
)
|
| 304 |
+
try:
|
| 305 |
+
topic_answer, _, _ = _generate_answer(
|
| 306 |
+
topic_prompt,
|
| 307 |
+
title_context,
|
| 308 |
+
application="general_qa",
|
| 309 |
+
model=body.get("model"),
|
| 310 |
+
)
|
| 311 |
+
topic_answer = str(topic_answer or "").strip()
|
| 312 |
+
if topic_answer:
|
| 313 |
+
prefix = "Main research topics:"
|
| 314 |
+
if topic_answer.lower().startswith(prefix.lower()):
|
| 315 |
+
topic_body = topic_answer[len(prefix):].strip()
|
| 316 |
+
else:
|
| 317 |
+
topic_body = topic_answer
|
| 318 |
+
answer += f"\n\n**Main research topics:** {topic_body}"
|
| 319 |
+
except Exception:
|
| 320 |
+
# Topic synthesis is supplementary; discovery should still succeed
|
| 321 |
+
# if the model cannot generate this optional section.
|
| 322 |
+
pass
|
| 323 |
+
|
| 324 |
strategy = "metadata_overview"
|
| 325 |
document_ids: list[str] = []
|
| 326 |
picked_rows: list[dict[str, Any]] = []
|