Rename
This commit is contained in:
parent
a706e90d2d
commit
baefb850cf
10
main.py
10
main.py
|
|
@ -3,10 +3,10 @@ from tradingagents.default_config import DEFAULT_CONFIG
|
||||||
|
|
||||||
# Create a custom config
|
# Create a custom config
|
||||||
config = DEFAULT_CONFIG.copy()
|
config = DEFAULT_CONFIG.copy()
|
||||||
config["llm_provider"] = "google" # Use a different model
|
config["llm_provider"] = "openai" # Use a different model
|
||||||
config["backend_url"] = "https://generativelanguage.googleapis.com/v1" # Use a different backend
|
config["backend_url"] = "https://api.openai.com/v1" # Use a different backend
|
||||||
config["deep_think_llm"] = "gemini-2.0-flash" # Use a different model
|
config["deep_think_llm"] = "o4-mini" # Use a different model
|
||||||
config["quick_think_llm"] = "gemini-2.0-flash" # Use a different model
|
config["quick_think_llm"] = "gpt-4o-mini" # Use a different model
|
||||||
config["max_debate_rounds"] = 1 # Increase debate rounds
|
config["max_debate_rounds"] = 1 # Increase debate rounds
|
||||||
config["online_tools"] = True # Increase debate rounds
|
config["online_tools"] = True # Increase debate rounds
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ config["online_tools"] = True # Increase debate rounds
|
||||||
ta = TradingAgentsGraph(debug=True, config=config)
|
ta = TradingAgentsGraph(debug=True, config=config)
|
||||||
|
|
||||||
# forward propagate
|
# forward propagate
|
||||||
_, decision = ta.propagate("NVDA", "2024-05-10")
|
_, decision = ta.propagate("NVDA", "2024-08-01")
|
||||||
print(decision)
|
print(decision)
|
||||||
|
|
||||||
# Memorize mistakes and reflect
|
# Memorize mistakes and reflect
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,24 @@ from pathlib import Path
|
||||||
@dataclass
|
@dataclass
|
||||||
class TransformationConfig:
|
class TransformationConfig:
|
||||||
"""Configuration for the data transformation agent"""
|
"""Configuration for the data transformation agent"""
|
||||||
openai_api_key: str
|
openai_api_key: str = os.environ.get("OPENAI_API_KEY")
|
||||||
model: str = "gpt-4o"
|
model: str = "gpt-4o-mini"
|
||||||
eval_results_path: str = "scripts/eval_results"
|
eval_results_path: str = "scripts/eval_results/AVAH/TradingAgentsStrategy_logs"
|
||||||
output_path: str = "web_app/frontend/public/transformed_data"
|
output_path: str = "scripts/eval_results/AVAH/TradingAgentsStrategy_transformed_logs"
|
||||||
|
backend_url: str = "https://api.openai.com/v1"
|
||||||
|
|
||||||
class DataTransformationAgent:
|
class DataTransformationAgent:
|
||||||
"""Agent that transforms TradingAgents output into widget-friendly JSON format"""
|
"""Agent that transforms TradingAgents output into widget-friendly JSON format"""
|
||||||
|
|
||||||
def __init__(self, config: TransformationConfig):
|
def __init__(self, config: TransformationConfig):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.client = openai.OpenAI(api_key=config.openai_api_key)
|
self.client = openai.OpenAI(
|
||||||
|
api_key=config.openai_api_key,
|
||||||
|
base_url=config.backend_url
|
||||||
|
)
|
||||||
|
|
||||||
# Ensure output directory exists
|
# Ensure output directory exists
|
||||||
os.makedirs(config.output_path, exist_ok=True)
|
os.makedirs(self.config.output_path, exist_ok=True)
|
||||||
|
|
||||||
def get_transformation_prompt(self) -> str:
|
def get_transformation_prompt(self) -> str:
|
||||||
"""Returns the comprehensive transformation prompt"""
|
"""Returns the comprehensive transformation prompt"""
|
||||||
|
|
@ -271,7 +275,7 @@ IMPORTANT: Return ONLY the transformed JSON, no additional text or explanations.
|
||||||
{"role": "user", "content": full_prompt}
|
{"role": "user", "content": full_prompt}
|
||||||
],
|
],
|
||||||
temperature=0.1,
|
temperature=0.1,
|
||||||
max_tokens=4000
|
max_tokens=16384
|
||||||
)
|
)
|
||||||
|
|
||||||
# Parse the response
|
# Parse the response
|
||||||
|
|
@ -288,13 +292,14 @@ IMPORTANT: Return ONLY the transformed JSON, no additional text or explanations.
|
||||||
# Add fallback values if transformation missed anything
|
# Add fallback values if transformation missed anything
|
||||||
self._add_fallback_values(transformed_data, input_data)
|
self._add_fallback_values(transformed_data, input_data)
|
||||||
|
|
||||||
return transformed_data
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error transforming data: {e}")
|
print(f"Error transforming data: {e}")
|
||||||
# Return a basic fallback structure
|
# Return a basic fallback structure
|
||||||
return self._create_fallback_structure(input_data)
|
transformed_data = self._create_fallback_structure(input_data)
|
||||||
|
|
||||||
|
return transformed_data
|
||||||
|
|
||||||
def _add_fallback_values(self, transformed_data: Dict[str, Any], original_data: Dict[str, Any]):
|
def _add_fallback_values(self, transformed_data: Dict[str, Any], original_data: Dict[str, Any]):
|
||||||
"""Add fallback values for any missing required fields"""
|
"""Add fallback values for any missing required fields"""
|
||||||
|
|
||||||
|
|
@ -450,35 +455,26 @@ IMPORTANT: Return ONLY the transformed JSON, no additional text or explanations.
|
||||||
for company_dir in eval_results_path.iterdir():
|
for company_dir in eval_results_path.iterdir():
|
||||||
if not company_dir.is_dir():
|
if not company_dir.is_dir():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
company_ticker = company_dir.name
|
company_ticker = company_dir.name
|
||||||
logs_dir = company_dir / "TradingAgentsStrategy_logs"
|
logs_dir = company_dir / "TradingAgentsStrategy_logs"
|
||||||
|
transformed_dir = company_dir / "TradingAgentsStrategy_transformed_logs"
|
||||||
if not logs_dir.exists():
|
transformed_dir.mkdir(parents=True, exist_ok=True)
|
||||||
continue
|
|
||||||
|
|
||||||
# Process each JSON file in the logs directory
|
# Process each JSON file in the logs directory
|
||||||
for json_file in logs_dir.glob("*.json"):
|
for json_file in logs_dir.glob("*.json"):
|
||||||
try:
|
try:
|
||||||
print(f"Processing {json_file}")
|
print(f"Processing {json_file}")
|
||||||
|
|
||||||
# Load the original data
|
# Process the file
|
||||||
with open(json_file, 'r') as f:
|
success = self.process_single_file(str(json_file), str(transformed_dir / json_file.name))
|
||||||
original_data = json.load(f)
|
|
||||||
|
|
||||||
# Transform the data
|
if success:
|
||||||
transformed_data = self.transform_single_file(original_data)
|
results["success"].append(str(transformed_dir / json_file.name))
|
||||||
|
print(f"Successfully transformed and saved: {transformed_dir / json_file.name}")
|
||||||
# Create output filename
|
else:
|
||||||
output_filename = f"{company_ticker}_{json_file.stem}_transformed.json"
|
results["failed"].append(str(json_file))
|
||||||
output_path = Path(self.config.output_path) / output_filename
|
print(f"Failed to process {json_file}")
|
||||||
|
|
||||||
# Save the transformed data
|
|
||||||
with open(output_path, 'w') as f:
|
|
||||||
json.dump(transformed_data, f, indent=2)
|
|
||||||
|
|
||||||
results["success"].append(str(output_path))
|
|
||||||
print(f"Successfully transformed and saved: {output_path}")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to process {json_file}: {e}")
|
print(f"Failed to process {json_file}: {e}")
|
||||||
|
|
@ -525,11 +521,11 @@ def main():
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Transform TradingAgents output to widget-friendly format")
|
parser = argparse.ArgumentParser(description="Transform TradingAgents output to widget-friendly format")
|
||||||
parser.add_argument("--api-key", required=True, help="OpenAI API key")
|
parser.add_argument("--api-key", help="OpenAI API key")
|
||||||
parser.add_argument("--input-file", help="Process a single input file")
|
parser.add_argument("--input-file", default="scripts/eval_results/AVAH/TradingAgentsStrategy_logs/full_states_log_2025-07-26.json", help="Process a single input file")
|
||||||
parser.add_argument("--output-file", help="Output file path (for single file processing)")
|
parser.add_argument("--output-file", default="scripts/eval_results/AVAH/TradingAgentsStrategy_transformed_logs/full_states_log_2025-07-26.json", help="Output file path (for single file processing)")
|
||||||
parser.add_argument("--eval-results-path", default="scripts/eval_results", help="Path to eval_results directory")
|
parser.add_argument("--eval-results-path", default="scripts/eval_results", help="Path to eval_results directory")
|
||||||
parser.add_argument("--output-path", default="web_app/frontend/public/transformed_data", help="Output directory path")
|
parser.add_argument("--output-path", default="scripts/eval_results/AVAH/TradingAgentsStrategy_transformed_logs/", help="Output directory path")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
Loading…
Reference in New Issue