Update agent/rica_agent.py
Browse files- agent/rica_agent.py +13 -6
agent/rica_agent.py
CHANGED
|
@@ -1,20 +1,27 @@
|
|
| 1 |
"""
|
| 2 |
RICA Agent optimized for Hugging Face Spaces
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import os
|
| 6 |
from smolagents import CodeAgent
|
| 7 |
-
from
|
| 8 |
from agent_tools.ml_tools import predict_customer_churn_hf, get_model_status
|
| 9 |
|
| 10 |
def create_rica_agent_hf():
|
| 11 |
-
"""Create RICA agent
|
| 12 |
|
| 13 |
# Check API key availability
|
| 14 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
if not api_key:
|
| 16 |
raise ValueError("OpenAI API key not configured")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# HF Spaces optimized tools
|
| 19 |
hf_tools = [
|
| 20 |
predict_customer_churn_hf,
|
|
@@ -22,11 +29,11 @@ def create_rica_agent_hf():
|
|
| 22 |
]
|
| 23 |
|
| 24 |
try:
|
|
|
|
| 25 |
agent = CodeAgent(
|
| 26 |
tools=hf_tools,
|
| 27 |
-
model=
|
| 28 |
-
add_base_tools=False
|
| 29 |
-
max_iterations=3 # Reduced for HF Spaces performance
|
| 30 |
)
|
| 31 |
return agent
|
| 32 |
except Exception as e:
|
|
@@ -56,7 +63,7 @@ def execute_rica_analysis_hf(analysis_type: str, parameters: dict = None):
|
|
| 56 |
|
| 57 |
"churn_focus": f"""
|
| 58 |
Focus on customer churn analysis:
|
| 59 |
-
1) Predict customer churn with predict_customer_churn_hf(risk_threshold={parameters.get('risk_threshold', 0.6)})
|
| 60 |
2) Identify high-risk customers requiring immediate attention
|
| 61 |
3) Provide specific intervention strategies
|
| 62 |
|
|
|
|
| 1 |
"""
|
| 2 |
RICA Agent optimized for Hugging Face Spaces
|
| 3 |
+
Fixed for latest smolagents API
|
| 4 |
"""
|
| 5 |
|
| 6 |
import os
|
| 7 |
from smolagents import CodeAgent
|
| 8 |
+
from smolagents.models import OpenAIServerModel
|
| 9 |
from agent_tools.ml_tools import predict_customer_churn_hf, get_model_status
|
| 10 |
|
| 11 |
def create_rica_agent_hf():
|
| 12 |
+
"""Create RICA agent using correct smolagents API"""
|
| 13 |
|
| 14 |
# Check API key availability
|
| 15 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 16 |
if not api_key:
|
| 17 |
raise ValueError("OpenAI API key not configured")
|
| 18 |
|
| 19 |
+
# Initialize OpenAI model using smolagents model class
|
| 20 |
+
model = OpenAIServerModel(
|
| 21 |
+
model_id="gpt-3.5-turbo",
|
| 22 |
+
api_key=api_key
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
# HF Spaces optimized tools
|
| 26 |
hf_tools = [
|
| 27 |
predict_customer_churn_hf,
|
|
|
|
| 29 |
]
|
| 30 |
|
| 31 |
try:
|
| 32 |
+
# Create agent with correct parameters (no max_iterations)
|
| 33 |
agent = CodeAgent(
|
| 34 |
tools=hf_tools,
|
| 35 |
+
model=model,
|
| 36 |
+
add_base_tools=False
|
|
|
|
| 37 |
)
|
| 38 |
return agent
|
| 39 |
except Exception as e:
|
|
|
|
| 63 |
|
| 64 |
"churn_focus": f"""
|
| 65 |
Focus on customer churn analysis:
|
| 66 |
+
1) Predict customer churn with predict_customer_churn_hf(risk_threshold={parameters.get('risk_threshold', 0.6) if parameters else 0.6})
|
| 67 |
2) Identify high-risk customers requiring immediate attention
|
| 68 |
3) Provide specific intervention strategies
|
| 69 |
|