Spaces:
Sleeping
Sleeping
fix: DDL generation resilience — retry + longer timeout + Google None guard
Browse files- Anthropic client timeout: 60s → 180s (complex schemas need more headroom)
- DDL generation: 2-attempt retry loop; logs warning on first failure before retry
- Google provider: explicitly raise ValueError when response.text is None
(safety filter block silently returns None, causing misleading "Result: None" error)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- chat_interface.py +23 -6
- main_research.py +5 -2
chat_interface.py
CHANGED
|
@@ -2758,17 +2758,34 @@ Generate complete CREATE TABLE statements with proper Snowflake syntax and depen
|
|
| 2758 |
{"role": "user", "content": schema_prompt}
|
| 2759 |
]
|
| 2760 |
|
| 2761 |
-
# Make request (non-streaming for DDL)
|
| 2762 |
-
self.log_feedback("Generating DDL...")
|
| 2763 |
import time as _time
|
|
|
|
| 2764 |
_ddl_start = _time.time()
|
| 2765 |
-
ddl_result =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2766 |
_ddl_ms = int((_time.time() - _ddl_start) * 1000)
|
| 2767 |
-
|
| 2768 |
# Log the prompt/response
|
| 2769 |
-
from prompt_logger import log_researcher_call
|
| 2770 |
log_researcher_call("ddl", researcher, messages, ddl_result or "", duration_ms=_ddl_ms, logger=self._prompt_logger)
|
| 2771 |
-
|
| 2772 |
# Validate DDL result
|
| 2773 |
if not ddl_result or not isinstance(ddl_result, str) or 'CREATE TABLE' not in ddl_result.upper():
|
| 2774 |
raise Exception(f"DDL generation failed or produced invalid output. Result: {ddl_result[:200] if ddl_result else 'None'}")
|
|
|
|
| 2758 |
{"role": "user", "content": schema_prompt}
|
| 2759 |
]
|
| 2760 |
|
| 2761 |
+
# Make request (non-streaming for DDL) — retry once on failure
|
|
|
|
| 2762 |
import time as _time
|
| 2763 |
+
from prompt_logger import log_researcher_call
|
| 2764 |
_ddl_start = _time.time()
|
| 2765 |
+
ddl_result = None
|
| 2766 |
+
for _attempt in range(2):
|
| 2767 |
+
try:
|
| 2768 |
+
if _attempt > 0:
|
| 2769 |
+
self.log_feedback(f"⚠️ DDL attempt {_attempt} failed — retrying...")
|
| 2770 |
+
_time.sleep(5)
|
| 2771 |
+
else:
|
| 2772 |
+
self.log_feedback("Generating DDL...")
|
| 2773 |
+
ddl_result = researcher.make_request(messages, temperature=0.2, max_tokens=4000, stream=False)
|
| 2774 |
+
if ddl_result and isinstance(ddl_result, str) and 'CREATE TABLE' in ddl_result.upper():
|
| 2775 |
+
break # valid DDL received
|
| 2776 |
+
if _attempt == 0:
|
| 2777 |
+
self.log_feedback(f"⚠️ DDL attempt 1 returned empty/invalid output, retrying...")
|
| 2778 |
+
except Exception as _e:
|
| 2779 |
+
if _attempt == 0:
|
| 2780 |
+
self.log_feedback(f"⚠️ DDL attempt 1 raised {type(_e).__name__}: {_e} — retrying...")
|
| 2781 |
+
ddl_result = None
|
| 2782 |
+
else:
|
| 2783 |
+
raise
|
| 2784 |
_ddl_ms = int((_time.time() - _ddl_start) * 1000)
|
| 2785 |
+
|
| 2786 |
# Log the prompt/response
|
|
|
|
| 2787 |
log_researcher_call("ddl", researcher, messages, ddl_result or "", duration_ms=_ddl_ms, logger=self._prompt_logger)
|
| 2788 |
+
|
| 2789 |
# Validate DDL result
|
| 2790 |
if not ddl_result or not isinstance(ddl_result, str) or 'CREATE TABLE' not in ddl_result.upper():
|
| 2791 |
raise Exception(f"DDL generation failed or produced invalid output. Result: {ddl_result[:200] if ddl_result else 'None'}")
|
main_research.py
CHANGED
|
@@ -416,7 +416,7 @@ class MultiLLMResearcher:
|
|
| 416 |
elif provider == "anthropic":
|
| 417 |
import anthropic as _anthropic
|
| 418 |
api_key = api_key or get_anthropic_api_key(required=False)
|
| 419 |
-
self.client = _anthropic.Anthropic(api_key=api_key, timeout=
|
| 420 |
|
| 421 |
elif provider == "google":
|
| 422 |
api_key = api_key or get_google_api_key(required=False)
|
|
@@ -478,7 +478,10 @@ class MultiLLMResearcher:
|
|
| 478 |
return model.generate_content(prompt, generation_config=generation_config, stream=True)
|
| 479 |
|
| 480 |
response = model.generate_content(prompt, generation_config=generation_config)
|
| 481 |
-
|
|
|
|
|
|
|
|
|
|
| 482 |
|
| 483 |
except Exception as e:
|
| 484 |
print(f"{self.provider.upper()} API request failed: {str(e)}")
|
|
|
|
| 416 |
elif provider == "anthropic":
|
| 417 |
import anthropic as _anthropic
|
| 418 |
api_key = api_key or get_anthropic_api_key(required=False)
|
| 419 |
+
self.client = _anthropic.Anthropic(api_key=api_key, timeout=180.0)
|
| 420 |
|
| 421 |
elif provider == "google":
|
| 422 |
api_key = api_key or get_google_api_key(required=False)
|
|
|
|
| 478 |
return model.generate_content(prompt, generation_config=generation_config, stream=True)
|
| 479 |
|
| 480 |
response = model.generate_content(prompt, generation_config=generation_config)
|
| 481 |
+
result = response.text
|
| 482 |
+
if result is None:
|
| 483 |
+
raise ValueError("Google returned None response (possible safety filter block or empty candidates)")
|
| 484 |
+
return result
|
| 485 |
|
| 486 |
except Exception as e:
|
| 487 |
print(f"{self.provider.upper()} API request failed: {str(e)}")
|