Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,170 +5,163 @@ from tools.final_answer import FinalAnswerTool
|
|
| 5 |
from Gradio_UI import GradioUI
|
| 6 |
|
| 7 |
@tool
|
| 8 |
-
def
|
| 9 |
-
"""Provides
|
| 10 |
|
| 11 |
Args:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
Returns:
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
if
|
| 20 |
-
return "Error:
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
valid_phases = ["planning", "development", "testing", "deployment", "monitoring"]
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
valid_complexity = ["low", "medium", "high"]
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
"
|
| 54 |
-
|
| 55 |
-
{"name": "VS Code", "category": "IDE", "complexity": "Low", "min_team_size": 1, "description": "Lightweight, extensible code editor"}
|
| 56 |
-
],
|
| 57 |
-
"medium": [
|
| 58 |
-
{"name": "GitLab", "category": "DevOps Platform", "complexity": "Medium", "min_team_size": 5, "description": "Integrated DevOps platform with built-in CI/CD"},
|
| 59 |
-
{"name": "JetBrains IDEs", "category": "IDE", "complexity": "Medium", "min_team_size": 1, "description": "Language-specific professional IDEs"}
|
| 60 |
-
],
|
| 61 |
-
"high": [
|
| 62 |
-
{"name": "Bitbucket + Bamboo", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 10, "description": "Atlassian's integrated code and CI/CD solution"},
|
| 63 |
-
{"name": "GitHub Enterprise", "category": "Enterprise DevOps", "complexity": "High", "min_team_size": 20, "description": "Self-hosted, compliant GitHub with advanced security"}
|
| 64 |
-
]
|
| 65 |
-
},
|
| 66 |
-
"testing": {
|
| 67 |
-
"low": [
|
| 68 |
-
{"name": "Jest", "category": "Testing Framework", "complexity": "Low", "min_team_size": 1, "description": "JavaScript testing framework with minimal configuration"},
|
| 69 |
-
{"name": "GitHub Actions", "category": "CI/CD", "complexity": "Low", "min_team_size": 1, "description": "Simple workflow automation integrated with GitHub"}
|
| 70 |
-
],
|
| 71 |
-
"medium": [
|
| 72 |
-
{"name": "Jenkins", "category": "CI/CD", "complexity": "Medium", "min_team_size": 3, "description": "Flexible automation server for building, testing, and deployment"},
|
| 73 |
-
{"name": "Selenium", "category": "Testing", "complexity": "Medium", "min_team_size": 2, "description": "Browser automation for web application testing"}
|
| 74 |
-
],
|
| 75 |
-
"high": [
|
| 76 |
-
{"name": "Azure DevOps Pipelines", "category": "CI/CD", "complexity": "High", "min_team_size": 5, "description": "Enterprise-grade pipelines with extensive integration"},
|
| 77 |
-
{"name": "SonarQube", "category": "Code Quality", "complexity": "High", "min_team_size": 5, "description": "Advanced code quality and security platform"}
|
| 78 |
-
]
|
| 79 |
-
},
|
| 80 |
-
"deployment": {
|
| 81 |
-
"low": [
|
| 82 |
-
{"name": "Netlify", "category": "Hosting", "complexity": "Low", "min_team_size": 1, "description": "Simple deployment platform for frontend applications"},
|
| 83 |
-
{"name": "Heroku", "category": "PaaS", "complexity": "Low", "min_team_size": 1, "description": "Platform-as-a-Service with simplified deployment"}
|
| 84 |
-
],
|
| 85 |
-
"medium": [
|
| 86 |
-
{"name": "Docker", "category": "Containerization", "complexity": "Medium", "min_team_size": 2, "description": "Container platform for application packaging"},
|
| 87 |
-
{"name": "AWS Elastic Beanstalk", "category": "PaaS", "complexity": "Medium", "min_team_size": 3, "description": "Easy-to-use service for deploying applications"}
|
| 88 |
-
],
|
| 89 |
-
"high": [
|
| 90 |
-
{"name": "Kubernetes", "category": "Container Orchestration", "complexity": "High", "min_team_size": 5, "description": "Production-grade container orchestration"},
|
| 91 |
-
{"name": "Terraform", "category": "IaC", "complexity": "High", "min_team_size": 3, "description": "Infrastructure as Code for multi-cloud deployment"}
|
| 92 |
-
]
|
| 93 |
-
},
|
| 94 |
-
"monitoring": {
|
| 95 |
-
"low": [
|
| 96 |
-
{"name": "Uptime Robot", "category": "Monitoring", "complexity": "Low", "min_team_size": 1, "description": "Simple uptime monitoring for websites"},
|
| 97 |
-
{"name": "Sentry", "category": "Error Tracking", "complexity": "Low", "min_team_size": 1, "description": "Application error monitoring"}
|
| 98 |
-
],
|
| 99 |
-
"medium": [
|
| 100 |
-
{"name": "Grafana", "category": "Observability", "complexity": "Medium", "min_team_size": 2, "description": "Metrics visualization and dashboards"},
|
| 101 |
-
{"name": "New Relic", "category": "APM", "complexity": "Medium", "min_team_size": 3, "description": "Application performance monitoring"}
|
| 102 |
-
],
|
| 103 |
-
"high": [
|
| 104 |
-
{"name": "Prometheus", "category": "Monitoring", "complexity": "High", "min_team_size": 3, "description": "Advanced metrics collection and alerting system"},
|
| 105 |
-
{"name": "Datadog", "category": "Observability", "complexity": "High", "min_team_size": 5, "description": "Full-stack observability platform"}
|
| 106 |
-
]
|
| 107 |
}
|
| 108 |
-
}
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
#
|
| 114 |
-
|
| 115 |
-
tools_for_phase = udp_tools[development_phase][project_complexity]
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Format response
|
| 123 |
-
response = f"##
|
| 124 |
-
response += f"**
|
| 125 |
-
response += f"**
|
| 126 |
-
response += f"**
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
for
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
response += f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
else:
|
| 138 |
-
response += "Unfortunately, we cannot provide specific
|
| 139 |
-
|
| 140 |
-
# Additional phase-specific advice
|
| 141 |
-
if development_phase == "planning":
|
| 142 |
-
response += "### Planning Phase Tips\n"
|
| 143 |
-
response += "- Document your requirements clearly\n"
|
| 144 |
-
response += "- Set up communication channels\n"
|
| 145 |
-
response += "- Define team roles and responsibilities\n"
|
| 146 |
-
elif development_phase == "development":
|
| 147 |
-
response += "### Development Phase Tips\n"
|
| 148 |
-
response += "- Implement branch protection rules\n"
|
| 149 |
-
response += "- Use consistent code formatting\n"
|
| 150 |
-
response += "- Schedule regular code reviews\n"
|
| 151 |
-
elif development_phase == "testing":
|
| 152 |
-
response += "### Testing Phase Tips\n"
|
| 153 |
-
response += "- Automate unit and integration tests\n"
|
| 154 |
-
response += "- Establish QA processes\n"
|
| 155 |
-
response += "- Document test cases and expected outcomes\n"
|
| 156 |
-
elif development_phase == "deployment":
|
| 157 |
-
response += "### Deployment Phase Tips\n"
|
| 158 |
-
response += "- Use environment-specific configurations\n"
|
| 159 |
-
response += "- Implement rollback strategies\n"
|
| 160 |
-
response += "- Document deployment procedures\n"
|
| 161 |
-
elif development_phase == "monitoring":
|
| 162 |
-
response += "### Monitoring Phase Tips\n"
|
| 163 |
-
response += "- Set up alerts for critical metrics\n"
|
| 164 |
-
response += "- Establish incident response processes\n"
|
| 165 |
-
response += "- Regularly review logs and performance data\n"
|
| 166 |
|
| 167 |
-
response += "
|
| 168 |
response += "- These are general recommendations based on the information provided.\n"
|
| 169 |
-
response += "- Before
|
| 170 |
-
response += "-
|
| 171 |
-
response += "-
|
| 172 |
|
| 173 |
return response
|
| 174 |
|
|
@@ -181,19 +174,19 @@ model = HfApiModel(
|
|
| 181 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 182 |
)
|
| 183 |
|
| 184 |
-
# Configure templates for the
|
| 185 |
-
|
| 186 |
-
"react-system": """You are
|
| 187 |
You have access to the following tools:
|
| 188 |
|
| 189 |
{tools_string}
|
| 190 |
|
| 191 |
-
You should help the user determine
|
| 192 |
-
1. The
|
| 193 |
-
2. The
|
| 194 |
-
3. The
|
| 195 |
|
| 196 |
-
Use the
|
| 197 |
|
| 198 |
To use a tool, output an action in this format:
|
| 199 |
```py
|
|
@@ -204,63 +197,63 @@ Always use Python syntax for calling tools. After using a tool, analyze the resu
|
|
| 204 |
""",
|
| 205 |
"react-human": "{input_string}",
|
| 206 |
"react-assistant": "{agent_response}",
|
| 207 |
-
"final_answer": "Final Answer: {answer}"
|
| 208 |
}
|
| 209 |
|
| 210 |
# Load prompt templates from file or use our templates
|
| 211 |
try:
|
| 212 |
with open("prompts.yaml", 'r') as stream:
|
| 213 |
prompt_templates = yaml.safe_load(stream)
|
| 214 |
-
prompt_templates.update(
|
| 215 |
except:
|
| 216 |
-
prompt_templates =
|
| 217 |
|
| 218 |
# Create the agent
|
| 219 |
agent = CodeAgent(
|
| 220 |
model=model,
|
| 221 |
-
tools=[final_answer,
|
| 222 |
max_steps=3,
|
| 223 |
verbosity_level=1,
|
| 224 |
prompt_templates=prompt_templates
|
| 225 |
)
|
| 226 |
|
| 227 |
# Create a custom Gradio UI
|
| 228 |
-
class
|
| 229 |
def launch(self, **kwargs):
|
| 230 |
import gradio as gr
|
| 231 |
|
| 232 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 233 |
-
gr.Markdown("#
|
| 234 |
-
gr.Markdown("Get personalized
|
| 235 |
|
| 236 |
with gr.Row():
|
| 237 |
with gr.Column():
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
submit_btn = gr.Button("Get Recommendations", variant="primary")
|
| 242 |
|
| 243 |
with gr.Row():
|
| 244 |
with gr.Column():
|
| 245 |
-
recommendation_output = gr.Markdown(label="
|
| 246 |
|
| 247 |
-
def get_recommendations(
|
| 248 |
-
if not
|
| 249 |
-
return "Please
|
| 250 |
-
if not
|
| 251 |
-
return "Please
|
| 252 |
-
if not
|
| 253 |
-
return "Please
|
| 254 |
|
| 255 |
try:
|
| 256 |
-
recommendations =
|
| 257 |
return recommendations
|
| 258 |
except Exception as e:
|
| 259 |
return f"Error generating recommendations: {str(e)}"
|
| 260 |
|
| 261 |
-
submit_btn.click(get_recommendations, inputs=[
|
| 262 |
|
| 263 |
demo.launch(**kwargs)
|
| 264 |
|
| 265 |
# Launch the interface
|
| 266 |
-
|
|
|
|
|
|
| 5 |
from Gradio_UI import GradioUI
|
| 6 |
|
| 7 |
@tool
|
| 8 |
+
def investment_advisor(amount: int, risk_profile: str, age: int) -> str:
|
| 9 |
+
"""Provides investment recommendations based on the amount in shekels, risk profile, and age.
|
| 10 |
|
| 11 |
Args:
|
| 12 |
+
amount: Amount to invest in shekels
|
| 13 |
+
risk_profile: Risk profile (low, medium, high)
|
| 14 |
+
age: Age of the investor
|
| 15 |
|
| 16 |
Returns:
|
| 17 |
+
Investment recommendations as formatted text
|
| 18 |
"""
|
| 19 |
+
if amount <= 0:
|
| 20 |
+
return "Error: Investment amount must be a positive number."
|
| 21 |
|
| 22 |
+
if age <= 0 or age > 120:
|
| 23 |
+
return "Error: Please provide a valid age."
|
|
|
|
| 24 |
|
| 25 |
+
# Normalize risk profile
|
| 26 |
+
risk_profile = risk_profile.lower().strip()
|
| 27 |
+
valid_profiles = ["low", "medium", "high"]
|
| 28 |
|
| 29 |
+
if risk_profile not in valid_profiles:
|
| 30 |
+
return "Error: Risk profile must be 'low', 'medium', or 'high'."
|
|
|
|
| 31 |
|
| 32 |
+
# Database of Israeli funds (ETFs and mutual funds)
|
| 33 |
+
israeli_funds = {
|
| 34 |
+
"low": [
|
| 35 |
+
{"name": "KSM Tel Bond 20", "ticker": "TELBOND20", "type": "Bonds", "risk": "Low", "min_investment": 1000, "description": "ETF tracking Tel Aviv corporate bond index"},
|
| 36 |
+
{"name": "Psagot Government Shekel Bonds", "ticker": "PSAGOT-GOV", "type": "Gov Bonds", "risk": "Low", "min_investment": 500, "description": "Israeli government bonds fund"},
|
| 37 |
+
{"name": "Migdal Foreign Currency", "ticker": "MIGDAL-FOREX", "type": "Currency", "risk": "Low-medium", "min_investment": 1000, "description": "Fund investing in foreign currency and money market instruments"},
|
| 38 |
+
{"name": "Harel Deposits Basket", "ticker": "HAREL-PIKADON", "type": "Deposits", "risk": "Very low", "min_investment": 500, "description": "Fixed income bank deposits fund"}
|
| 39 |
+
],
|
| 40 |
+
"medium": [
|
| 41 |
+
{"name": "Tachlit Tel Aviv 35", "ticker": "TA35ETF", "type": "Index", "risk": "Medium", "min_investment": 1000, "description": "ETF tracking the 35 largest companies on the Tel Aviv Stock Exchange"},
|
| 42 |
+
{"name": "Meitav Dash 50/50", "ticker": "MEITAV-50", "type": "Mixed", "risk": "Medium", "min_investment": 2000, "description": "Balanced fund with 50% stocks and 50% bonds"},
|
| 43 |
+
{"name": "Altshuler Shaham Global", "ticker": "ALTSHULER-GLOBAL", "type": "Global", "risk": "Medium", "min_investment": 5000, "description": "Fund with diversified global investments"},
|
| 44 |
+
{"name": "Analyst Corporate AA and Above", "ticker": "ANALYST-AA", "type": "Corp Bonds", "risk": "Medium", "min_investment": 2000, "description": "High-quality corporate bonds fund with AA rating and above"}
|
| 45 |
+
],
|
| 46 |
+
"high": [
|
| 47 |
+
{"name": "Tachlit NASDAQ 100", "ticker": "TACHLIT-NDX", "type": "Technology", "risk": "High", "min_investment": 3000, "description": "ETF tracking the NASDAQ 100 index of largest non-financial companies"},
|
| 48 |
+
{"name": "KSM S&P 500", "ticker": "KSM-SP500", "type": "US", "risk": "High", "min_investment": 3000, "description": "ETF tracking the S&P 500 index"},
|
| 49 |
+
{"name": "Mor Technologies", "ticker": "MOR-TECH", "type": "Sector", "risk": "Very high", "min_investment": 5000, "description": "Fund of Israeli technology companies"},
|
| 50 |
+
{"name": "Harel Foreign Stocks", "ticker": "HAREL-GLOBAL", "type": "International", "risk": "High", "min_investment": 5000, "description": "Fund of international stocks with high growth potential"}
|
| 51 |
+
]
|
| 52 |
+
}
|
| 53 |
|
| 54 |
+
# Asset allocation based on age and risk
|
| 55 |
+
def get_allocation(age, risk):
|
| 56 |
+
# Basic rule: 120 - age = % stocks (for medium risk)
|
| 57 |
+
base_stocks = max(0, min(100, 120 - age))
|
| 58 |
+
|
| 59 |
+
if risk == "low":
|
| 60 |
+
stocks = max(0, base_stocks - 20)
|
| 61 |
+
elif risk == "high":
|
| 62 |
+
stocks = min(100, base_stocks + 20)
|
| 63 |
+
else: # medium risk
|
| 64 |
+
stocks = base_stocks
|
| 65 |
+
|
| 66 |
+
bonds = min(100 - stocks, 80)
|
| 67 |
+
cash = 100 - stocks - bonds
|
| 68 |
+
|
| 69 |
+
return {
|
| 70 |
+
"stocks": stocks,
|
| 71 |
+
"bonds": bonds,
|
| 72 |
+
"cash": cash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
|
|
|
| 74 |
|
| 75 |
+
# Get asset allocation
|
| 76 |
+
allocation = get_allocation(age, risk_profile)
|
| 77 |
+
|
| 78 |
+
# Find suitable funds based on available amount and allocation
|
| 79 |
+
suitable_funds = []
|
| 80 |
+
funds_for_profile = israeli_funds[risk_profile]
|
| 81 |
+
|
| 82 |
+
# Distribute amount by asset class
|
| 83 |
+
stock_amount = amount * allocation["stocks"] / 100
|
| 84 |
+
bond_amount = amount * allocation["bonds"] / 100
|
| 85 |
+
cash_amount = amount * allocation["cash"] / 100
|
| 86 |
+
|
| 87 |
+
# Fund recommendations
|
| 88 |
+
stock_funds = [f for f in funds_for_profile if f["type"] in ["Index", "Technology", "US", "International", "Sector"]]
|
| 89 |
+
bond_funds = [f for f in funds_for_profile if f["type"] in ["Bonds", "Gov Bonds", "Corp Bonds"]]
|
| 90 |
+
cash_funds = [f for f in funds_for_profile if f["type"] in ["Deposits", "Currency"]]
|
| 91 |
|
| 92 |
+
# Build recommendations
|
| 93 |
+
recommendations = []
|
|
|
|
| 94 |
|
| 95 |
+
if stock_amount >= 1000 and stock_funds:
|
| 96 |
+
for fund in stock_funds:
|
| 97 |
+
if fund["min_investment"] <= stock_amount:
|
| 98 |
+
amount_to_invest = min(stock_amount * 0.8, stock_amount)
|
| 99 |
+
recommendations.append({
|
| 100 |
+
"fund": fund,
|
| 101 |
+
"amount": math.floor(amount_to_invest / 100) * 100,
|
| 102 |
+
"asset_class": "Stocks"
|
| 103 |
+
})
|
| 104 |
+
break
|
| 105 |
+
|
| 106 |
+
if bond_amount >= 1000 and bond_funds:
|
| 107 |
+
for fund in bond_funds:
|
| 108 |
+
if fund["min_investment"] <= bond_amount:
|
| 109 |
+
amount_to_invest = min(bond_amount * 0.8, bond_amount)
|
| 110 |
+
recommendations.append({
|
| 111 |
+
"fund": fund,
|
| 112 |
+
"amount": math.floor(amount_to_invest / 100) * 100,
|
| 113 |
+
"asset_class": "Bonds"
|
| 114 |
+
})
|
| 115 |
+
break
|
| 116 |
+
|
| 117 |
+
if cash_amount >= 500 and cash_funds:
|
| 118 |
+
for fund in cash_funds:
|
| 119 |
+
if fund["min_investment"] <= cash_amount:
|
| 120 |
+
amount_to_invest = min(cash_amount * 0.9, cash_amount)
|
| 121 |
+
recommendations.append({
|
| 122 |
+
"fund": fund,
|
| 123 |
+
"amount": math.floor(amount_to_invest / 100) * 100,
|
| 124 |
+
"asset_class": "Cash"
|
| 125 |
+
})
|
| 126 |
+
break
|
| 127 |
|
| 128 |
# Format response
|
| 129 |
+
response = f"## Investment Recommendations\n\n"
|
| 130 |
+
response += f"**Amount:** {amount:,} ₪\n"
|
| 131 |
+
response += f"**Age:** {age} years\n"
|
| 132 |
+
response += f"**Risk Profile:** {risk_profile.capitalize()}\n\n"
|
| 133 |
|
| 134 |
+
response += "### Recommended Asset Allocation\n"
|
| 135 |
+
response += f"- Stocks: {allocation['stocks']}% ({int(stock_amount):,} ₪)\n"
|
| 136 |
+
response += f"- Bonds: {allocation['bonds']}% ({int(bond_amount):,} ₪)\n"
|
| 137 |
+
response += f"- Cash: {allocation['cash']}% ({int(cash_amount):,} ₪)\n\n"
|
| 138 |
+
|
| 139 |
+
if recommendations:
|
| 140 |
+
response += "### Recommended Investments\n\n"
|
| 141 |
+
total_invested = 0
|
| 142 |
|
| 143 |
+
for rec in recommendations:
|
| 144 |
+
fund = rec["fund"]
|
| 145 |
+
amount_to_invest = rec["amount"]
|
| 146 |
+
total_invested += amount_to_invest
|
| 147 |
+
|
| 148 |
+
response += f"**{fund['name']}** ({fund['ticker']})\n"
|
| 149 |
+
response += f"- Type: {fund['type']} ({rec['asset_class']})\n"
|
| 150 |
+
response += f"- Risk: {fund['risk']}\n"
|
| 151 |
+
response += f"- Recommended amount: {amount_to_invest:,} ₪\n"
|
| 152 |
+
response += f"- Description: {fund['description']}\n\n"
|
| 153 |
+
|
| 154 |
+
remaining = amount - total_invested
|
| 155 |
+
if remaining > 0:
|
| 156 |
+
response += f"**Remaining funds:** {remaining:,} ₪ recommended to keep in a savings account for unexpected expenses.\n\n"
|
| 157 |
else:
|
| 158 |
+
response += "Unfortunately, we cannot provide specific fund recommendations for the specified amount. Consider savings accounts or increasing your investment amount.\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
+
response += "### Important Information\n"
|
| 161 |
response += "- These are general recommendations based on the information provided.\n"
|
| 162 |
+
response += "- Before investing, it is recommended to consult with a licensed financial advisor.\n"
|
| 163 |
+
response += "- Past performance does not guarantee future returns.\n"
|
| 164 |
+
response += "- Investments involve risks, including possible loss of principal.\n"
|
| 165 |
|
| 166 |
return response
|
| 167 |
|
|
|
|
| 174 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 175 |
)
|
| 176 |
|
| 177 |
+
# Configure templates for the investment advisor
|
| 178 |
+
investment_prompt_templates = {
|
| 179 |
+
"react-system": """You are an investment advisor who helps users make informed investment decisions in the Israeli market.
|
| 180 |
You have access to the following tools:
|
| 181 |
|
| 182 |
{tools_string}
|
| 183 |
|
| 184 |
+
You should help the user determine where to invest their funds in shekels based on:
|
| 185 |
+
1. The amount in shekels the user is willing to invest
|
| 186 |
+
2. The user's risk profile (low, medium, or high)
|
| 187 |
+
3. The user's age
|
| 188 |
|
| 189 |
+
Use the investment_advisor tool to analyze these factors and formulate investment recommendations.
|
| 190 |
|
| 191 |
To use a tool, output an action in this format:
|
| 192 |
```py
|
|
|
|
| 197 |
""",
|
| 198 |
"react-human": "{input_string}",
|
| 199 |
"react-assistant": "{agent_response}",
|
|
|
|
| 200 |
}
|
| 201 |
|
| 202 |
# Load prompt templates from file or use our templates
|
| 203 |
try:
|
| 204 |
with open("prompts.yaml", 'r') as stream:
|
| 205 |
prompt_templates = yaml.safe_load(stream)
|
| 206 |
+
prompt_templates.update(investment_prompt_templates)
|
| 207 |
except:
|
| 208 |
+
prompt_templates = investment_prompt_templates
|
| 209 |
|
| 210 |
# Create the agent
|
| 211 |
agent = CodeAgent(
|
| 212 |
model=model,
|
| 213 |
+
tools=[final_answer, investment_advisor],
|
| 214 |
max_steps=3,
|
| 215 |
verbosity_level=1,
|
| 216 |
prompt_templates=prompt_templates
|
| 217 |
)
|
| 218 |
|
| 219 |
# Create a custom Gradio UI
|
| 220 |
+
class InvestmentAdvisorUI(GradioUI):
|
| 221 |
def launch(self, **kwargs):
|
| 222 |
import gradio as gr
|
| 223 |
|
| 224 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 225 |
+
gr.Markdown("# Investment Advisor for the Israeli Market")
|
| 226 |
+
gr.Markdown("Get personalized investment recommendations based on your profile")
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
with gr.Column():
|
| 230 |
+
amount_input = gr.Number(label="Amount to invest (in shekels)", minimum=100)
|
| 231 |
+
risk_input = gr.Radio(["Low", "Medium", "High"], label="Risk Profile")
|
| 232 |
+
age_input = gr.Slider(minimum=18, maximum=100, step=1, label="Your Age")
|
| 233 |
submit_btn = gr.Button("Get Recommendations", variant="primary")
|
| 234 |
|
| 235 |
with gr.Row():
|
| 236 |
with gr.Column():
|
| 237 |
+
recommendation_output = gr.Markdown(label="Investment Recommendations")
|
| 238 |
|
| 239 |
+
def get_recommendations(amount, risk, age):
|
| 240 |
+
if not amount or amount < 100:
|
| 241 |
+
return "Please enter an amount of at least 100 shekels."
|
| 242 |
+
if not risk:
|
| 243 |
+
return "Please select a risk profile."
|
| 244 |
+
if not age or age < 18:
|
| 245 |
+
return "Please provide a valid age (18 years or older)."
|
| 246 |
|
| 247 |
try:
|
| 248 |
+
recommendations = investment_advisor(int(amount), risk.lower(), int(age))
|
| 249 |
return recommendations
|
| 250 |
except Exception as e:
|
| 251 |
return f"Error generating recommendations: {str(e)}"
|
| 252 |
|
| 253 |
+
submit_btn.click(get_recommendations, inputs=[amount_input, risk_input, age_input], outputs=recommendation_output)
|
| 254 |
|
| 255 |
demo.launch(**kwargs)
|
| 256 |
|
| 257 |
# Launch the interface
|
| 258 |
+
InvestmentAdvisorUI(agent).launch()
|
| 259 |
+
|