Spaces:
Sleeping
Sleeping
Zeggai Abdellah commited on
Commit Β·
2de691a
1
Parent(s): d2019ea
fix the prompt
Browse files- prepare_env.py +198 -198
- rag_pipeline.py +1 -5
prepare_env.py
CHANGED
|
@@ -356,208 +356,208 @@ def create_section_tools(embedding_function, llm):
|
|
| 356 |
return "Guide retriever not available - main guide file may be missing"
|
| 357 |
return section_tool_wrapper(guide_retriever, guide_path, query)
|
| 358 |
|
| 359 |
-
def who_immunization_tool(query: str) -> str:
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
def program_overview_tool(query: str) -> str:
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
def disease_info_tool(query: str) -> str:
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
def vaccine_properties_tool(query: str) -> str:
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
def catch_up_vaccination_tool(query: str) -> str:
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
def special_populations_tool(query: str) -> str:
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
def cold_chain_tool(query: str) -> str:
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
def injection_safety_tool(query: str) -> str:
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
def session_management_tool(query: str) -> str:
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
def planning_and_logistics_tool(query: str) -> str:
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
def communication_tool(query: str) -> str:
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
|
| 546 |
# Create FunctionTool objects with new, clearer names
|
| 547 |
tools = [
|
| 548 |
FunctionTool.from_defaults(name="general_guide_tool", fn=general_guide_tool),
|
| 549 |
-
FunctionTool.from_defaults(name="who_immunization_tool", fn=who_immunization_tool),
|
| 550 |
-
# Section-specific tools
|
| 551 |
-
FunctionTool.from_defaults(name="program_overview_tool", fn=program_overview_tool),
|
| 552 |
-
FunctionTool.from_defaults(name="disease_info_tool", fn=disease_info_tool),
|
| 553 |
-
FunctionTool.from_defaults(name="vaccine_properties_tool", fn=vaccine_properties_tool),
|
| 554 |
-
FunctionTool.from_defaults(name="catch_up_vaccination_tool", fn=catch_up_vaccination_tool),
|
| 555 |
-
FunctionTool.from_defaults(name="special_populations_tool", fn=special_populations_tool),
|
| 556 |
-
FunctionTool.from_defaults(name="cold_chain_tool", fn=cold_chain_tool),
|
| 557 |
-
FunctionTool.from_defaults(name="injection_safety_tool", fn=injection_safety_tool),
|
| 558 |
-
FunctionTool.from_defaults(name="session_management_tool", fn=session_management_tool),
|
| 559 |
-
FunctionTool.from_defaults(name="planning_and_logistics_tool", fn=planning_and_logistics_tool),
|
| 560 |
-
FunctionTool.from_defaults(name="communication_tool", fn=communication_tool),
|
| 561 |
]
|
| 562 |
|
| 563 |
print(f"β
Created {len(tools)} tools with improved routing descriptions")
|
|
|
|
| 356 |
return "Guide retriever not available - main guide file may be missing"
|
| 357 |
return section_tool_wrapper(guide_retriever, guide_path, query)
|
| 358 |
|
| 359 |
+
# def who_immunization_tool(query: str) -> str:
|
| 360 |
+
# """
|
| 361 |
+
# Provides information from the WHO's 'Immunization in Practice' guide. Use this for questions about
|
| 362 |
+
# **global immunization standards**, international best practices, or for comparing Algerian policy to
|
| 363 |
+
# general WHO recommendations on topics like cold chain, safety, and disease control.
|
| 364 |
+
|
| 365 |
+
# Args:
|
| 366 |
+
# query (str): A question seeking global or general immunization practices.
|
| 367 |
+
|
| 368 |
+
# Returns:
|
| 369 |
+
# str: Content from the WHO Immunization in Practice guide.
|
| 370 |
+
# """
|
| 371 |
+
# print(f"π WHO TOOL CALLED: {query[:50]}...")
|
| 372 |
+
# if not immunization_retriever:
|
| 373 |
+
# return "Immunization in Practice retriever not available - WHO guide file may be missing"
|
| 374 |
+
# return section_tool_wrapper(immunization_retriever, immunization_path, query)
|
| 375 |
+
|
| 376 |
+
# def program_overview_tool(query: str) -> str:
|
| 377 |
+
# """
|
| 378 |
+
# (Section 1) The primary tool for questions about the **history, objectives, and structure** of Algeria's
|
| 379 |
+
# national immunization program (PEV - Programme Γlargi de Vaccination). Use this for topics like
|
| 380 |
+
# the program's rationale, key achievements, and the reasons for updates to the vaccination calendar.
|
| 381 |
+
|
| 382 |
+
# Args:
|
| 383 |
+
# query (str): A question about the foundation or evolution of the PEV.
|
| 384 |
+
|
| 385 |
+
# Returns:
|
| 386 |
+
# str: Response from Section 1.
|
| 387 |
+
# """
|
| 388 |
+
# print(f"π PROGRAM OVERVIEW (S1) TOOL CALLED: {query[:50]}...")
|
| 389 |
+
# if not section_retrievers.get('one'):
|
| 390 |
+
# return "Section 1 retriever not available"
|
| 391 |
+
# return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
|
| 392 |
+
|
| 393 |
+
# def disease_info_tool(query: str) -> str:
|
| 394 |
+
# """
|
| 395 |
+
# (Section 2) The definitive tool for information on **specific vaccine-preventable diseases**.
|
| 396 |
+
# Use this to find details on **symptoms, transmission methods, complications**, and prevention
|
| 397 |
+
# strategies for diseases like Diphtheria, Measles, Polio, Tetanus, etc.
|
| 398 |
+
|
| 399 |
+
# Args:
|
| 400 |
+
# query (str): A question about a disease covered by the national vaccination program.
|
| 401 |
+
|
| 402 |
+
# Returns:
|
| 403 |
+
# str: Disease-specific content from Section 2.
|
| 404 |
+
# """
|
| 405 |
+
# print(f"π¦ DISEASE INFO (S2) TOOL CALLED: {query[:50]}...")
|
| 406 |
+
# if not section_retrievers.get('two'):
|
| 407 |
+
# return "Section 2 retriever not available"
|
| 408 |
+
# return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
|
| 409 |
+
|
| 410 |
+
# def vaccine_properties_tool(query: str) -> str:
|
| 411 |
+
# """
|
| 412 |
+
# (Section 3) The specific tool for questions about the **vaccines themselves**: their types (e.g., BCG, ROR,
|
| 413 |
+
# DTCaVPI), composition, whether they are live or inactivated, and the correct **method of administration**
|
| 414 |
+
# (e.g., intradermal, intramuscular, oral).
|
| 415 |
+
|
| 416 |
+
# Args:
|
| 417 |
+
# query (str): A question about a vaccine's formulation or how it is administered.
|
| 418 |
+
|
| 419 |
+
# Returns:
|
| 420 |
+
# str: Vaccine-specific info from Section 3.
|
| 421 |
+
# """
|
| 422 |
+
# print(f"π VACCINE PROPERTIES (S3) TOOL CALLED: {query[:50]}...")
|
| 423 |
+
# if not section_retrievers.get('three'):
|
| 424 |
+
# return "Section 3 retriever not available"
|
| 425 |
+
# return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
|
| 426 |
+
|
| 427 |
+
# def catch_up_vaccination_tool(query: str) -> str:
|
| 428 |
+
# """
|
| 429 |
+
# (Section 4) Specialized tool for **missed or delayed vaccinations (rattrapage vaccinal)**.
|
| 430 |
+
# Use this for questions about creating a **catch-up schedule** for a child who is behind
|
| 431 |
+
# on their shots, based on their age and vaccination history.
|
| 432 |
+
|
| 433 |
+
# Args:
|
| 434 |
+
# query (str): A question about catch-up vaccination due to a delay or missed dose.
|
| 435 |
+
|
| 436 |
+
# Returns:
|
| 437 |
+
# str: Catch-up schedule guidance from Section 4.
|
| 438 |
+
# """
|
| 439 |
+
# print(f"π CATCH-UP (S4) TOOL CALLED: {query[:50]}...")
|
| 440 |
+
# if not section_retrievers.get('four'):
|
| 441 |
+
# return "Section 4 retriever not available"
|
| 442 |
+
# return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
|
| 443 |
+
|
| 444 |
+
# def special_populations_tool(query: str) -> str:
|
| 445 |
+
# """
|
| 446 |
+
# (Section 5) The designated tool for vaccination guidelines concerning **special populations**.
|
| 447 |
+
# Use for questions about vaccinating preterm infants, allergic children, or patients with
|
| 448 |
+
# immunosuppression, chronic illnesses (cardiac, pulmonary), or other specific health conditions.
|
| 449 |
+
|
| 450 |
+
# Args:
|
| 451 |
+
# query (str): A question about tailored vaccination for a vulnerable or special group.
|
| 452 |
+
|
| 453 |
+
# Returns:
|
| 454 |
+
# str: Custom recommendations from Section 5.
|
| 455 |
+
# """
|
| 456 |
+
# print(f"π₯ SPECIAL POPULATIONS (S5) TOOL CALLED: {query[:50]}...")
|
| 457 |
+
# if not section_retrievers.get('five'):
|
| 458 |
+
# return "Section 5 retriever not available"
|
| 459 |
+
# return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
|
| 460 |
+
|
| 461 |
+
# def cold_chain_tool(query: str) -> str:
|
| 462 |
+
# """
|
| 463 |
+
# (Section 6) The definitive tool for all questions about the **cold chain**, including vaccine **storage
|
| 464 |
+
# temperatures**, transport protocols, refrigerators, temperature monitoring (like PCV pastilles),
|
| 465 |
+
# and procedures for handling cold chain failures or power outages.
|
| 466 |
+
|
| 467 |
+
# Args:
|
| 468 |
+
# query (str): A logistics-related question about vaccine temperature management.
|
| 469 |
+
|
| 470 |
+
# Returns:
|
| 471 |
+
# str: Cold chain instructions from Section 6.
|
| 472 |
+
# """
|
| 473 |
+
# print(f"βοΈ COLD CHAIN (S6) TOOL CALLED: {query[:50]}...")
|
| 474 |
+
# if not section_retrievers.get('six'):
|
| 475 |
+
# return "Section 6 retriever not available"
|
| 476 |
+
# return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
|
| 477 |
+
|
| 478 |
+
# def injection_safety_tool(query: str) -> str:
|
| 479 |
+
# """
|
| 480 |
+
# (Section 7) The primary tool for questions related to the **safe administration of injections**.
|
| 481 |
+
# Use for topics like sterile equipment, proper injection techniques, preventing needlestick injuries,
|
| 482 |
+
# and safe disposal of medical waste (DASRI).
|
| 483 |
+
|
| 484 |
+
# Args:
|
| 485 |
+
# query (str): A question about how to perform vaccine injections safely.
|
| 486 |
+
|
| 487 |
+
# Returns:
|
| 488 |
+
# str: Best practices from Section 7.
|
| 489 |
+
# """
|
| 490 |
+
# print(f"π‘οΈ INJECTION SAFETY (S7) TOOL CALLED: {query[:50]}...")
|
| 491 |
+
# if not section_retrievers.get('seven'):
|
| 492 |
+
# return "Section 7 retriever not available"
|
| 493 |
+
# return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
|
| 494 |
+
|
| 495 |
+
# def session_management_tool(query: str) -> str:
|
| 496 |
+
# """
|
| 497 |
+
# (Section 8) Use this tool for questions about the **operational conduct of a vaccination session**
|
| 498 |
+
# and **vaccinovigilance**. This includes preparing the session, material setup, registering vaccination
|
| 499 |
+
# acts, and monitoring/reporting adverse events post-vaccination (MPVI).
|
| 500 |
+
|
| 501 |
+
# Args:
|
| 502 |
+
# query (str): A question about running a vaccination session or post-vaccine monitoring.
|
| 503 |
+
|
| 504 |
+
# Returns:
|
| 505 |
+
# str: Workflow and safety monitoring details from Section 8.
|
| 506 |
+
# """
|
| 507 |
+
# print(f"π SESSION MGMT (S8) TOOL CALLED: {query[:50]}...")
|
| 508 |
+
# if not section_retrievers.get('eight'):
|
| 509 |
+
# return "Section 8 retriever not available"
|
| 510 |
+
# return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
|
| 511 |
+
|
| 512 |
+
# def planning_and_logistics_tool(query: str) -> str:
|
| 513 |
+
# """
|
| 514 |
+
# (Section 9) This tool is for **planning vaccination sessions and managing logistics**. Use it for
|
| 515 |
+
# questions about creating operational maps, estimating vaccine and supply needs, managing stock,
|
| 516 |
+
# and reducing vaccine wastage.
|
| 517 |
+
|
| 518 |
+
# Args:
|
| 519 |
+
# query (str): A question about organizing vaccination services or managing stock.
|
| 520 |
+
|
| 521 |
+
# Returns:
|
| 522 |
+
# str: Planning and stock guidance from Section 9.
|
| 523 |
+
# """
|
| 524 |
+
# print(f"π
PLANNING & LOGISTICS (S9) TOOL CALLED: {query[:50]}...")
|
| 525 |
+
# if not section_retrievers.get('nine'):
|
| 526 |
+
# return "Section 9 retriever not available"
|
| 527 |
+
# return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
|
| 528 |
+
|
| 529 |
+
# def communication_tool(query: str) -> str:
|
| 530 |
+
# """
|
| 531 |
+
# (Section 10) The specific tool for **social mobilization and communication**. Use this for
|
| 532 |
+
# questions about communication strategies, addressing **vaccine hesitancy**, managing rumors,
|
| 533 |
+
# and community outreach to promote vaccination.
|
| 534 |
+
|
| 535 |
+
# Args:
|
| 536 |
+
# query (str): A question about public engagement or communication for vaccination.
|
| 537 |
+
|
| 538 |
+
# Returns:
|
| 539 |
+
# str: Public mobilization strategies from Section 10.
|
| 540 |
+
# """
|
| 541 |
+
# print(f"π’ COMMUNICATION (S10) TOOL CALLED: {query[:50]}...")
|
| 542 |
+
# if not section_retrievers.get('ten'):
|
| 543 |
+
# return "Section 10 retriever not available"
|
| 544 |
+
# return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
|
| 545 |
|
| 546 |
# Create FunctionTool objects with new, clearer names
|
| 547 |
tools = [
|
| 548 |
FunctionTool.from_defaults(name="general_guide_tool", fn=general_guide_tool),
|
| 549 |
+
# FunctionTool.from_defaults(name="who_immunization_tool", fn=who_immunization_tool),
|
| 550 |
+
# # Section-specific tools
|
| 551 |
+
# FunctionTool.from_defaults(name="program_overview_tool", fn=program_overview_tool),
|
| 552 |
+
# FunctionTool.from_defaults(name="disease_info_tool", fn=disease_info_tool),
|
| 553 |
+
# FunctionTool.from_defaults(name="vaccine_properties_tool", fn=vaccine_properties_tool),
|
| 554 |
+
# FunctionTool.from_defaults(name="catch_up_vaccination_tool", fn=catch_up_vaccination_tool),
|
| 555 |
+
# FunctionTool.from_defaults(name="special_populations_tool", fn=special_populations_tool),
|
| 556 |
+
# FunctionTool.from_defaults(name="cold_chain_tool", fn=cold_chain_tool),
|
| 557 |
+
# FunctionTool.from_defaults(name="injection_safety_tool", fn=injection_safety_tool),
|
| 558 |
+
# FunctionTool.from_defaults(name="session_management_tool", fn=session_management_tool),
|
| 559 |
+
# FunctionTool.from_defaults(name="planning_and_logistics_tool", fn=planning_and_logistics_tool),
|
| 560 |
+
# FunctionTool.from_defaults(name="communication_tool", fn=communication_tool),
|
| 561 |
]
|
| 562 |
|
| 563 |
print(f"β
Created {len(tools)} tools with improved routing descriptions")
|
rag_pipeline.py
CHANGED
|
@@ -184,11 +184,7 @@ After using the tools to gather all necessary information, you MUST synthesize a
|
|
| 184 |
original_template = original_prompts["agent_worker:system_prompt"].template
|
| 185 |
|
| 186 |
# Add instructions at the very beginning, before "You are designed to help..."
|
| 187 |
-
safe_template = f"""{custom_instructions}
|
| 188 |
-
|
| 189 |
-
---
|
| 190 |
-
|
| 191 |
-
{original_template}"""
|
| 192 |
|
| 193 |
# Create new prompt with same metadata as original
|
| 194 |
original_prompt = original_prompts["agent_worker:system_prompt"]
|
|
|
|
| 184 |
original_template = original_prompts["agent_worker:system_prompt"].template
|
| 185 |
|
| 186 |
# Add instructions at the very beginning, before "You are designed to help..."
|
| 187 |
+
safe_template = f"""{custom_instructions}{original_template}"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
# Create new prompt with same metadata as original
|
| 190 |
original_prompt = original_prompts["agent_worker:system_prompt"]
|