Emperor555 Claude commited on
Commit
8a930bf
·
1 Parent(s): 5983c54

Add debug logging for API key detection

Browse files

Shows which environment variables are available when
NEBIUS_API_KEY is not found, helping diagnose Modal
secret configuration issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. modal_app.py +24 -9
modal_app.py CHANGED
@@ -44,6 +44,9 @@ def serve():
44
  os.environ["ENABLE_MCP_SERVER"] = "false"
45
  os.chdir("/app")
46
 
 
 
 
47
  # Pass environment variables to subprocess
48
  env = os.environ.copy()
49
 
@@ -78,23 +81,35 @@ def format_mcp_tools(tools):
78
  return md
79
 
80
  def explain_topic(topic, persona_name, audience=""):
 
 
81
  if not topic.strip():
82
  return "Please enter a topic!", "", "", ""
83
  if not persona_name:
84
  persona_name = "5-Year-Old"
 
 
 
 
 
 
 
85
  steps_log = []
86
  explanation = ""
87
  sources = []
88
  mcp_tools = []
89
- for update in run_agent(topic, persona_name, audience):
90
- if update["type"] == "step":
91
- steps_log.append(f"**{update['title']}**\\n{update['content']}")
92
- if update["step"] == "research_done" and "sources" in update:
93
- sources = update["sources"]
94
- elif update["type"] == "result":
95
- explanation = update["explanation"]
96
- sources = update.get("sources", sources)
97
- mcp_tools = update.get("mcp_tools", [])
 
 
 
98
  return explanation, format_sources(sources), "\\n\\n---\\n\\n".join(steps_log), format_mcp_tools(mcp_tools)
99
 
100
  def generate_audio(explanation, persona_name):
 
44
  os.environ["ENABLE_MCP_SERVER"] = "false"
45
  os.chdir("/app")
46
 
47
+ # Debug: Print available env vars (without values)
48
+ print("Available env vars:", [k for k in os.environ.keys() if 'KEY' in k or 'API' in k or 'NEBIUS' in k or 'ELEVEN' in k])
49
+
50
  # Pass environment variables to subprocess
51
  env = os.environ.copy()
52
 
 
81
  return md
82
 
83
  def explain_topic(topic, persona_name, audience=""):
84
+ import os
85
+ import traceback
86
  if not topic.strip():
87
  return "Please enter a topic!", "", "", ""
88
  if not persona_name:
89
  persona_name = "5-Year-Old"
90
+
91
+ # Check API key
92
+ nebius_key = os.getenv("NEBIUS_API_KEY")
93
+ if not nebius_key:
94
+ available_keys = [k for k in os.environ.keys() if 'KEY' in k or 'API' in k or 'NEBIUS' in k]
95
+ return f"Error: NEBIUS_API_KEY not found. Available: {available_keys}", "", "", ""
96
+
97
  steps_log = []
98
  explanation = ""
99
  sources = []
100
  mcp_tools = []
101
+ try:
102
+ for update in run_agent(topic, persona_name, audience):
103
+ if update["type"] == "step":
104
+ steps_log.append(f"**{update['title']}**\\n{update['content']}")
105
+ if update["step"] == "research_done" and "sources" in update:
106
+ sources = update["sources"]
107
+ elif update["type"] == "result":
108
+ explanation = update["explanation"]
109
+ sources = update.get("sources", sources)
110
+ mcp_tools = update.get("mcp_tools", [])
111
+ except Exception as e:
112
+ return f"Error: {str(e)}\\n\\n{traceback.format_exc()}", "", "\\n\\n---\\n\\n".join(steps_log), ""
113
  return explanation, format_sources(sources), "\\n\\n---\\n\\n".join(steps_log), format_mcp_tools(mcp_tools)
114
 
115
  def generate_audio(explanation, persona_name):