Update agents/simple_tools.py

#13
Files changed (1) hide show
  1. agents/simple_tools.py +21 -10
agents/simple_tools.py CHANGED
@@ -77,11 +77,12 @@ def generate_notes_full_pipeline_from_path(file_path: str, note_numbers: str = "
77
 
78
 
79
  @tool
80
- def generate_balance_sheet(file_path: str, **kwargs) -> Dict[str, Any]:
81
  """
82
  Generate balance sheet from trial balance file using complete pipeline
83
  Args:
84
  file_path: Path to trial balance Excel file
 
85
  """
86
  execution_id = str(uuid.uuid4())[:8]
87
  start_time = time.time()
@@ -91,12 +92,19 @@ def generate_balance_sheet(file_path: str, **kwargs) -> Dict[str, Any]:
91
  try:
92
  # Use the complete BS pipeline from the existing endpoint
93
  env = os.environ.copy()
94
- if os.getenv("OPENROUTER_API_KEY"):
95
- env["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
96
- # Override with user-provided API key if available
97
- user_api_key = kwargs.get("user_api_key")
98
  if user_api_key:
99
  env["OPENROUTER_API_KEY"] = user_api_key
 
 
 
 
 
 
 
 
100
  env["INPUT_FILE"] = "data/clean_financial_data_bs.json"
101
  cwd = os.getcwd()
102
 
@@ -397,12 +405,13 @@ def generate_cash_flow_statement(file_path: str) -> Dict[str, Any]:
397
  }
398
 
399
  @tool
400
- def generate_llm_notes(file_path: str, note_numbers: str = "", **kwargs) -> Dict[str, Any]:
401
  """
402
  Generate notes using LLM-based approach (FlexibleFinancialNoteGenerator)
403
  Args:
404
  file_path: Path to trial balance Excel file
405
  note_numbers: Optional comma-separated note numbers to generate
 
406
  Returns:
407
  dict with status, output_xlsx_path, and error if any
408
  """
@@ -412,12 +421,14 @@ def generate_llm_notes(file_path: str, note_numbers: str = "", **kwargs) -> Dict
412
  try:
413
  # Use the complete LLM notes pipeline from existing scripts
414
  env = os.environ.copy()
415
- if os.getenv("OPENROUTER_API_KEY"):
416
- env["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
417
- # Override with user-provided API key if available
418
- user_api_key = kwargs.get("user_api_key")
419
  if user_api_key:
420
  env["OPENROUTER_API_KEY"] = user_api_key
 
 
 
 
421
  cwd = os.getcwd()
422
 
423
  # Step 1: Run LLM notes data processor
 
77
 
78
 
79
  @tool
80
+ def generate_balance_sheet(file_path: str, user_api_key: str = None, **kwargs) -> Dict[str, Any]:
81
  """
82
  Generate balance sheet from trial balance file using complete pipeline
83
  Args:
84
  file_path: Path to trial balance Excel file
85
+ user_api_key: OpenRouter API key for LLM calls
86
  """
87
  execution_id = str(uuid.uuid4())[:8]
88
  start_time = time.time()
 
92
  try:
93
  # Use the complete BS pipeline from the existing endpoint
94
  env = os.environ.copy()
95
+
96
+ # Get user-provided API key from parameter
97
+ logger.info(f"generate_balance_sheet: user_api_key received = {bool(user_api_key)}")
 
98
  if user_api_key:
99
  env["OPENROUTER_API_KEY"] = user_api_key
100
+ logger.info("generate_balance_sheet: Setting OPENROUTER_API_KEY from user_api_key")
101
+ elif os.getenv("OPENROUTER_API_KEY"):
102
+ # Fallback to environment variable if no user key provided
103
+ env["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
104
+ logger.info("generate_balance_sheet: Using OPENROUTER_API_KEY from environment")
105
+ else:
106
+ logger.warning("generate_balance_sheet: No API key available!")
107
+
108
  env["INPUT_FILE"] = "data/clean_financial_data_bs.json"
109
  cwd = os.getcwd()
110
 
 
405
  }
406
 
407
  @tool
408
+ def generate_llm_notes(file_path: str, note_numbers: str = "", user_api_key: str = None, **kwargs) -> Dict[str, Any]:
409
  """
410
  Generate notes using LLM-based approach (FlexibleFinancialNoteGenerator)
411
  Args:
412
  file_path: Path to trial balance Excel file
413
  note_numbers: Optional comma-separated note numbers to generate
414
+ user_api_key: OpenRouter API key for LLM calls
415
  Returns:
416
  dict with status, output_xlsx_path, and error if any
417
  """
 
421
  try:
422
  # Use the complete LLM notes pipeline from existing scripts
423
  env = os.environ.copy()
424
+
425
+ # Get user-provided API key from parameter
 
 
426
  if user_api_key:
427
  env["OPENROUTER_API_KEY"] = user_api_key
428
+ elif os.getenv("OPENROUTER_API_KEY"):
429
+ # Fallback to environment variable if no user key provided
430
+ env["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")
431
+
432
  cwd = os.getcwd()
433
 
434
  # Step 1: Run LLM notes data processor