redhairedshanks1 commited on
Commit
f55317e
·
1 Parent(s): dd0b012

Update services/agent_crewai.py

Browse files
Files changed (1) hide show
  1. services/agent_crewai.py +20 -28
services/agent_crewai.py CHANGED
@@ -276,38 +276,30 @@ Current session file: {session_file_path}
276
  Execution plan: {plan_json}
277
  """
278
 
279
- # Initialize LLM explicitly using LiteLLM wrapper
280
- # This works even if google-generativeai is not installed
281
  try:
282
- from litellm import completion
283
- from langchain.llms.base import LLM
284
- from typing import Any, List, Optional
285
 
286
- class LiteLLMWrapper(LLM):
287
- """Wrapper for LiteLLM to use with CrewAI"""
288
- model_name: str = "gemini/gemini-2.0-flash"
289
-
290
- @property
291
- def _llm_type(self) -> str:
292
- return "litellm"
293
-
294
- def _call(
295
- self,
296
- prompt: str,
297
- stop: Optional[List[str]] = None,
298
- **kwargs: Any,
299
- ) -> str:
300
- response = completion(
301
- model=self.model_name,
302
- messages=[{"role": "user", "content": prompt}],
303
- api_key=os.getenv("GOOGLE_API_KEY") or os.getenv("GEMINI_API_KEY"),
304
- )
305
- return response.choices[0].message.content
306
 
307
- llm = LiteLLMWrapper()
308
  except Exception as e:
309
- print(f"Warning: Could not initialize LiteLLM wrapper: {e}")
310
- print("Falling back to string-based LLM (may require google-generativeai)")
311
  llm = os.getenv("CREWAI_LLM", "gemini/gemini-2.0-flash")
312
 
313
  agent = Agent(
 
276
  Execution plan: {plan_json}
277
  """
278
 
279
+ # Initialize Gemini LLM using google.generativeai directly
280
+ # This bypasses CrewAI's string parser which requires google-genai extra
281
  try:
282
+ import google.generativeai as genai
 
 
283
 
284
+ # Configure Gemini
285
+ api_key = os.getenv("GOOGLE_API_KEY") or os.getenv("GEMINI_API_KEY")
286
+ if api_key:
287
+ genai.configure(api_key=api_key)
288
+
289
+ # Create Gemini model instance
290
+ model = genai.GenerativeModel('gemini-2.0-flash-exp')
291
+ llm = model
292
+ print(f"✅ CrewAI using Google Gemini directly: gemini-2.0-flash-exp")
293
+
294
+ except ImportError as e:
295
+ print(f"Warning: google.generativeai not available: {e}")
296
+ print("Falling back to LiteLLM string format")
297
+ # Use litellm format as fallback
298
+ llm = "gemini/gemini-2.0-flash"
 
 
 
 
 
299
 
 
300
  except Exception as e:
301
+ print(f"Warning: Could not initialize Gemini: {e}")
302
+ print("Falling back to CrewAI string format")
303
  llm = os.getenv("CREWAI_LLM", "gemini/gemini-2.0-flash")
304
 
305
  agent = Agent(