Spaces:
Sleeping
Sleeping
Some more tweaking
Browse filesIncreased timeouts and defaulted to qwen3-coder and openrouter everywhere
- app/config.py +2 -2
- app/services/aipipe_client.py +6 -6
- app/services/github_service.py +10 -42
app/config.py
CHANGED
|
@@ -13,8 +13,8 @@ class Settings(BaseSettings):
|
|
| 13 |
|
| 14 |
# AIpipe / OpenAI-compatible
|
| 15 |
openai_api_key: str | None = Field(None, alias="OPENAI_API_KEY")
|
| 16 |
-
openai_base_url: str = Field("https://aipipe.org/
|
| 17 |
-
aipipe_model: str = Field("qwen/qwen3-coder
|
| 18 |
|
| 19 |
# Pages polling
|
| 20 |
# Pages polling: now internal defaults in app.services.pages.wait_for_200
|
|
|
|
| 13 |
|
| 14 |
# AIpipe / OpenAI-compatible
|
| 15 |
openai_api_key: str | None = Field(None, alias="OPENAI_API_KEY")
|
| 16 |
+
openai_base_url: str = Field("https://aipipe.org/openrouter/v1/chat/completions", alias="OPENAI_BASE_URL")
|
| 17 |
+
aipipe_model: str = Field("qwen/qwen3-coder", alias="AIPIPE_MODEL")
|
| 18 |
|
| 19 |
# Pages polling
|
| 20 |
# Pages polling: now internal defaults in app.services.pages.wait_for_200
|
app/services/aipipe_client.py
CHANGED
|
@@ -18,9 +18,9 @@ class LLMResponse(BaseModel):
|
|
| 18 |
|
| 19 |
class AIpipeClient:
|
| 20 |
def __init__(self, model: str):
|
| 21 |
-
self.model = model if model is not None else "qwen3-coder
|
| 22 |
self.api_key = os.environ.get("OPENAI_API_KEY")
|
| 23 |
-
self.base_url = os.environ.get("OPENAI_BASE_URL", "https://aipipe.org/
|
| 24 |
if not self.api_key:
|
| 25 |
raise RuntimeError("OPENAI_API_KEY (AIpipe token) not set")
|
| 26 |
|
|
@@ -154,10 +154,10 @@ class AIpipeClient:
|
|
| 154 |
print("Starting AIpipe request...")
|
| 155 |
|
| 156 |
timeouts = httpx.Timeout(
|
| 157 |
-
timeout=
|
| 158 |
connect=60.0,
|
| 159 |
-
read=
|
| 160 |
-
write=
|
| 161 |
)
|
| 162 |
async with httpx.AsyncClient(timeout=timeouts) as client:
|
| 163 |
print("Sending request to AIpipe...")
|
|
@@ -295,7 +295,7 @@ class AIpipeClient:
|
|
| 295 |
"temperature": 0.2,
|
| 296 |
}
|
| 297 |
|
| 298 |
-
timeouts = httpx.Timeout(timeout=
|
| 299 |
async with httpx.AsyncClient(timeout=timeouts) as client:
|
| 300 |
resp = await client.post(url, headers=headers, json=payload)
|
| 301 |
resp.raise_for_status()
|
|
|
|
| 18 |
|
| 19 |
class AIpipeClient:
|
| 20 |
def __init__(self, model: str):
|
| 21 |
+
self.model = model if model is not None else "qwen/qwen3-coder"
|
| 22 |
self.api_key = os.environ.get("OPENAI_API_KEY")
|
| 23 |
+
self.base_url = os.environ.get("OPENAI_BASE_URL", "https://aipipe.org/openrouter/v1/chat/completions")
|
| 24 |
if not self.api_key:
|
| 25 |
raise RuntimeError("OPENAI_API_KEY (AIpipe token) not set")
|
| 26 |
|
|
|
|
| 154 |
print("Starting AIpipe request...")
|
| 155 |
|
| 156 |
timeouts = httpx.Timeout(
|
| 157 |
+
timeout=300.0,
|
| 158 |
connect=60.0,
|
| 159 |
+
read=300.0,
|
| 160 |
+
write=120.0
|
| 161 |
)
|
| 162 |
async with httpx.AsyncClient(timeout=timeouts) as client:
|
| 163 |
print("Sending request to AIpipe...")
|
|
|
|
| 295 |
"temperature": 0.2,
|
| 296 |
}
|
| 297 |
|
| 298 |
+
timeouts = httpx.Timeout(timeout=180.0, connect=30.0, read=180.0, write=60.0)
|
| 299 |
async with httpx.AsyncClient(timeout=timeouts) as client:
|
| 300 |
resp = await client.post(url, headers=headers, json=payload)
|
| 301 |
resp.raise_for_status()
|
app/services/github_service.py
CHANGED
|
@@ -107,49 +107,17 @@ SOFTWARE."""
|
|
| 107 |
"Accept": "application/vnd.github.v3+json",
|
| 108 |
"Authorization": f"Bearer {self.token}"
|
| 109 |
}
|
| 110 |
-
import time
|
| 111 |
import httpx
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
)
|
| 123 |
-
# Treat 201/204 as success. 409 can happen if Pages is already configured; not fatal.
|
| 124 |
-
if response.status_code in (201, 204, 409):
|
| 125 |
-
if response.status_code == 409:
|
| 126 |
-
print("GitHub Pages may already be configured (409). Proceeding.")
|
| 127 |
-
else:
|
| 128 |
-
print("Configured GitHub Pages to serve from main branch root")
|
| 129 |
-
last_err = None
|
| 130 |
-
break
|
| 131 |
-
else:
|
| 132 |
-
print(f"Warning: Pages configuration (main) returned status {response.status_code}: {response.text}")
|
| 133 |
-
# Retry only on 5xx server errors
|
| 134 |
-
if 500 <= response.status_code < 600 and attempt < max_attempts:
|
| 135 |
-
time.sleep(backoff)
|
| 136 |
-
backoff = min(backoff * 2, 16)
|
| 137 |
-
continue
|
| 138 |
-
else:
|
| 139 |
-
break
|
| 140 |
-
except httpx.RequestError as e:
|
| 141 |
-
# Network/DNS/connection errors – retry with backoff
|
| 142 |
-
last_err = e
|
| 143 |
-
if attempt < max_attempts:
|
| 144 |
-
print(f"Warning: Pages setup attempt {attempt} failed: {e}. Retrying in {backoff:.0f}s…")
|
| 145 |
-
time.sleep(backoff)
|
| 146 |
-
backoff = min(backoff * 2, 16)
|
| 147 |
-
continue
|
| 148 |
-
else:
|
| 149 |
-
print(f"Warning: Pages setup failed after {max_attempts} attempts: {e}")
|
| 150 |
-
break
|
| 151 |
-
if last_err:
|
| 152 |
-
raise last_err
|
| 153 |
except Exception as e:
|
| 154 |
print(f"Warning: Pages setup encountered an error: {e}")
|
| 155 |
|
|
|
|
| 107 |
"Accept": "application/vnd.github.v3+json",
|
| 108 |
"Authorization": f"Bearer {self.token}"
|
| 109 |
}
|
|
|
|
| 110 |
import httpx
|
| 111 |
+
with httpx.Client() as client:
|
| 112 |
+
response = client.post(
|
| 113 |
+
pages_url,
|
| 114 |
+
json={"source": {"branch": "main", "path": "/"}},
|
| 115 |
+
headers=headers
|
| 116 |
+
)
|
| 117 |
+
if response.status_code not in (201, 204):
|
| 118 |
+
print(f"Warning: Pages configuration (main) returned status {response.status_code}: {response.text}")
|
| 119 |
+
else:
|
| 120 |
+
print("Configured GitHub Pages to serve from main branch root")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
except Exception as e:
|
| 122 |
print(f"Warning: Pages setup encountered an error: {e}")
|
| 123 |
|