From 26ccc48066eb7271a9e23b7f8e89415d65ba1943 Mon Sep 17 00:00:00 2001 From: Kevin Bruton Date: Mon, 29 Sep 2025 08:58:02 +0200 Subject: [PATCH] feat: add more frontend config options --- webapp/main.py | 60 ++++++++++++-- webapp/static/styles.css | 26 +++++- webapp/templates/index.html | 157 ++++++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 8 deletions(-) diff --git a/webapp/main.py b/webapp/main.py index 6e037461..4ceedd22 100644 --- a/webapp/main.py +++ b/webapp/main.py @@ -148,17 +148,46 @@ def update_execution_state(state: Dict[str, Any]): if child.get("children")) app_state["overall_progress"] = min(100, int((completed_agents / max(total_phases, 1)) * 100)) -def run_trading_process(company_symbol: str): +def run_trading_process(company_symbol: str, config: Dict[str, Any]): """Runs the TradingAgentsGraph in a separate thread.""" with app_state_lock: app_state["overall_status"] = "in_progress" app_state["overall_progress"] = 0 try: - graph = TradingAgentsGraph() - current_date = time.strftime("%Y-%m-%d") # Use current date for analysis + # Import and create custom config + from tradingagents.default_config import DEFAULT_CONFIG + + # Create custom configuration with user selections + custom_config = DEFAULT_CONFIG.copy() + custom_config["llm_provider"] = config["llm_provider"] + custom_config["max_debate_rounds"] = config["max_debate_rounds"] + custom_config["cost_per_trade"] = config["cost_per_trade"] + + # Set the appropriate LLM models based on provider + if config["llm_provider"] == "google": + custom_config["gemini_quick_think_llm"] = config["quick_think_llm"] + custom_config["gemini_deep_think_llm"] = config["deep_think_llm"] + else: + custom_config["quick_think_llm"] = config["quick_think_llm"] + custom_config["deep_think_llm"] = config["deep_think_llm"] + + # Set backend URL based on provider + if config["llm_provider"] == "openrouter": + custom_config["backend_url"] = "https://openrouter.ai/api/v1" + elif config["llm_provider"] == "google": + custom_config["backend_url"] = "https://generativelanguage.googleapis.com/v1" + elif config["llm_provider"] == "anthropic": + custom_config["backend_url"] = "https://api.anthropic.com/" + elif config["llm_provider"] == "ollama": + custom_config["backend_url"] = f"http://{os.getenv('OLLAMA_HOST', 'localhost')}:11434/v1" + else: # openai + custom_config["backend_url"] = "https://api.openai.com/v1" + + graph = TradingAgentsGraph(config=custom_config) + analysis_date = config["analysis_date"] # Use user-selected date # The propagate method now accepts the callback and trade_date - final_state = graph.propagate(company_symbol, trade_date=current_date, on_step_callback=update_execution_state) + final_state = graph.propagate(company_symbol, trade_date=analysis_date, on_step_callback=update_execution_state) with app_state_lock: app_state["overall_status"] = "completed" @@ -197,7 +226,16 @@ async def read_root(): return template.render(app_state=app_state) @app.post("/start", response_class=HTMLResponse) -async def start_process(background_tasks: BackgroundTasks, company_symbol: str = Form(...)): +async def start_process( + background_tasks: BackgroundTasks, + company_symbol: str = Form(...), + llm_provider: str = Form(...), + quick_think_llm: str = Form(...), + deep_think_llm: str = Form(...), + max_debate_rounds: int = Form(...), + cost_per_trade: float = Form(...), + analysis_date: str = Form(...) +): # Check if all required environment variables are set missing_vars = [var for var in required_env_vars if not os.getenv(var)] if missing_vars: @@ -224,8 +262,18 @@ async def start_process(background_tasks: BackgroundTasks, company_symbol: str = app_state["execution_tree"] = [] # Clear for new run app_state["overall_status"] = "in_progress" app_state["overall_progress"] = 0 + + # Store all configuration parameters + app_state["config"] = { + "llm_provider": llm_provider, + "quick_think_llm": quick_think_llm, + "deep_think_llm": deep_think_llm, + "max_debate_rounds": max_debate_rounds, + "cost_per_trade": cost_per_trade, + "analysis_date": analysis_date + } - background_tasks.add_task(run_trading_process, company_symbol) + background_tasks.add_task(run_trading_process, company_symbol, app_state["config"]) template = jinja_env.get_template("_partials/left_panel.html") return template.render(tree=app_state["execution_tree"], app_state=app_state) diff --git a/webapp/static/styles.css b/webapp/static/styles.css index e9b3da6e..07af7314 100644 --- a/webapp/static/styles.css +++ b/webapp/static/styles.css @@ -103,7 +103,8 @@ body { font-size: 0.9em; } -#config-form input { +#config-form input, +#config-form select { width: 100%; padding: 10px; margin-bottom: 15px; @@ -113,14 +114,35 @@ body { color: var(--text-primary); font-size: 1em; transition: border-color 0.3s ease, box-shadow 0.3s ease; + box-sizing: border-box; } -#config-form input:focus { +#config-form input:focus, +#config-form select:focus { outline: none; border-color: var(--accent-color); box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2); } +/* Specific styling for select dropdowns */ +#config-form select { + cursor: pointer; + background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E"); + background-repeat: no-repeat; + background-position: right 10px center; + background-size: 16px; + padding-right: 40px; + appearance: none; + -webkit-appearance: none; + -moz-appearance: none; +} + +#config-form select option { + background-color: var(--input-bg); + color: var(--text-primary); + padding: 8px; +} + #config-form button { width: 100%; padding: 12px; diff --git a/webapp/templates/index.html b/webapp/templates/index.html index f308cd35..3342cd52 100644 --- a/webapp/templates/index.html +++ b/webapp/templates/index.html @@ -22,6 +22,41 @@
+ + + + + + + + + + + + + + + + + + +
Starting process...
@@ -32,5 +67,127 @@

Enter a company symbol (e.g., AAPL, MSFT, GOOGL) and click "Start Process" to begin the trading analysis.

+ +