Spaces:
Sleeping
Sleeping
Zeggai Abdellah commited on
Commit ·
c06c6fb
1
Parent(s): 11ba922
update tool descrition to not overlaping
Browse files- prepare_env.py +92 -75
prepare_env.py
CHANGED
|
@@ -225,98 +225,100 @@ def create_section_tools(embedding_function, llm):
|
|
| 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
|
| 234 |
-
|
| 235 |
-
|
| 236 |
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
Args:
|
| 240 |
-
query (str): A general
|
| 241 |
|
| 242 |
Returns:
|
| 243 |
-
str: Synthesized
|
| 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
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
| 270 |
|
| 271 |
Args:
|
| 272 |
-
query (str): A question
|
| 273 |
|
| 274 |
Returns:
|
| 275 |
-
str:
|
| 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
|
| 290 |
-
|
| 291 |
-
for calendar updates.
|
| 292 |
|
| 293 |
-
|
| 294 |
-
Secondary source for operational benchmarks: WHO Immunization in Practice (optional).
|
| 295 |
|
| 296 |
Args:
|
| 297 |
-
query (str): A question about
|
| 298 |
|
| 299 |
Returns:
|
| 300 |
-
str:
|
| 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
|
| 308 |
|
| 309 |
-
Use
|
| 310 |
-
symptoms, transmission, complications, and prevention
|
| 311 |
|
| 312 |
-
|
| 313 |
-
Secondary source: WHO guide may support contextual insights.
|
| 314 |
|
| 315 |
Args:
|
| 316 |
-
query (str): A question about a
|
| 317 |
|
| 318 |
Returns:
|
| 319 |
-
str: Disease-specific
|
| 320 |
"""
|
| 321 |
return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
|
| 322 |
|
|
@@ -325,14 +327,16 @@ def create_section_tools(embedding_function, llm):
|
|
| 325 |
"""
|
| 326 |
Section 3: Vaccins du Calendrier
|
| 327 |
|
| 328 |
-
Use
|
| 329 |
-
|
|
|
|
|
|
|
| 330 |
|
| 331 |
Args:
|
| 332 |
-
query (str): A question about a
|
| 333 |
|
| 334 |
Returns:
|
| 335 |
-
str: Vaccine
|
| 336 |
"""
|
| 337 |
return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
|
| 338 |
|
|
@@ -341,30 +345,34 @@ def create_section_tools(embedding_function, llm):
|
|
| 341 |
"""
|
| 342 |
Section 4: Rattrapage Vaccinal
|
| 343 |
|
| 344 |
-
Use
|
| 345 |
-
|
|
|
|
|
|
|
| 346 |
|
| 347 |
Args:
|
| 348 |
-
query (str): A question about
|
| 349 |
|
| 350 |
Returns:
|
| 351 |
-
str: Catch-up
|
| 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:
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
-
|
| 361 |
-
preterm infants, immunocompromised children, allergies (e.g. eggs), and chronic diseases.
|
| 362 |
|
| 363 |
Args:
|
| 364 |
-
query (str): A question about vaccination
|
| 365 |
|
| 366 |
Returns:
|
| 367 |
-
str:
|
| 368 |
"""
|
| 369 |
return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
|
| 370 |
|
|
@@ -373,14 +381,16 @@ def create_section_tools(embedding_function, llm):
|
|
| 373 |
"""
|
| 374 |
Section 6: Chaîne du Froid
|
| 375 |
|
| 376 |
-
Use
|
| 377 |
-
|
|
|
|
|
|
|
| 378 |
|
| 379 |
Args:
|
| 380 |
-
query (str): A question about
|
| 381 |
|
| 382 |
Returns:
|
| 383 |
-
str:
|
| 384 |
"""
|
| 385 |
return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
|
| 386 |
|
|
@@ -389,30 +399,34 @@ def create_section_tools(embedding_function, llm):
|
|
| 389 |
"""
|
| 390 |
Section 7: Sécurité des Injections
|
| 391 |
|
| 392 |
-
Use
|
| 393 |
-
|
|
|
|
|
|
|
| 394 |
|
| 395 |
Args:
|
| 396 |
-
query (str): A question about
|
| 397 |
|
| 398 |
Returns:
|
| 399 |
-
str:
|
| 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:
|
| 407 |
|
| 408 |
-
Use
|
| 409 |
-
|
|
|
|
|
|
|
| 410 |
|
| 411 |
Args:
|
| 412 |
-
query (str): A question about
|
| 413 |
|
| 414 |
Returns:
|
| 415 |
-
str:
|
| 416 |
"""
|
| 417 |
return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
|
| 418 |
|
|
@@ -421,14 +435,16 @@ def create_section_tools(embedding_function, llm):
|
|
| 421 |
"""
|
| 422 |
Section 9: Planification des Séances de Vaccination
|
| 423 |
|
| 424 |
-
Use
|
| 425 |
-
|
|
|
|
|
|
|
| 426 |
|
| 427 |
Args:
|
| 428 |
-
query (str): A question about
|
| 429 |
|
| 430 |
Returns:
|
| 431 |
-
str:
|
| 432 |
"""
|
| 433 |
return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
|
| 434 |
|
|
@@ -437,17 +453,18 @@ def create_section_tools(embedding_function, llm):
|
|
| 437 |
"""
|
| 438 |
Section 10: Mobilisation Sociale
|
| 439 |
|
| 440 |
-
Use
|
| 441 |
-
|
|
|
|
|
|
|
| 442 |
|
| 443 |
Args:
|
| 444 |
-
query (str): A question about public
|
| 445 |
|
| 446 |
Returns:
|
| 447 |
-
str:
|
| 448 |
"""
|
| 449 |
return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
|
| 450 |
-
|
| 451 |
# Create FunctionTool objects
|
| 452 |
tools = [
|
| 453 |
FunctionTool.from_defaults(name="Guide_vector_tool", fn=guide_retrieval_tool),
|
|
|
|
| 225 |
guide_retriever = create_retriever(guide_vstore, guide_docs, llm)
|
| 226 |
else:
|
| 227 |
guide_retriever = None
|
| 228 |
+
# Primary + Secondary Document Paths
|
| 229 |
+
immunization_path = './data/Immunization in Practice_WHO_eng_2015.json'
|
| 230 |
+
|
| 231 |
+
# WHO Immunization in Practice Tool
|
| 232 |
+
if os.path.exists(immunization_path):
|
| 233 |
+
immunization_vstore, immunization_docs = create_vectorstore_from_json(
|
| 234 |
+
immunization_path,
|
| 235 |
+
"Immunization_in_Practice_WHO_eng_2015",
|
| 236 |
+
embedding_function
|
| 237 |
+
)
|
| 238 |
+
immunization_retriever = create_retriever(immunization_vstore, immunization_docs, llm)
|
| 239 |
+
else:
|
| 240 |
+
immunization_retriever = None
|
| 241 |
+
|
| 242 |
# General-purpose tool (entire Algerian guide)
|
| 243 |
def guide_retrieval_tool(query: str) -> str:
|
| 244 |
"""
|
| 245 |
General-purpose retrieval tool for the entire Algerian National Vaccination Guide (2023).
|
| 246 |
|
| 247 |
+
Use ONLY when a query spans multiple unrelated sections or cannot be confidently routed
|
| 248 |
+
to a more specific tool. This tool provides a fallback when the intent is ambiguous
|
| 249 |
+
or multi-topic (e.g., combining schedule, cold chain, and public outreach in one query).
|
| 250 |
|
| 251 |
+
Do NOT use this tool for clearly scoped questions related to vaccination schedules, disease profiles,
|
| 252 |
+
vaccine logistics, or procedural workflows — use the specific section tools instead.
|
| 253 |
+
|
| 254 |
+
Secondary source: WHO Immunization Guide (use `immunization_tool` when broader context is required).
|
| 255 |
|
| 256 |
Args:
|
| 257 |
+
query (str): A general, complex, or cross-sectional vaccination query.
|
| 258 |
|
| 259 |
Returns:
|
| 260 |
+
str: Synthesized answer from the entire national guide.
|
| 261 |
"""
|
| 262 |
if not guide_retriever:
|
| 263 |
return "Guide retriever not available"
|
| 264 |
return section_tool_wrapper(guide_retriever, guide_path, query)
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
def immunization_tool(query: str) -> str:
|
| 268 |
"""
|
| 269 |
WHO Immunization in Practice 2015 retrieval tool.
|
| 270 |
|
| 271 |
+
Use ONLY when global guidance or procedural context is needed that is not covered or
|
| 272 |
+
is unclear in the Algerian guide. This is a secondary reference for training standards,
|
| 273 |
+
general immunization logistics, and vaccine delivery practices.
|
| 274 |
+
|
| 275 |
+
Do NOT use this tool to answer country-specific policy or scheduling questions.
|
| 276 |
|
| 277 |
Args:
|
| 278 |
+
query (str): A question seeking global immunization practices.
|
| 279 |
|
| 280 |
Returns:
|
| 281 |
+
str: Content from the WHO Immunization in Practice guide.
|
| 282 |
"""
|
| 283 |
if not immunization_retriever:
|
| 284 |
return "Immunization in Practice retriever not available"
|
| 285 |
return section_tool_wrapper(immunization_retriever, immunization_path, query)
|
| 286 |
|
| 287 |
|
| 288 |
+
# Section-Specific Tools
|
|
|
|
| 289 |
|
| 290 |
def section_one_tool(query: str) -> str:
|
| 291 |
"""
|
| 292 |
Section 1: Programme Élargi de Vaccination (PEV)
|
| 293 |
|
| 294 |
+
Use for queries about the national immunization program structure: its objectives,
|
| 295 |
+
history, evaluation, and rationale for updates to the Algerian calendar.
|
|
|
|
| 296 |
|
| 297 |
+
Do NOT use for vaccine schedules, disease information, or administration techniques.
|
|
|
|
| 298 |
|
| 299 |
Args:
|
| 300 |
+
query (str): A question about the foundation or evolution of the PEV.
|
| 301 |
|
| 302 |
Returns:
|
| 303 |
+
str: Response from Section 1.
|
| 304 |
"""
|
| 305 |
return section_tool_wrapper(section_retrievers['one'], section_paths['one'], query)
|
| 306 |
|
| 307 |
|
| 308 |
def section_two_tool(query: str) -> str:
|
| 309 |
"""
|
| 310 |
+
Section 2: Maladies Ciblées
|
| 311 |
|
| 312 |
+
Use ONLY for questions about the characteristics of vaccine-preventable diseases:
|
| 313 |
+
symptoms, transmission, complications, and prevention.
|
| 314 |
|
| 315 |
+
Do NOT use for questions about vaccines, administration schedules, or procedures.
|
|
|
|
| 316 |
|
| 317 |
Args:
|
| 318 |
+
query (str): A question about a disease covered by the national vaccination program.
|
| 319 |
|
| 320 |
Returns:
|
| 321 |
+
str: Disease-specific content from Section 2.
|
| 322 |
"""
|
| 323 |
return section_tool_wrapper(section_retrievers['two'], section_paths['two'], query)
|
| 324 |
|
|
|
|
| 327 |
"""
|
| 328 |
Section 3: Vaccins du Calendrier
|
| 329 |
|
| 330 |
+
Use ONLY for questions about the vaccines themselves: their types, compositions,
|
| 331 |
+
methods of administration, and how they work.
|
| 332 |
+
|
| 333 |
+
Do NOT use for schedule timing, catch-up protocols, or disease information.
|
| 334 |
|
| 335 |
Args:
|
| 336 |
+
query (str): A question about a vaccine's formulation or method of delivery.
|
| 337 |
|
| 338 |
Returns:
|
| 339 |
+
str: Vaccine info from Section 3.
|
| 340 |
"""
|
| 341 |
return section_tool_wrapper(section_retrievers['three'], section_paths['three'], query)
|
| 342 |
|
|
|
|
| 345 |
"""
|
| 346 |
Section 4: Rattrapage Vaccinal
|
| 347 |
|
| 348 |
+
Use ONLY when the question involves missed or delayed vaccinations and how to reschedule them
|
| 349 |
+
based on the child’s current age.
|
| 350 |
+
|
| 351 |
+
Do NOT use for standard schedules (on-time), vaccine properties, or cold chain issues.
|
| 352 |
|
| 353 |
Args:
|
| 354 |
+
query (str): A question about catch-up vaccination based on delay or omission.
|
| 355 |
|
| 356 |
Returns:
|
| 357 |
+
str: Catch-up guidance from Section 4.
|
| 358 |
"""
|
| 359 |
return section_tool_wrapper(section_retrievers['four'], section_paths['four'], query)
|
| 360 |
|
| 361 |
|
| 362 |
def section_five_tool(query: str) -> str:
|
| 363 |
"""
|
| 364 |
+
Section 5: Populations Particulières
|
| 365 |
+
|
| 366 |
+
Use ONLY for vaccination questions concerning special populations:
|
| 367 |
+
preterm infants, immunosuppressed patients, chronic illness, or allergy conditions.
|
| 368 |
|
| 369 |
+
Do NOT use for general population, standard calendar, or vaccine preparation.
|
|
|
|
| 370 |
|
| 371 |
Args:
|
| 372 |
+
query (str): A question about tailored vaccination for vulnerable groups.
|
| 373 |
|
| 374 |
Returns:
|
| 375 |
+
str: Custom recommendations from Section 5.
|
| 376 |
"""
|
| 377 |
return section_tool_wrapper(section_retrievers['five'], section_paths['five'], query)
|
| 378 |
|
|
|
|
| 381 |
"""
|
| 382 |
Section 6: Chaîne du Froid
|
| 383 |
|
| 384 |
+
Use ONLY for questions about vaccine storage, transport, cold chain equipment,
|
| 385 |
+
temperature monitoring, or cold chain failures.
|
| 386 |
+
|
| 387 |
+
Do NOT use for dose timing, administration methods, or disease information.
|
| 388 |
|
| 389 |
Args:
|
| 390 |
+
query (str): A logistics-related question about vaccine temperature management.
|
| 391 |
|
| 392 |
Returns:
|
| 393 |
+
str: Cold chain instructions from Section 6.
|
| 394 |
"""
|
| 395 |
return section_tool_wrapper(section_retrievers['six'], section_paths['six'], query)
|
| 396 |
|
|
|
|
| 399 |
"""
|
| 400 |
Section 7: Sécurité des Injections
|
| 401 |
|
| 402 |
+
Use ONLY for questions related to the safe administration of vaccines:
|
| 403 |
+
equipment use, technique, safety precautions, and waste disposal.
|
| 404 |
+
|
| 405 |
+
Do NOT use for vaccine types, schedules, or cold chain issues.
|
| 406 |
|
| 407 |
Args:
|
| 408 |
+
query (str): A question about how to inject vaccines safely.
|
| 409 |
|
| 410 |
Returns:
|
| 411 |
+
str: Best practices from Section 7.
|
| 412 |
"""
|
| 413 |
return section_tool_wrapper(section_retrievers['seven'], section_paths['seven'], query)
|
| 414 |
|
| 415 |
|
| 416 |
def section_eight_tool(query: str) -> str:
|
| 417 |
"""
|
| 418 |
+
Section 8: Séance de Vaccination & Vaccinovigilance
|
| 419 |
|
| 420 |
+
Use ONLY for questions about running a vaccination session, preparing the setting,
|
| 421 |
+
recording injections, and monitoring for adverse events (AEFI).
|
| 422 |
+
|
| 423 |
+
Do NOT use for disease, vaccine, or scheduling details.
|
| 424 |
|
| 425 |
Args:
|
| 426 |
+
query (str): A question about operational conduct during vaccination.
|
| 427 |
|
| 428 |
Returns:
|
| 429 |
+
str: Workflow and safety monitoring details from Section 8.
|
| 430 |
"""
|
| 431 |
return section_tool_wrapper(section_retrievers['eight'], section_paths['eight'], query)
|
| 432 |
|
|
|
|
| 435 |
"""
|
| 436 |
Section 9: Planification des Séances de Vaccination
|
| 437 |
|
| 438 |
+
Use ONLY for planning and logistics questions: session scheduling, stock estimation,
|
| 439 |
+
and operational preparation at the facility level.
|
| 440 |
+
|
| 441 |
+
Do NOT use for vaccine info, schedules, or injection techniques.
|
| 442 |
|
| 443 |
Args:
|
| 444 |
+
query (str): A question about how to plan or organize vaccination services.
|
| 445 |
|
| 446 |
Returns:
|
| 447 |
+
str: Planning and stock guidance from Section 9.
|
| 448 |
"""
|
| 449 |
return section_tool_wrapper(section_retrievers['nine'], section_paths['nine'], query)
|
| 450 |
|
|
|
|
| 453 |
"""
|
| 454 |
Section 10: Mobilisation Sociale
|
| 455 |
|
| 456 |
+
Use ONLY for questions about communication strategies, overcoming vaccine hesitancy,
|
| 457 |
+
rumor management, or community outreach.
|
| 458 |
+
|
| 459 |
+
Do NOT use for medical, logistical, or procedural topics.
|
| 460 |
|
| 461 |
Args:
|
| 462 |
+
query (str): A question about public engagement or communication for vaccination.
|
| 463 |
|
| 464 |
Returns:
|
| 465 |
+
str: Public mobilization strategies from Section 10.
|
| 466 |
"""
|
| 467 |
return section_tool_wrapper(section_retrievers['ten'], section_paths['ten'], query)
|
|
|
|
| 468 |
# Create FunctionTool objects
|
| 469 |
tools = [
|
| 470 |
FunctionTool.from_defaults(name="Guide_vector_tool", fn=guide_retrieval_tool),
|