File size: 1,249 Bytes
364c214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/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")