Spaces:
Sleeping
Sleeping
Commit ·
f55317e
1
Parent(s): dd0b012
Update services/agent_crewai.py
Browse files- 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
|
| 280 |
-
# This
|
| 281 |
try:
|
| 282 |
-
|
| 283 |
-
from langchain.llms.base import LLM
|
| 284 |
-
from typing import Any, List, Optional
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 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
|
| 310 |
-
print("Falling back to string
|
| 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(
|