Add critical fix: apply_llm_timeout.py patches OpenAI backend with 60s timeout
Browse files- apply_llm_timeout.py +15 -0
apply_llm_timeout.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Apply the OpenAI backend timeout fix directly."""
|
| 3 |
+
import os
|
| 4 |
+
path = os.path.join(os.path.dirname(__file__), "purpose_agent", "llm_backend.py")
|
| 5 |
+
with open(path, "r") as f:
|
| 6 |
+
content = f.read()
|
| 7 |
+
old = ' def __init__(\n self,\n model: str = "gpt-4o",\n base_url: str | None = None,\n api_key: str | None = None,\n ):\n from openai import OpenAI\n\n self.model = model\n self.client = OpenAI(\n base_url=base_url,\n api_key=api_key or os.environ.get("OPENAI_API_KEY"),\n )'
|
| 8 |
+
new = ' def __init__(\n self,\n model: str = "gpt-4o",\n base_url: str | None = None,\n api_key: str | None = None,\n timeout: float = 60.0,\n ):\n from openai import OpenAI\n\n self.model = model\n self.client = OpenAI(\n base_url=base_url,\n api_key=api_key or os.environ.get("OPENAI_API_KEY"),\n timeout=timeout,\n )'
|
| 9 |
+
if old in content:
|
| 10 |
+
content = content.replace(old, new, 1)
|
| 11 |
+
with open(path, "w") as f:
|
| 12 |
+
f.write(content)
|
| 13 |
+
print("✅ Applied OpenAI backend timeout fix (60s)")
|
| 14 |
+
else:
|
| 15 |
+
print("⚠️ Pattern not found — may already be patched")
|