Commit Β·
4e5a109
1
Parent(s): 06c0480
.......
Browse files
app.py
CHANGED
|
@@ -273,9 +273,11 @@ class CacheManager:
|
|
| 273 |
class SearchProvider(ABC):
|
| 274 |
def __init__(self, config_dict: Dict):
|
| 275 |
self.provider_config = config_dict.get('search', {})
|
| 276 |
-
self._enabled = False
|
| 277 |
-
self._quota_limit = self.provider_config.get("quota_limit", float('inf'))
|
| 278 |
self._quota_used = 0
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
@property
|
| 281 |
@abstractmethod
|
|
@@ -309,7 +311,7 @@ class GoogleProvider(SearchProvider):
|
|
| 309 |
return "Google"
|
| 310 |
|
| 311 |
def __init__(self, config_dict: Dict):
|
| 312 |
-
super().__init__(config_dict)
|
| 313 |
self._api_key = self.provider_config.get("google_api_key")
|
| 314 |
self._cse_id = self.provider_config.get("google_cse_id")
|
| 315 |
self._timeout = self.provider_config.get("google_timeout", 8)
|
|
@@ -317,7 +319,7 @@ class GoogleProvider(SearchProvider):
|
|
| 317 |
self._enabled = True
|
| 318 |
gaia_logger.info(f"β {self.provider_name} API configured.")
|
| 319 |
else:
|
| 320 |
-
self._enabled = False
|
| 321 |
gaia_logger.warning(f"β {self.provider_name} API key/CSE ID missing in RAG config.")
|
| 322 |
|
| 323 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
|
@@ -361,33 +363,32 @@ class TavilyProvider(SearchProvider):
|
|
| 361 |
return "Tavily"
|
| 362 |
|
| 363 |
def __init__(self, config_dict: Dict):
|
| 364 |
-
super().__init__(config_dict)
|
| 365 |
self._api_key = self.provider_config.get("tavily_api_key")
|
| 366 |
self._search_depth = self.provider_config.get("tavily_depth", "basic")
|
| 367 |
if self._api_key and TavilyClient:
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
else:
|
| 371 |
-
self._enabled = False
|
| 372 |
-
gaia_logger.warning(f"β {self.provider_name} API key missing
|
| 373 |
|
| 374 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
| 375 |
-
if not self._enabled:
|
| 376 |
-
return None
|
| 377 |
try:
|
| 378 |
response = self._client.search(query=query, max_results=max_results, search_depth=self._search_depth)
|
| 379 |
hits = response.get('results', [])
|
| 380 |
-
if not hits:
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
return [{
|
| 384 |
-
'href': h.get('url'),
|
| 385 |
-
'title': h.get('title',''),
|
| 386 |
-
'body': h.get('content','')
|
| 387 |
-
} for h in hits]
|
| 388 |
-
except Exception as e:
|
| 389 |
-
gaia_logger.warning(f"[{self.provider_name}] Search fail: '{query[:70]}': {e}")
|
| 390 |
-
return None
|
| 391 |
|
| 392 |
class DuckDuckGoProvider(SearchProvider):
|
| 393 |
@property
|
|
@@ -395,34 +396,26 @@ class DuckDuckGoProvider(SearchProvider):
|
|
| 395 |
return "DuckDuckGo"
|
| 396 |
|
| 397 |
def __init__(self, config_dict: Dict):
|
| 398 |
-
super().__init__(config_dict)
|
| 399 |
if DDGS:
|
| 400 |
try:
|
| 401 |
self._client = DDGS(timeout=10)
|
| 402 |
self._enabled = True
|
| 403 |
gaia_logger.info(f"β {self.provider_name} Search initialized.")
|
| 404 |
except Exception as e:
|
|
|
|
| 405 |
gaia_logger.warning(f"β {self.provider_name} init fail: {e}", exc_info=False)
|
| 406 |
else:
|
|
|
|
| 407 |
gaia_logger.warning(f"β {self.provider_name}: DDGS lib missing.")
|
| 408 |
-
self._quota_limit = float('inf')
|
| 409 |
|
| 410 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
| 411 |
-
if not self._enabled:
|
| 412 |
-
return None
|
| 413 |
try:
|
| 414 |
hits = list(self._client.text(query, region='wt-wt', max_results=max_results))[:max_results]
|
| 415 |
-
if not hits:
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
return [{
|
| 419 |
-
'href': r.get('href'),
|
| 420 |
-
'title': r.get('title',''),
|
| 421 |
-
'body': r.get('body','')
|
| 422 |
-
} for r in hits]
|
| 423 |
-
except Exception as e:
|
| 424 |
-
gaia_logger.warning(f"[{self.provider_name}] Search fail: '{query[:70]}': {e}")
|
| 425 |
-
return None
|
| 426 |
|
| 427 |
class CompositeSearchClient:
|
| 428 |
def __init__(self, config_dict: Dict):
|
|
@@ -681,7 +674,7 @@ class GaiaLevel1Agent:
|
|
| 681 |
if genai and GOOGLE_GEMINI_API_KEY:
|
| 682 |
try:
|
| 683 |
genai.configure(api_key=GOOGLE_GEMINI_API_KEY)
|
| 684 |
-
model_name = 'gemini-
|
| 685 |
self.llm_model = genai.GenerativeModel(model_name)
|
| 686 |
gaia_logger.info(f"Gemini LLM ('{model_name}') initialized.")
|
| 687 |
except Exception as e:
|
|
|
|
| 273 |
class SearchProvider(ABC):
|
| 274 |
def __init__(self, config_dict: Dict):
|
| 275 |
self.provider_config = config_dict.get('search', {})
|
| 276 |
+
self._enabled = False # Initial default
|
|
|
|
| 277 |
self._quota_used = 0
|
| 278 |
+
# This call to self.provider_name will invoke the subclass's implementation.
|
| 279 |
+
raw_quota = self.provider_config.get(f'{self.provider_name.lower()}_quota', float('inf'))
|
| 280 |
+
self._quota_limit = float(raw_quota) if raw_quota is not None else float('inf')
|
| 281 |
|
| 282 |
@property
|
| 283 |
@abstractmethod
|
|
|
|
| 311 |
return "Google"
|
| 312 |
|
| 313 |
def __init__(self, config_dict: Dict):
|
| 314 |
+
super().__init__(config_dict) # Sets self._enabled = False initially via SearchProvider
|
| 315 |
self._api_key = self.provider_config.get("google_api_key")
|
| 316 |
self._cse_id = self.provider_config.get("google_cse_id")
|
| 317 |
self._timeout = self.provider_config.get("google_timeout", 8)
|
|
|
|
| 319 |
self._enabled = True
|
| 320 |
gaia_logger.info(f"β {self.provider_name} API configured.")
|
| 321 |
else:
|
| 322 |
+
self._enabled = False # Explicitly ensure it's false if keys are missing
|
| 323 |
gaia_logger.warning(f"β {self.provider_name} API key/CSE ID missing in RAG config.")
|
| 324 |
|
| 325 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
|
|
|
| 363 |
return "Tavily"
|
| 364 |
|
| 365 |
def __init__(self, config_dict: Dict):
|
| 366 |
+
super().__init__(config_dict) # Sets self._enabled = False initially
|
| 367 |
self._api_key = self.provider_config.get("tavily_api_key")
|
| 368 |
self._search_depth = self.provider_config.get("tavily_depth", "basic")
|
| 369 |
if self._api_key and TavilyClient:
|
| 370 |
+
try:
|
| 371 |
+
self._client = TavilyClient(api_key=self._api_key)
|
| 372 |
+
self._enabled = True
|
| 373 |
+
gaia_logger.info(f"β {self.provider_name} API initialized.")
|
| 374 |
+
except Exception as e:
|
| 375 |
+
self._enabled = False # Explicitly ensure it's false on init fail
|
| 376 |
+
gaia_logger.warning(f"β {self.provider_name} init fail: {e}", exc_info=False)
|
| 377 |
+
elif not TavilyClient:
|
| 378 |
+
self._enabled = False # Explicitly ensure it's false if lib missing
|
| 379 |
+
gaia_logger.warning(f"β {self.provider_name}: TavilyClient lib missing.")
|
| 380 |
else:
|
| 381 |
+
self._enabled = False # Explicitly ensure it's false if API key missing
|
| 382 |
+
gaia_logger.warning(f"β {self.provider_name}: API key missing in RAG config.")
|
| 383 |
|
| 384 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
| 385 |
+
if not self._enabled: return None # Should be caught by SearchProvider.search, but good for safety
|
|
|
|
| 386 |
try:
|
| 387 |
response = self._client.search(query=query, max_results=max_results, search_depth=self._search_depth)
|
| 388 |
hits = response.get('results', [])
|
| 389 |
+
if not hits: gaia_logger.info(f"[{self.provider_name}] No results: '{query[:70]}'"); return []
|
| 390 |
+
return [{'href': h.get('url'), 'title': h.get('title',''), 'body': h.get('content','')} for h in hits]
|
| 391 |
+
except Exception as e: gaia_logger.warning(f"[{self.provider_name}] Search fail: '{query[:70]}': {e}"); return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
class DuckDuckGoProvider(SearchProvider):
|
| 394 |
@property
|
|
|
|
| 396 |
return "DuckDuckGo"
|
| 397 |
|
| 398 |
def __init__(self, config_dict: Dict):
|
| 399 |
+
super().__init__(config_dict) # Sets self._enabled = False initially
|
| 400 |
if DDGS:
|
| 401 |
try:
|
| 402 |
self._client = DDGS(timeout=10)
|
| 403 |
self._enabled = True
|
| 404 |
gaia_logger.info(f"β {self.provider_name} Search initialized.")
|
| 405 |
except Exception as e:
|
| 406 |
+
self._enabled = False # Explicitly ensure it's false on init fail
|
| 407 |
gaia_logger.warning(f"β {self.provider_name} init fail: {e}", exc_info=False)
|
| 408 |
else:
|
| 409 |
+
self._enabled = False # Explicitly ensure it's false if lib missing
|
| 410 |
gaia_logger.warning(f"β {self.provider_name}: DDGS lib missing.")
|
|
|
|
| 411 |
|
| 412 |
def _perform_search(self, query: str, max_results: int) -> Optional[List[Dict[str, str]]]:
|
| 413 |
+
if not self._enabled: return None # Should be caught by SearchProvider.search
|
|
|
|
| 414 |
try:
|
| 415 |
hits = list(self._client.text(query, region='wt-wt', max_results=max_results))[:max_results]
|
| 416 |
+
if not hits: gaia_logger.info(f"[{self.provider_name}] No results: '{query[:70]}'"); return []
|
| 417 |
+
return [{'href': r.get('href'), 'title': r.get('title',''), 'body': r.get('body','')} for r in hits]
|
| 418 |
+
except Exception as e: gaia_logger.warning(f"[{self.provider_name}] Search fail: '{query[:70]}': {e}"); return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
class CompositeSearchClient:
|
| 421 |
def __init__(self, config_dict: Dict):
|
|
|
|
| 674 |
if genai and GOOGLE_GEMINI_API_KEY:
|
| 675 |
try:
|
| 676 |
genai.configure(api_key=GOOGLE_GEMINI_API_KEY)
|
| 677 |
+
model_name = 'gemini-2.0-flash'
|
| 678 |
self.llm_model = genai.GenerativeModel(model_name)
|
| 679 |
gaia_logger.info(f"Gemini LLM ('{model_name}') initialized.")
|
| 680 |
except Exception as e:
|