Spaces:
Sleeping
Sleeping
File size: 2,303 Bytes
08e2c16 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# Tool selection utilities for determining which tools to use
from config import (
YOUTUBE_PATTERNS, REVERSE_TEXT_PATTERNS, WIKIPEDIA_PATTERNS,
WEB_SEARCH_PATTERNS, AI_PATTERNS, FILE_PATTERNS
)
def determine_tools_needed(question):
"""Determine which tools should be used for a given question."""
question_lower = question.lower()
# YouTube detection
needs_youtube = any(pattern in question_lower for pattern in YOUTUBE_PATTERNS)
# Reverse text detection
is_reverse_text = (
any(pattern in question_lower for pattern in REVERSE_TEXT_PATTERNS) or
(question_lower != question_lower[::-1] and
"ecnetnes" in question_lower or "sdrow" in question_lower)
)
# Wikipedia detection
needs_wikipedia = any(pattern in question_lower for pattern in WIKIPEDIA_PATTERNS)
# Web search detection
needs_web_search = any(pattern in question_lower for pattern in WEB_SEARCH_PATTERNS)
# Knowledge retrieval for AI/agent questions
needs_knowledge = any(term in question_lower for term in AI_PATTERNS)
# File analysis detection
has_file_analysis = any(pattern in question_lower for pattern in FILE_PATTERNS)
return {
"use_youtube": needs_youtube,
"use_wikipedia": needs_wikipedia,
"is_reverse_text": is_reverse_text,
"use_web_search": needs_web_search,
"use_knowledge_retrieval": needs_knowledge,
"use_webpage_visit": needs_web_search and ("link" in question_lower or "paper" in question_lower),
"has_file_analysis": has_file_analysis
}
def needs_special_handling(question, tool_selection):
"""Check if question needs special handling beyond standard tools."""
question_lower = question.lower()
# Reverse text questions
if tool_selection.get("is_reverse_text", False):
return True
# Mathematical table analysis
if "table" in question_lower and ("commutative" in question_lower or "operation" in question_lower):
return True
# Grocery/botany questions
if "grocery" in question_lower and "botany" in question_lower:
return True
# File analysis questions
if tool_selection.get("has_file_analysis", False):
return True
return False
|