mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-09 04:57:44 +00:00
fix(strategy): Fix template variables, APIBackend import, and JSON extraction
- Fix {{ ic_values }} template variable not being replaced in prompts
- Fix APIBackend abstract class import (use factory from llm_utils)
- Add robust JSON extraction with python code block fallback
- Add response_format json_object to LLM payload
- Add detailed debug logging for LLM responses
- Simplify prompt variable replacement for readability
Files:
rdagent/components/coder/strategy_orchestrator.py
rdagent/components/prompt_loader.py
rdagent/app/cli.py
prompts/strategy_generation_v4.yaml
This commit is contained in:
+1
-1
@@ -567,7 +567,7 @@ def rl_trading_cli(
|
||||
@app.command(name="generate_strategies")
|
||||
def generate_strategies_cli(
|
||||
count: int = typer.Option(10, "--count", "-n", help="Number of strategies to generate"),
|
||||
workers: int = typer.Option(4, "--workers", "-w", help="Parallel workers"),
|
||||
workers: int = typer.Option(2, "--workers", "-w", help="Parallel workers (default: 2 to avoid LLM overload)"),
|
||||
style: str = typer.Option("swing", "--style", "-s", help="Trading style: daytrading or swing"),
|
||||
optuna: bool = typer.Option(True, "--optuna/--no-optuna", help="Enable Optuna optimization"),
|
||||
optuna_trials: int = typer.Option(30, "--optuna-trials", help="Number of Optuna trials per strategy"),
|
||||
|
||||
@@ -39,8 +39,8 @@ def get_local_prompt_path(name: str) -> Optional[Path]:
|
||||
if not LOCAL_PROMPTS_DIR.exists():
|
||||
return None
|
||||
|
||||
# Try versioned files first (v3, v2, v1, etc.)
|
||||
for version in ["v3", "v2", "v1"]:
|
||||
# Try versioned files first (v4, v3, v2, v1, etc.)
|
||||
for version in ["v4", "v3", "v2", "v1"]:
|
||||
for ext in ["yaml", "yml"]:
|
||||
path = LOCAL_PROMPTS_DIR / f"{name}_{version}.{ext}"
|
||||
if path.exists():
|
||||
@@ -101,12 +101,15 @@ def load_prompt(
|
||||
if local_path:
|
||||
print(f"✓ Loading prompt '{name}' from local: {local_path}")
|
||||
data = load_yaml_file(local_path)
|
||||
|
||||
|
||||
if section:
|
||||
return data.get(section, "")
|
||||
|
||||
# If data is dict with 'system' and 'user', return full dict
|
||||
|
||||
# If data is dict, unwrap single-key dicts (e.g., {'strategy_generation': {'system': ...}})
|
||||
if isinstance(data, dict):
|
||||
# If only one key and it matches the name, unwrap it
|
||||
if len(data) == 1 and name in data:
|
||||
return data[name]
|
||||
return data
|
||||
return str(data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user