purpose-agent / apply_llm_timeout.py
Rohan03's picture
Add critical fix: apply_llm_timeout.py patches OpenAI backend with 60s timeout
364c214 verified
raw
history blame
1.25 kB
#!/usr/bin/env python3
"""Apply the OpenAI backend timeout fix directly."""
import os
path = os.path.join(os.path.dirname(__file__), "purpose_agent", "llm_backend.py")
with open(path, "r") as f:
content = f.read()
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 )'
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 )'
if old in content:
content = content.replace(old, new, 1)
with open(path, "w") as f:
f.write(content)
print("✅ Applied OpenAI backend timeout fix (60s)")
else:
print("⚠️ Pattern not found — may already be patched")