Spaces:
Sleeping
Sleeping
Graham Paasch commited on
Commit ·
116aa59
1
Parent(s): a97abe4
Remove LLM mock fallbacks and surface real errors
Browse files- agent/llm_client.py +10 -29
agent/llm_client.py
CHANGED
|
@@ -87,7 +87,7 @@ class LLMClient:
|
|
| 87 |
Returns response text or yields chunks if streaming
|
| 88 |
"""
|
| 89 |
if not self.provider:
|
| 90 |
-
|
| 91 |
|
| 92 |
if self.provider == "openrouter":
|
| 93 |
return self._call_openrouter(messages, temperature, max_tokens, stream)
|
|
@@ -104,8 +104,7 @@ class LLMClient:
|
|
| 104 |
) -> Iterator[str]:
|
| 105 |
"""Stream chat completion response"""
|
| 106 |
if not self.provider:
|
| 107 |
-
|
| 108 |
-
return
|
| 109 |
|
| 110 |
if self.provider == "openrouter":
|
| 111 |
yield from self._stream_openrouter(messages, temperature, max_tokens)
|
|
@@ -159,7 +158,7 @@ class LLMClient:
|
|
| 159 |
logger.error(f"OpenRouter API error: {e}")
|
| 160 |
if monitor:
|
| 161 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 162 |
-
|
| 163 |
|
| 164 |
def _stream_openrouter(self, messages, temperature, max_tokens):
|
| 165 |
"""Stream from OpenRouter"""
|
|
@@ -217,7 +216,7 @@ class LLMClient:
|
|
| 217 |
logger.error(f"OpenRouter streaming error: {e}")
|
| 218 |
if monitor:
|
| 219 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 220 |
-
|
| 221 |
|
| 222 |
def _call_openai(self, messages, temperature, max_tokens, stream):
|
| 223 |
"""Call OpenAI API"""
|
|
@@ -254,7 +253,7 @@ class LLMClient:
|
|
| 254 |
logger.error(f"OpenAI API error: {e}")
|
| 255 |
if monitor:
|
| 256 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 257 |
-
|
| 258 |
|
| 259 |
def _stream_openai(self, messages, temperature, max_tokens):
|
| 260 |
"""Stream from OpenAI"""
|
|
@@ -294,7 +293,7 @@ class LLMClient:
|
|
| 294 |
logger.error(f"OpenAI streaming error: {e}")
|
| 295 |
if monitor:
|
| 296 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 297 |
-
|
| 298 |
|
| 299 |
def _call_anthropic(self, messages, temperature, max_tokens, stream):
|
| 300 |
"""Call Anthropic API"""
|
|
@@ -346,7 +345,7 @@ class LLMClient:
|
|
| 346 |
if self.openai_key:
|
| 347 |
logger.info("Falling back to OpenAI due to Anthropic error")
|
| 348 |
return self._call_openai(messages, temperature, max_tokens, stream=False)
|
| 349 |
-
|
| 350 |
|
| 351 |
def _stream_anthropic(self, messages, temperature, max_tokens):
|
| 352 |
"""Stream from Anthropic"""
|
|
@@ -401,26 +400,8 @@ class LLMClient:
|
|
| 401 |
logger.info("Falling back to OpenAI streaming due to Anthropic error")
|
| 402 |
yield from self._stream_openai(messages, temperature, max_tokens)
|
| 403 |
else:
|
| 404 |
-
|
| 405 |
|
| 406 |
def _mock_response(self, messages: List[LLMMessage]) -> str:
|
| 407 |
-
"""
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
if "consultation" in last_user_msg.lower():
|
| 411 |
-
return json.dumps({
|
| 412 |
-
"questions": [
|
| 413 |
-
"What is your total budget for this network deployment?",
|
| 414 |
-
"Do you have any vendor preferences? (Cisco, Juniper, Arista, Ubiquiti, MikroTik)",
|
| 415 |
-
"When do you need this network operational?",
|
| 416 |
-
"Do you have existing infrastructure to integrate with?",
|
| 417 |
-
"What are your bandwidth requirements per location?"
|
| 418 |
-
],
|
| 419 |
-
"clarifications": [
|
| 420 |
-
"How many total concurrent devices across all 3 locations?",
|
| 421 |
-
"Do you need site-to-site VPN between locations?",
|
| 422 |
-
"PCI-DSS compliance required for payment processing?"
|
| 423 |
-
]
|
| 424 |
-
})
|
| 425 |
-
|
| 426 |
-
return "Mock LLM response - please configure API keys"
|
|
|
|
| 87 |
Returns response text or yields chunks if streaming
|
| 88 |
"""
|
| 89 |
if not self.provider:
|
| 90 |
+
raise RuntimeError("No LLM provider configured. Set ANTHROPIC_MCP_1ST_BDAY or OPENAI_MCP_1ST_BDAY.")
|
| 91 |
|
| 92 |
if self.provider == "openrouter":
|
| 93 |
return self._call_openrouter(messages, temperature, max_tokens, stream)
|
|
|
|
| 104 |
) -> Iterator[str]:
|
| 105 |
"""Stream chat completion response"""
|
| 106 |
if not self.provider:
|
| 107 |
+
raise RuntimeError("No LLM provider configured. Set ANTHROPIC_MCP_1ST_BDAY or OPENAI_MCP_1ST_BDAY.")
|
|
|
|
| 108 |
|
| 109 |
if self.provider == "openrouter":
|
| 110 |
yield from self._stream_openrouter(messages, temperature, max_tokens)
|
|
|
|
| 158 |
logger.error(f"OpenRouter API error: {e}")
|
| 159 |
if monitor:
|
| 160 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 161 |
+
raise
|
| 162 |
|
| 163 |
def _stream_openrouter(self, messages, temperature, max_tokens):
|
| 164 |
"""Stream from OpenRouter"""
|
|
|
|
| 216 |
logger.error(f"OpenRouter streaming error: {e}")
|
| 217 |
if monitor:
|
| 218 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 219 |
+
raise
|
| 220 |
|
| 221 |
def _call_openai(self, messages, temperature, max_tokens, stream):
|
| 222 |
"""Call OpenAI API"""
|
|
|
|
| 253 |
logger.error(f"OpenAI API error: {e}")
|
| 254 |
if monitor:
|
| 255 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 256 |
+
raise
|
| 257 |
|
| 258 |
def _stream_openai(self, messages, temperature, max_tokens):
|
| 259 |
"""Stream from OpenAI"""
|
|
|
|
| 293 |
logger.error(f"OpenAI streaming error: {e}")
|
| 294 |
if monitor:
|
| 295 |
monitor.complete_call(call_id, success=False, error_message=str(e))
|
| 296 |
+
raise
|
| 297 |
|
| 298 |
def _call_anthropic(self, messages, temperature, max_tokens, stream):
|
| 299 |
"""Call Anthropic API"""
|
|
|
|
| 345 |
if self.openai_key:
|
| 346 |
logger.info("Falling back to OpenAI due to Anthropic error")
|
| 347 |
return self._call_openai(messages, temperature, max_tokens, stream=False)
|
| 348 |
+
raise RuntimeError(f"Anthropic call failed: {err_msg}")
|
| 349 |
|
| 350 |
def _stream_anthropic(self, messages, temperature, max_tokens):
|
| 351 |
"""Stream from Anthropic"""
|
|
|
|
| 400 |
logger.info("Falling back to OpenAI streaming due to Anthropic error")
|
| 401 |
yield from self._stream_openai(messages, temperature, max_tokens)
|
| 402 |
else:
|
| 403 |
+
raise RuntimeError(f"Anthropic streaming failed: {err_msg}")
|
| 404 |
|
| 405 |
def _mock_response(self, messages: List[LLMMessage]) -> str:
|
| 406 |
+
"""Deprecated: mocks disabled to avoid hiding real failures."""
|
| 407 |
+
raise RuntimeError("LLM mock responses are disabled. Provide a valid API key.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|