Spaces:
Runtime error
Runtime error
Update agents/simple_tools.py
Browse files2 unmodified lines345678415 unmodified lines4244254264274284294305 unmodified lines4364374384394404414422 unmodified lines44544644744844945045145245345445545645745845946046146246346446546655 unmodified lines52252352452552652752852953053153253353453553653753853954054154254354454554654754814 unmodified lines5635645655665675682 unmodified linesFocus: Notes, Balance Sheet, P&L, Cash Flow generation only"""from langchain_core.tools import toolimport osimport subprocessimport json415 unmodified linesif user_api_key:env["OPENROUTER_API_KEY"] = user_api_keyelif os.getenv("OPENROUTER_API_KEY"):# Fallback to environment variable if no user key providedenv["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")cwd = os.getcwd()5 unmodified linesenv=env,cwd=cwd,capture_output=True,text=True)if result1.returncode != 0:2 unmodified lines# Step 2: Run LLM notes generatorlogger.info("Step 2: Generating notes using LLM")if note_numbers:# Generate specific notesresult2 = subprocess.run(["python", "notes/llm_notes_generator.py", "specific", note_numbers],env=env,cwd=cwd,capture_output=True,text=True)else:# Generate all notesresult2 = subprocess.run(["python", "notes/llm_notes_generator.py", "all", ""],env=env,cwd=cwd,capture_output=True,text=True)if result2.returncode != 0:55 unmodified linesexcept Exception as e:logger.error(f"Error applying UDFs to JSON: {e}")# Check if JSON file has contenttry:with open(input_json, 'r', encoding='utf-8') as f:json_content = json.load(f)if isinstance(json_content, dict) and 'notes' in json_content and not json_content['notes']:logger.warning("JSON file exists but contains no notes")except Exception as e:execution_time = round(time.time() - start_time, 2)return {"status": "error","error": f"Invalid JSON file generated: {str(e)}","execution_id": execution_id,"execution_time": execution_time}result3 = subprocess.run(["python", "notes/llm_notes_excel_converter.py", input_json, output_excel],env=env,cwd=cwd,capture_output=True,text=True)if result3.returncode == 0:14 unmodified lines"execution_time": execution_time}except Exception as e:execution_time = round(time.time() - start_time, 2)logger.error(f"LLM notes generation failed: {e}")2 unmodified lines3456789415 unmodified lines4254264274284294305 unmodified lines4364374384394404414424432 unmodified lines44644744844945045145245345445545645745845946046146246346446546646755 unmodified lines52352452552652752852953053153253353453514 unmodified lines5505515525535545555565575585595605615625635645652 unmodified linesFocus: Notes, Balance Sheet, P&L, Cash Flow generation only"""from langchain_core.tools import toolimport subprocessimport osimport subprocessimport json415 unmodified linesif user_api_key:env["OPENROUTER_API_KEY"] = user_api_keyelif os.getenv("OPENROUTER_API_KEY"):env["OPENROUTER_API_KEY"] = os.getenv("OPENROUTER_API_KEY")cwd = os.getcwd()5 unmodified linesenv=env,cwd=cwd,capture_output=True,text=True,timeout=120 # ADD THIS: 2 minute timeout)if result1.returncode != 0:2 unmodified lines# Step 2: Run LLM notes generatorlogger.info("Step 2: Generating notes using LLM")if note_numbers:result2 = subprocess.run(["python", "notes/llm_notes_generator.py", "specific", note_numbers],env=env,cwd=cwd,capture_output=True,text=True,timeout=600 # ADD THIS: 10 minute timeout for LLM generation)else:result2 = subprocess.run(["python", "notes/llm_notes_generator.py", "all", ""],env=env,cwd=cwd,capture_output=True,text=True,timeout=900 # ADD THIS: 15 minute timeout for all notes)if result2.returncode != 0:55 unmodified linesexcept Exception as e:logger.error(f"Error applying UDFs to JSON: {e}")result3 = subprocess.run(["python", "notes/llm_notes_excel_converter.py", input_json, output_excel],env=env,cwd=cwd,capture_output=True,text=True,timeout=120 # ADD THIS: 2 minute timeout)if result3.returncode == 0:14 unmodified lines"execution_time": execution_time}except subprocess.TimeoutExpired as te: # ADD THIS: Handle timeoutexecution_time = round(time.time() - start_time, 2)logger.error(f"LLM notes generation timed out after {execution_time}s")return {"status": "error","error": f"LLM notes generation timed out. The process took longer than expected. Try generating fewer notes or check your API key.","execution_id": execution_id,"execution_time": execution_time,"timeout": True}except Exception as e:execution_time = round(time.time() - start_time, 2)logger.error(f"LLM notes generation failed: {e}")
agents/simple_tools.py+19-22