GuglielmoTor commited on
Commit
c64c256
·
verified ·
1 Parent(s): c0df812

Update insight_and_tasks/agents/follower_agent.py

Browse files
insight_and_tasks/agents/follower_agent.py CHANGED
@@ -363,15 +363,20 @@ class EnhancedFollowerAnalysisAgent:
363
  # Ensure the LLM for PandasAI is correctly configured before this call
364
  # This might involve re-calling configure_pandasai if it's not persistent
365
  # or if the LLM object needs to be explicitly passed to PandasAI DataFrame.
366
- if not hasattr(pai.config, 'llm'): # Check if LLM is set for PandasAI
 
 
367
  logger.warning("PandasAI LLM not configured. Attempting to configure now.")
368
- # This assumes configure_pandasai is available and sets pai.config.llm
369
  from insight_and_tasks.utils.pandasai_setup import configure_pandasai
370
  configure_pandasai(self.api_key, self.model_name)
371
- if not pai.config.get("llm"):
372
- raise RuntimeError("PandasAI LLM could not be configured for chat operation.")
 
 
 
373
 
374
- logger.info(f"Executing PandasAI chat for follower analysis with LLM: {pai.config.get('llm')}")
375
  return pandas_ai_df.chat(analysis_query)
376
 
377
  analysis_result_raw = self.retry_mechanism.retry_with_backoff(
 
363
  # Ensure the LLM for PandasAI is correctly configured before this call
364
  # This might involve re-calling configure_pandasai if it's not persistent
365
  # or if the LLM object needs to be explicitly passed to PandasAI DataFrame.
366
+ # Check if LLM is configured using the proper config.get() method
367
+ config = pai.config.get()
368
+ if not config.get("llm"):
369
  logger.warning("PandasAI LLM not configured. Attempting to configure now.")
370
+ # This assumes configure_pandasai is available and sets the LLM config
371
  from insight_and_tasks.utils.pandasai_setup import configure_pandasai
372
  configure_pandasai(self.api_key, self.model_name)
373
+
374
+ # Re-check configuration after setup attempt
375
+ config = pai.config.get()
376
+ if not config.get("llm"):
377
+ raise RuntimeError("PandasAI LLM could not be configured for chat operation.")
378
 
379
+ logger.info(f"Executing PandasAI chat for follower analysis with LLM: {config.get('llm')}")
380
  return pandas_ai_df.chat(analysis_query)
381
 
382
  analysis_result_raw = self.retry_mechanism.retry_with_backoff(