Spaces:
Sleeping
Sleeping
Zeggai Abdellah
commited on
Commit
·
938709d
1
Parent(s):
9317650
update tool description
Browse files- prepare_env.py +189 -28
prepare_env.py
CHANGED
|
@@ -225,66 +225,227 @@ def create_section_tools(embedding_function, llm):
|
|
| 225 |
guide_retriever = create_retriever(guide_vstore, guide_docs, llm)
|
| 226 |
else:
|
| 227 |
guide_retriever = None
|
| 228 |
-
|
| 229 |
-
# Define tool functions
|
| 230 |
def guide_retrieval_tool(query: str) -> str:
|
| 231 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
if not guide_retriever:
|
| 233 |
return "Guide retriever not available"
|
| 234 |
return section_tool_wrapper(guide_retriever, guide_path, query)
|
| 235 |
-
|
| 236 |
-
#
|
| 237 |
immunization_path = './data/Immunization_in_Practice_WHO_eng_2015.json'
|
|
|
|
|
|
|
| 238 |
if os.path.exists(immunization_path):
|
| 239 |
-
immunization_vstore, immunization_docs = create_vectorstore_from_json(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
immunization_retriever = create_retriever(immunization_vstore, immunization_docs, llm)
|
| 241 |
else:
|
| 242 |
immunization_retriever = None
|
| 243 |
-
|
| 244 |
def immunization_tool(query: str) -> str:
|
| 245 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
if not immunization_retriever:
|
| 247 |
return "Immunization in Practice retriever not available"
|
| 248 |
return section_tool_wrapper(immunization_retriever, immunization_path, query)
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
def section_one_tool(query: str) -> str:
|
| 251 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
|
| 253 |
-
|
|
|
|
| 254 |
def section_two_tool(query: str) -> str:
|
| 255 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
|
| 257 |
-
|
|
|
|
| 258 |
def section_three_tool(query: str) -> str:
|
| 259 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
|
| 261 |
-
|
|
|
|
| 262 |
def section_four_tool(query: str) -> str:
|
| 263 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
|
| 265 |
-
|
|
|
|
| 266 |
def section_five_tool(query: str) -> str:
|
| 267 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
|
| 269 |
-
|
|
|
|
| 270 |
def section_six_tool(query: str) -> str:
|
| 271 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
|
| 273 |
-
|
|
|
|
| 274 |
def section_seven_tool(query: str) -> str:
|
| 275 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
|
| 277 |
-
|
|
|
|
| 278 |
def section_eight_tool(query: str) -> str:
|
| 279 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
|
| 281 |
-
|
|
|
|
| 282 |
def section_nine_tool(query: str) -> str:
|
| 283 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
|
| 285 |
-
|
|
|
|
| 286 |
def section_ten_tool(query: str) -> str:
|
| 287 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
|
| 289 |
|
| 290 |
# Create FunctionTool objects
|
|
|
|
| 225 |
guide_retriever = create_retriever(guide_vstore, guide_docs, llm)
|
| 226 |
else:
|
| 227 |
guide_retriever = None
|
| 228 |
+
# General-purpose tool (entire Algerian guide)
|
|
|
|
| 229 |
def guide_retrieval_tool(query: str) -> str:
|
| 230 |
+
"""
|
| 231 |
+
General-purpose retrieval tool for the entire Algerian National Vaccination Guide (2023).
|
| 232 |
+
|
| 233 |
+
Use this tool when a query spans multiple sections or cannot be routed confidently to a specific tool.
|
| 234 |
+
This is the fallback and all-encompassing tool to retrieve any vaccination-related information
|
| 235 |
+
from the national guide.
|
| 236 |
+
|
| 237 |
+
Secondary source: The WHO Immunization Guide can be queried separately via `immunization_tool`.
|
| 238 |
+
|
| 239 |
+
Args:
|
| 240 |
+
query (str): A general or complex question related to vaccination policy, schedules, or practice.
|
| 241 |
+
|
| 242 |
+
Returns:
|
| 243 |
+
str: Synthesized response based on the full Algerian guide.
|
| 244 |
+
"""
|
| 245 |
if not guide_retriever:
|
| 246 |
return "Guide retriever not available"
|
| 247 |
return section_tool_wrapper(guide_retriever, guide_path, query)
|
| 248 |
+
|
| 249 |
+
# Primary + Secondary Document Paths
|
| 250 |
immunization_path = './data/Immunization_in_Practice_WHO_eng_2015.json'
|
| 251 |
+
|
| 252 |
+
# WHO Immunization in Practice Tool
|
| 253 |
if os.path.exists(immunization_path):
|
| 254 |
+
immunization_vstore, immunization_docs = create_vectorstore_from_json(
|
| 255 |
+
immunization_path,
|
| 256 |
+
"Immunization_in_Practice_WHO_eng_2015",
|
| 257 |
+
embedding_function
|
| 258 |
+
)
|
| 259 |
immunization_retriever = create_retriever(immunization_vstore, immunization_docs, llm)
|
| 260 |
else:
|
| 261 |
immunization_retriever = None
|
| 262 |
+
|
| 263 |
def immunization_tool(query: str) -> str:
|
| 264 |
+
"""
|
| 265 |
+
WHO Immunization in Practice 2015 retrieval tool.
|
| 266 |
+
|
| 267 |
+
Use this tool to provide global best practices and operational guidance on immunization,
|
| 268 |
+
especially when context or clarification is needed beyond the Algerian national guide.
|
| 269 |
+
This can serve as a secondary source for training, logistics, and procedural reference.
|
| 270 |
+
|
| 271 |
+
Args:
|
| 272 |
+
query (str): A question related to immunization practice in general.
|
| 273 |
+
|
| 274 |
+
Returns:
|
| 275 |
+
str: Retrieved guidance from the WHO Immunization in Practice manual (2015).
|
| 276 |
+
"""
|
| 277 |
if not immunization_retriever:
|
| 278 |
return "Immunization in Practice retriever not available"
|
| 279 |
return section_tool_wrapper(immunization_retriever, immunization_path, query)
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# Section-Specific Tools (Primary: Algerian National Vaccination Guide)
|
| 284 |
+
|
| 285 |
def section_one_tool(query: str) -> str:
|
| 286 |
+
"""
|
| 287 |
+
Section 1: Programme Élargi de Vaccination (PEV)
|
| 288 |
+
|
| 289 |
+
Use this tool to retrieve information about the Algerian immunization program:
|
| 290 |
+
its objectives, historical background, strengths and weaknesses, and justification
|
| 291 |
+
for calendar updates.
|
| 292 |
+
|
| 293 |
+
Primary source: Algerian National Vaccination Guide, Section 1.
|
| 294 |
+
Secondary source for operational benchmarks: WHO Immunization in Practice (optional).
|
| 295 |
+
|
| 296 |
+
Args:
|
| 297 |
+
query (str): A question about Algeria’s national immunization strategy.
|
| 298 |
+
|
| 299 |
+
Returns:
|
| 300 |
+
str: Relevant content from Section 1 of the guide.
|
| 301 |
+
"""
|
| 302 |
return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
|
| 303 |
+
|
| 304 |
+
|
| 305 |
def section_two_tool(query: str) -> str:
|
| 306 |
+
"""
|
| 307 |
+
Section 2: Maladies Ciblées par la Vaccination
|
| 308 |
+
|
| 309 |
+
Use this tool for questions about the diseases targeted by the national vaccination calendar:
|
| 310 |
+
symptoms, transmission, complications, and prevention strategies.
|
| 311 |
+
|
| 312 |
+
Primary source: Algerian National Guide, Section 2.
|
| 313 |
+
Secondary source: WHO guide may support contextual insights.
|
| 314 |
+
|
| 315 |
+
Args:
|
| 316 |
+
query (str): A question about a vaccine-preventable disease (e.g. polio, rougeole).
|
| 317 |
+
|
| 318 |
+
Returns:
|
| 319 |
+
str: Disease-specific guidance from Section 2.
|
| 320 |
+
"""
|
| 321 |
return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
|
| 322 |
+
|
| 323 |
+
|
| 324 |
def section_three_tool(query: str) -> str:
|
| 325 |
+
"""
|
| 326 |
+
Section 3: Vaccins du Calendrier
|
| 327 |
+
|
| 328 |
+
Use this tool to retrieve technical and procedural information about the vaccines used in the calendar:
|
| 329 |
+
names, contents, administration method, and dosing details.
|
| 330 |
+
|
| 331 |
+
Args:
|
| 332 |
+
query (str): A question about a specific vaccine's type or method of use.
|
| 333 |
+
|
| 334 |
+
Returns:
|
| 335 |
+
str: Vaccine information from Section 3.
|
| 336 |
+
"""
|
| 337 |
return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
def section_four_tool(query: str) -> str:
|
| 341 |
+
"""
|
| 342 |
+
Section 4: Rattrapage Vaccinal
|
| 343 |
+
|
| 344 |
+
Use this tool to determine catch-up strategies for children who missed or delayed one or more doses.
|
| 345 |
+
It provides age-adjusted rescheduling rules and justifications.
|
| 346 |
+
|
| 347 |
+
Args:
|
| 348 |
+
query (str): A question about how to manage missed vaccinations.
|
| 349 |
+
|
| 350 |
+
Returns:
|
| 351 |
+
str: Catch-up guidelines from Section 4.
|
| 352 |
+
"""
|
| 353 |
return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
|
| 354 |
+
|
| 355 |
+
|
| 356 |
def section_five_tool(query: str) -> str:
|
| 357 |
+
"""
|
| 358 |
+
Section 5: Vaccination des Populations Particulières
|
| 359 |
+
|
| 360 |
+
Use this tool to retrieve recommendations for specific medical contexts:
|
| 361 |
+
preterm infants, immunocompromised children, allergies (e.g. eggs), and chronic diseases.
|
| 362 |
+
|
| 363 |
+
Args:
|
| 364 |
+
query (str): A question about vaccination adaptations for vulnerable groups.
|
| 365 |
+
|
| 366 |
+
Returns:
|
| 367 |
+
str: Guidelines from Section 5.
|
| 368 |
+
"""
|
| 369 |
return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
|
| 370 |
+
|
| 371 |
+
|
| 372 |
def section_six_tool(query: str) -> str:
|
| 373 |
+
"""
|
| 374 |
+
Section 6: Chaîne du Froid
|
| 375 |
+
|
| 376 |
+
Use this tool for logistics, storage conditions, temperature monitoring,
|
| 377 |
+
and emergency procedures in case of cold chain failure.
|
| 378 |
+
|
| 379 |
+
Args:
|
| 380 |
+
query (str): A question about how vaccines should be stored and transported.
|
| 381 |
+
|
| 382 |
+
Returns:
|
| 383 |
+
str: Operational cold chain standards from Section 6.
|
| 384 |
+
"""
|
| 385 |
return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
def section_seven_tool(query: str) -> str:
|
| 389 |
+
"""
|
| 390 |
+
Section 7: Sécurité des Injections
|
| 391 |
+
|
| 392 |
+
Use this tool to ensure injection safety: handling equipment, preventing needle-stick injuries,
|
| 393 |
+
and disposing of biomedical waste.
|
| 394 |
+
|
| 395 |
+
Args:
|
| 396 |
+
query (str): A question about safe injection practices.
|
| 397 |
+
|
| 398 |
+
Returns:
|
| 399 |
+
str: Procedures and guidelines from Section 7.
|
| 400 |
+
"""
|
| 401 |
return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
|
| 402 |
+
|
| 403 |
+
|
| 404 |
def section_eight_tool(query: str) -> str:
|
| 405 |
+
"""
|
| 406 |
+
Section 8: Tenue d'une Séance de Vaccination & Vaccinovigilance
|
| 407 |
+
|
| 408 |
+
Use this tool to plan and monitor vaccination sessions, including material preparation,
|
| 409 |
+
injection recording, and handling of adverse events post-immunization (AEFI).
|
| 410 |
+
|
| 411 |
+
Args:
|
| 412 |
+
query (str): A question about session operations or vaccine side effect monitoring.
|
| 413 |
+
|
| 414 |
+
Returns:
|
| 415 |
+
str: Guidelines from Section 8.
|
| 416 |
+
"""
|
| 417 |
return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
|
| 418 |
+
|
| 419 |
+
|
| 420 |
def section_nine_tool(query: str) -> str:
|
| 421 |
+
"""
|
| 422 |
+
Section 9: Planification des Séances de Vaccination
|
| 423 |
+
|
| 424 |
+
Use this tool to support logistical planning: mapping, resource estimation,
|
| 425 |
+
scheduling, and stock management.
|
| 426 |
+
|
| 427 |
+
Args:
|
| 428 |
+
query (str): A question about planning and organizing vaccination sessions.
|
| 429 |
+
|
| 430 |
+
Returns:
|
| 431 |
+
str: Recommendations from Section 9.
|
| 432 |
+
"""
|
| 433 |
return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
|
| 434 |
+
|
| 435 |
+
|
| 436 |
def section_ten_tool(query: str) -> str:
|
| 437 |
+
"""
|
| 438 |
+
Section 10: Mobilisation Sociale
|
| 439 |
+
|
| 440 |
+
Use this tool for strategies to increase public engagement, combat vaccine hesitancy,
|
| 441 |
+
and manage misinformation.
|
| 442 |
+
|
| 443 |
+
Args:
|
| 444 |
+
query (str): A question about public communication and trust-building around vaccines.
|
| 445 |
+
|
| 446 |
+
Returns:
|
| 447 |
+
str: Social mobilization approaches from Section 10.
|
| 448 |
+
"""
|
| 449 |
return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
|
| 450 |
|
| 451 |
# Create FunctionTool objects
|