jm-vis commited on
Commit
eef9db2
·
1 Parent(s): 49bdc02

Add resolve_question_type function to tool_registry.py

Browse files
Files changed (1) hide show
  1. src/gaia/agent/tool_registry.py +48 -0
src/gaia/agent/tool_registry.py CHANGED
@@ -257,6 +257,54 @@ def create_default_registry() -> ToolRegistry:
257
  return registry
258
 
259
  def analyze_query(query: str) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  """
261
  Analyze a query to determine the best search strategy.
262
 
 
257
  return registry
258
 
259
  def analyze_query(query: str) -> Dict[str, Any]:
260
+ """
261
+ Analyze a query to determine its characteristics.
262
+
263
+ Args:
264
+ query: The query to analyze
265
+
266
+ Returns:
267
+ Dictionary with query analysis results
268
+ """
269
+
270
+ def resolve_question_type(question: str) -> str:
271
+ """
272
+ Determine the type of question.
273
+
274
+ This function analyzes the question text to determine its type,
275
+ particularly identifying special cases like reversed text.
276
+
277
+ Args:
278
+ question: The question text to analyze
279
+
280
+ Returns:
281
+ String indicating the question type (e.g., "factual", "reversed_text")
282
+ """
283
+ # Check for reversed text - if the text is backwards
284
+ if re.search(r'[a-zA-Z]{5,}\.', question) or question.count('.') > question.count(' '):
285
+ reversed_chars = [c for c in question if c.isalpha()]
286
+ # Count lowercase followed by uppercase as an indicator of reversed text
287
+ transitions = sum(1 for i in range(len(reversed_chars)-1)
288
+ if reversed_chars[i].islower() and reversed_chars[i+1].isupper())
289
+
290
+ if transitions > len(question) / 20: # Heuristic threshold
291
+ return "reversed_text"
292
+
293
+ # Check for specific question types based on keywords
294
+ if "youtube" in question.lower() or "video" in question.lower():
295
+ return "video"
296
+
297
+ if "image" in question.lower() or "picture" in question.lower() or "photo" in question.lower():
298
+ return "image"
299
+
300
+ if "math" in question.lower() or "calculate" in question.lower() or re.search(r'\d+[\+\-\*/]\d+', question):
301
+ return "math"
302
+
303
+ if "code" in question.lower() or "function" in question.lower() or "programming" in question.lower():
304
+ return "code"
305
+
306
+ # Default to factual for general knowledge questions
307
+ return "factual"
308
  """
309
  Analyze a query to determine the best search strategy.
310