Spaces:
Sleeping
Sleeping
Zeggai Abdellah commited on
Commit ยท
2de691a
1
Parent(s): d2019ea
fix the prompt
Browse filesFiles changed (2)
- prepare_env.py+198-198
- rag_pipeline.py+1-5
355 unmodified lines356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563355 unmodified linesreturn "Guide retriever not available - main guide file may be missing"return section_tool_wrapper(guide_retriever, guide_path, query)def who_immunization_tool(query: str) -> str:"""Provides information from the WHO's 'Immunization in Practice' guide. Use this for questions about**global immunization standards**, international best practices, or for comparing Algerian policy togeneral WHO recommendations on topics like cold chain, safety, and disease control.Args:query (str): A question seeking global or general immunization practices.Returns:str: Content from the WHO Immunization in Practice guide."""print(f"๐ WHO TOOL CALLED: {query[:50]}...")if not immunization_retriever:return "Immunization in Practice retriever not available - WHO guide file may be missing"return section_tool_wrapper(immunization_retriever, immunization_path, query)def program_overview_tool(query: str) -> str:"""(Section 1) The primary tool for questions about the **history, objectives, and structure** of Algeria'snational immunization program (PEV - Programme รlargi de Vaccination). Use this for topics likethe program's rationale, key achievements, and the reasons for updates to the vaccination calendar.Args:query (str): A question about the foundation or evolution of the PEV.Returns:str: Response from Section 1."""print(f"๐ PROGRAM OVERVIEW (S1) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('one'):return "Section 1 retriever not available"return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)def disease_info_tool(query: str) -> str:"""(Section 2) The definitive tool for information on **specific vaccine-preventable diseases**.Use this to find details on **symptoms, transmission methods, complications**, and preventionstrategies for diseases like Diphtheria, Measles, Polio, Tetanus, etc.Args:query (str): A question about a disease covered by the national vaccination program.Returns:str: Disease-specific content from Section 2."""print(f"๐ฆ DISEASE INFO (S2) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('two'):return "Section 2 retriever not available"return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)def vaccine_properties_tool(query: str) -> str:"""(Section 3) The specific tool for questions about the **vaccines themselves**: their types (e.g., BCG, ROR,DTCaVPI), composition, whether they are live or inactivated, and the correct **method of administration**(e.g., intradermal, intramuscular, oral).Args:query (str): A question about a vaccine's formulation or how it is administered.Returns:str: Vaccine-specific info from Section 3."""print(f"๐ VACCINE PROPERTIES (S3) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('three'):return "Section 3 retriever not available"return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)def catch_up_vaccination_tool(query: str) -> str:"""(Section 4) Specialized tool for **missed or delayed vaccinations (rattrapage vaccinal)**.Use this for questions about creating a **catch-up schedule** for a child who is behindon their shots, based on their age and vaccination history.Args:query (str): A question about catch-up vaccination due to a delay or missed dose.Returns:str: Catch-up schedule guidance from Section 4."""print(f"๐ CATCH-UP (S4) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('four'):return "Section 4 retriever not available"return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)def special_populations_tool(query: str) -> str:"""(Section 5) The designated tool for vaccination guidelines concerning **special populations**.Use for questions about vaccinating preterm infants, allergic children, or patients withimmunosuppression, chronic illnesses (cardiac, pulmonary), or other specific health conditions.Args:query (str): A question about tailored vaccination for a vulnerable or special group.Returns:str: Custom recommendations from Section 5."""print(f"๐ฅ SPECIAL POPULATIONS (S5) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('five'):return "Section 5 retriever not available"return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)def cold_chain_tool(query: str) -> str:"""(Section 6) The definitive tool for all questions about the **cold chain**, including vaccine **storagetemperatures**, transport protocols, refrigerators, temperature monitoring (like PCV pastilles),and procedures for handling cold chain failures or power outages.Args:query (str): A logistics-related question about vaccine temperature management.Returns:str: Cold chain instructions from Section 6."""print(f"โ๏ธ COLD CHAIN (S6) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('six'):return "Section 6 retriever not available"return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)def injection_safety_tool(query: str) -> str:"""(Section 7) The primary tool for questions related to the **safe administration of injections**.Use for topics like sterile equipment, proper injection techniques, preventing needlestick injuries,and safe disposal of medical waste (DASRI).Args:query (str): A question about how to perform vaccine injections safely.Returns:str: Best practices from Section 7."""print(f"๐ก๏ธ INJECTION SAFETY (S7) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('seven'):return "Section 7 retriever not available"return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)def session_management_tool(query: str) -> str:"""(Section 8) Use this tool for questions about the **operational conduct of a vaccination session**and **vaccinovigilance**. This includes preparing the session, material setup, registering vaccinationacts, and monitoring/reporting adverse events post-vaccination (MPVI).Args:query (str): A question about running a vaccination session or post-vaccine monitoring.Returns:str: Workflow and safety monitoring details from Section 8."""print(f"๐ SESSION MGMT (S8) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('eight'):return "Section 8 retriever not available"return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)def planning_and_logistics_tool(query: str) -> str:"""(Section 9) This tool is for **planning vaccination sessions and managing logistics**. Use it forquestions about creating operational maps, estimating vaccine and supply needs, managing stock,and reducing vaccine wastage.Args:query (str): A question about organizing vaccination services or managing stock.Returns:str: Planning and stock guidance from Section 9."""print(f"๐ PLANNING & LOGISTICS (S9) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('nine'):return "Section 9 retriever not available"return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)def communication_tool(query: str) -> str:"""(Section 10) The specific tool for **social mobilization and communication**. Use this forquestions about communication strategies, addressing **vaccine hesitancy**, managing rumors,and community outreach to promote vaccination.Args:query (str): A question about public engagement or communication for vaccination.Returns:str: Public mobilization strategies from Section 10."""print(f"๐ข COMMUNICATION (S10) TOOL CALLED: {query[:50]}...")if not section_retrievers.get('ten'):return "Section 10 retriever not available"return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)# Create FunctionTool objects with new, clearer namestools = [FunctionTool.from_defaults(name="general_guide_tool", fn=general_guide_tool),FunctionTool.from_defaults(name="who_immunization_tool", fn=who_immunization_tool),# Section-specific toolsFunctionTool.from_defaults(name="program_overview_tool", fn=program_overview_tool),FunctionTool.from_defaults(name="disease_info_tool", fn=disease_info_tool),FunctionTool.from_defaults(name="vaccine_properties_tool", fn=vaccine_properties_tool),FunctionTool.from_defaults(name="catch_up_vaccination_tool", fn=catch_up_vaccination_tool),FunctionTool.from_defaults(name="special_populations_tool", fn=special_populations_tool),FunctionTool.from_defaults(name="cold_chain_tool", fn=cold_chain_tool),FunctionTool.from_defaults(name="injection_safety_tool", fn=injection_safety_tool),FunctionTool.from_defaults(name="session_management_tool", fn=session_management_tool),FunctionTool.from_defaults(name="planning_and_logistics_tool", fn=planning_and_logistics_tool),FunctionTool.from_defaults(name="communication_tool", fn=communication_tool),]print(f"โ Created {len(tools)} tools with improved routing descriptions")355 unmodified lines356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563355 unmodified linesreturn "Guide retriever not available - main guide file may be missing"return section_tool_wrapper(guide_retriever, guide_path, query)# def who_immunization_tool(query: str) -> str:# """# Provides information from the WHO's 'Immunization in Practice' guide. Use this for questions about# **global immunization standards**, international best practices, or for comparing Algerian policy to# general WHO recommendations on topics like cold chain, safety, and disease control.# Args:# query (str): A question seeking global or general immunization practices.# Returns:# str: Content from the WHO Immunization in Practice guide.# """# print(f"๐ WHO TOOL CALLED: {query[:50]}...")# if not immunization_retriever:# return "Immunization in Practice retriever not available - WHO guide file may be missing"# return section_tool_wrapper(immunization_retriever, immunization_path, query)# def program_overview_tool(query: str) -> str:# """# (Section 1) The primary tool for questions about the **history, objectives, and structure** of Algeria's# national immunization program (PEV - Programme รlargi de Vaccination). Use this for topics like# the program's rationale, key achievements, and the reasons for updates to the vaccination calendar.# Args:# query (str): A question about the foundation or evolution of the PEV.# Returns:# str: Response from Section 1.# """# print(f"๐ PROGRAM OVERVIEW (S1) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('one'):# return "Section 1 retriever not available"# return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)# def disease_info_tool(query: str) -> str:# """# (Section 2) The definitive tool for information on **specific vaccine-preventable diseases**.# Use this to find details on **symptoms, transmission methods, complications**, and prevention# strategies for diseases like Diphtheria, Measles, Polio, Tetanus, etc.# Args:# query (str): A question about a disease covered by the national vaccination program.# Returns:# str: Disease-specific content from Section 2.# """# print(f"๐ฆ DISEASE INFO (S2) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('two'):# return "Section 2 retriever not available"# return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)# def vaccine_properties_tool(query: str) -> str:# """# (Section 3) The specific tool for questions about the **vaccines themselves**: their types (e.g., BCG, ROR,# DTCaVPI), composition, whether they are live or inactivated, and the correct **method of administration**# (e.g., intradermal, intramuscular, oral).# Args:# query (str): A question about a vaccine's formulation or how it is administered.# Returns:# str: Vaccine-specific info from Section 3.# """# print(f"๐ VACCINE PROPERTIES (S3) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('three'):# return "Section 3 retriever not available"# return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)# def catch_up_vaccination_tool(query: str) -> str:# """# (Section 4) Specialized tool for **missed or delayed vaccinations (rattrapage vaccinal)**.# Use this for questions about creating a **catch-up schedule** for a child who is behind# on their shots, based on their age and vaccination history.# Args:# query (str): A question about catch-up vaccination due to a delay or missed dose.# Returns:# str: Catch-up schedule guidance from Section 4.# """# print(f"๐ CATCH-UP (S4) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('four'):# return "Section 4 retriever not available"# return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)# def special_populations_tool(query: str) -> str:# """# (Section 5) The designated tool for vaccination guidelines concerning **special populations**.# Use for questions about vaccinating preterm infants, allergic children, or patients with# immunosuppression, chronic illnesses (cardiac, pulmonary), or other specific health conditions.# Args:# query (str): A question about tailored vaccination for a vulnerable or special group.# Returns:# str: Custom recommendations from Section 5.# """# print(f"๐ฅ SPECIAL POPULATIONS (S5) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('five'):# return "Section 5 retriever not available"# return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)# def cold_chain_tool(query: str) -> str:# """# (Section 6) The definitive tool for all questions about the **cold chain**, including vaccine **storage# temperatures**, transport protocols, refrigerators, temperature monitoring (like PCV pastilles),# and procedures for handling cold chain failures or power outages.# Args:# query (str): A logistics-related question about vaccine temperature management.# Returns:# str: Cold chain instructions from Section 6.# """# print(f"โ๏ธ COLD CHAIN (S6) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('six'):# return "Section 6 retriever not available"# return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)# def injection_safety_tool(query: str) -> str:# """# (Section 7) The primary tool for questions related to the **safe administration of injections**.# Use for topics like sterile equipment, proper injection techniques, preventing needlestick injuries,# and safe disposal of medical waste (DASRI).# Args:# query (str): A question about how to perform vaccine injections safely.# Returns:# str: Best practices from Section 7.# """# print(f"๐ก๏ธ INJECTION SAFETY (S7) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('seven'):# return "Section 7 retriever not available"# return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)# def session_management_tool(query: str) -> str:# """# (Section 8) Use this tool for questions about the **operational conduct of a vaccination session**# and **vaccinovigilance**. This includes preparing the session, material setup, registering vaccination# acts, and monitoring/reporting adverse events post-vaccination (MPVI).# Args:# query (str): A question about running a vaccination session or post-vaccine monitoring.# Returns:# str: Workflow and safety monitoring details from Section 8.# """# print(f"๐ SESSION MGMT (S8) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('eight'):# return "Section 8 retriever not available"# return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)# def planning_and_logistics_tool(query: str) -> str:# """# (Section 9) This tool is for **planning vaccination sessions and managing logistics**. Use it for# questions about creating operational maps, estimating vaccine and supply needs, managing stock,# and reducing vaccine wastage.# Args:# query (str): A question about organizing vaccination services or managing stock.# Returns:# str: Planning and stock guidance from Section 9.# """# print(f"๐ PLANNING & LOGISTICS (S9) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('nine'):# return "Section 9 retriever not available"# return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)# def communication_tool(query: str) -> str:# """# (Section 10) The specific tool for **social mobilization and communication**. Use this for# questions about communication strategies, addressing **vaccine hesitancy**, managing rumors,# and community outreach to promote vaccination.# Args:# query (str): A question about public engagement or communication for vaccination.# Returns:# str: Public mobilization strategies from Section 10.# """# print(f"๐ข COMMUNICATION (S10) TOOL CALLED: {query[:50]}...")# if not section_retrievers.get('ten'):# return "Section 10 retriever not available"# return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)# Create FunctionTool objects with new, clearer namestools = [FunctionTool.from_defaults(name="general_guide_tool", fn=general_guide_tool),# FunctionTool.from_defaults(name="who_immunization_tool", fn=who_immunization_tool),# # Section-specific tools# FunctionTool.from_defaults(name="program_overview_tool", fn=program_overview_tool),# FunctionTool.from_defaults(name="disease_info_tool", fn=disease_info_tool),# FunctionTool.from_defaults(name="vaccine_properties_tool", fn=vaccine_properties_tool),# FunctionTool.from_defaults(name="catch_up_vaccination_tool", fn=catch_up_vaccination_tool),# FunctionTool.from_defaults(name="special_populations_tool", fn=special_populations_tool),# FunctionTool.from_defaults(name="cold_chain_tool", fn=cold_chain_tool),# FunctionTool.from_defaults(name="injection_safety_tool", fn=injection_safety_tool),# FunctionTool.from_defaults(name="session_management_tool", fn=session_management_tool),# FunctionTool.from_defaults(name="planning_and_logistics_tool", fn=planning_and_logistics_tool),# FunctionTool.from_defaults(name="communication_tool", fn=communication_tool),]print(f"โ Created {len(tools)} tools with improved routing descriptions")
183 unmodified lines184185186187188189190191192193194183 unmodified linesoriginal_template = original_prompts["agent_worker:system_prompt"].template# Add instructions at the very beginning, before "You are designed to help..."safe_template = f"""{custom_instructions}---{original_template}"""# Create new prompt with same metadata as originaloriginal_prompt = original_prompts["agent_worker:system_prompt"]183 unmodified lines184185186187188189190183 unmodified linesoriginal_template = original_prompts["agent_worker:system_prompt"].template# Add instructions at the very beginning, before "You are designed to help..."safe_template = f"""{custom_instructions}{original_template}"""# Create new prompt with same metadata as originaloriginal_prompt = original_prompts["agent_worker:system_prompt"]
prepare_env.py+198-198
rag_pipeline.py+1-5