HouYunFei Codex commited on
Commit ·
f50bbcc
1
Parent(s): 2dd0d2e
Add configurable image poll timeout
Browse filesCo-Authored-By: Codex <noreply@openai.com>
- config.json +1 -0
- services/config.py +8 -0
- services/openai_backend_api.py +2 -1
- web/src/app/settings/components/config-card.tsx +11 -0
- web/src/app/settings/store.ts +7 -0
- web/src/lib/api.ts +1 -0
config.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
"auth-key": "chatgpt2api",
|
| 3 |
"refresh_account_interval_minute": 60,
|
| 4 |
"image_retention_days": 15,
|
|
|
|
| 5 |
"auto_remove_rate_limited_accounts": false,
|
| 6 |
"auto_remove_invalid_accounts": true,
|
| 7 |
"log_levels": [
|
|
|
|
| 2 |
"auth-key": "chatgpt2api",
|
| 3 |
"refresh_account_interval_minute": 60,
|
| 4 |
"image_retention_days": 15,
|
| 5 |
+
"image_poll_timeout_secs": 120,
|
| 6 |
"auto_remove_rate_limited_accounts": false,
|
| 7 |
"auto_remove_invalid_accounts": true,
|
| 8 |
"log_levels": [
|
services/config.py
CHANGED
|
@@ -110,6 +110,13 @@ class ConfigStore:
|
|
| 110 |
except (TypeError, ValueError):
|
| 111 |
return 30
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
@property
|
| 114 |
def auto_remove_invalid_accounts(self) -> bool:
|
| 115 |
value = self.data.get("auto_remove_invalid_accounts", False)
|
|
@@ -188,6 +195,7 @@ class ConfigStore:
|
|
| 188 |
data = dict(self.data)
|
| 189 |
data["refresh_account_interval_minute"] = self.refresh_account_interval_minute
|
| 190 |
data["image_retention_days"] = self.image_retention_days
|
|
|
|
| 191 |
data["auto_remove_invalid_accounts"] = self.auto_remove_invalid_accounts
|
| 192 |
data["auto_remove_rate_limited_accounts"] = self.auto_remove_rate_limited_accounts
|
| 193 |
data["log_levels"] = self.log_levels
|
|
|
|
| 110 |
except (TypeError, ValueError):
|
| 111 |
return 30
|
| 112 |
|
| 113 |
+
@property
|
| 114 |
+
def image_poll_timeout_secs(self) -> int:
|
| 115 |
+
try:
|
| 116 |
+
return max(1, int(self.data.get("image_poll_timeout_secs", 120)))
|
| 117 |
+
except (TypeError, ValueError):
|
| 118 |
+
return 120
|
| 119 |
+
|
| 120 |
@property
|
| 121 |
def auto_remove_invalid_accounts(self) -> bool:
|
| 122 |
value = self.data.get("auto_remove_invalid_accounts", False)
|
|
|
|
| 195 |
data = dict(self.data)
|
| 196 |
data["refresh_account_interval_minute"] = self.refresh_account_interval_minute
|
| 197 |
data["image_retention_days"] = self.image_retention_days
|
| 198 |
+
data["image_poll_timeout_secs"] = self.image_poll_timeout_secs
|
| 199 |
data["auto_remove_invalid_accounts"] = self.auto_remove_invalid_accounts
|
| 200 |
data["auto_remove_rate_limited_accounts"] = self.auto_remove_rate_limited_accounts
|
| 201 |
data["log_levels"] = self.log_levels
|
services/openai_backend_api.py
CHANGED
|
@@ -11,6 +11,7 @@ from curl_cffi import requests
|
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
from services.account_service import account_service
|
|
|
|
| 14 |
from services.proxy_service import proxy_settings
|
| 15 |
from utils.helper import ensure_ok, iter_sse_payloads, new_uuid
|
| 16 |
from utils.log import logger
|
|
@@ -674,7 +675,7 @@ class OpenAIBackendAPI:
|
|
| 674 |
sediment_ids = list(sediment_ids)
|
| 675 |
if poll and conversation_id and not file_ids and not sediment_ids:
|
| 676 |
logger.info({"event": "image_resolve_poll_needed", "conversation_id": conversation_id})
|
| 677 |
-
polled_file_ids, polled_sediment_ids = self._poll_image_results(conversation_id)
|
| 678 |
file_ids.extend(item for item in polled_file_ids if item and item not in file_ids)
|
| 679 |
sediment_ids.extend(item for item in polled_sediment_ids if item and item not in sediment_ids)
|
| 680 |
return self._resolve_image_urls(conversation_id, file_ids, sediment_ids)
|
|
|
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
from services.account_service import account_service
|
| 14 |
+
from services.config import config
|
| 15 |
from services.proxy_service import proxy_settings
|
| 16 |
from utils.helper import ensure_ok, iter_sse_payloads, new_uuid
|
| 17 |
from utils.log import logger
|
|
|
|
| 675 |
sediment_ids = list(sediment_ids)
|
| 676 |
if poll and conversation_id and not file_ids and not sediment_ids:
|
| 677 |
logger.info({"event": "image_resolve_poll_needed", "conversation_id": conversation_id})
|
| 678 |
+
polled_file_ids, polled_sediment_ids = self._poll_image_results(conversation_id, config.image_poll_timeout_secs)
|
| 679 |
file_ids.extend(item for item in polled_file_ids if item and item not in file_ids)
|
| 680 |
sediment_ids.extend(item for item in polled_sediment_ids if item and item not in sediment_ids)
|
| 681 |
return self._resolve_image_urls(conversation_id, file_ids, sediment_ids)
|
web/src/app/settings/components/config-card.tsx
CHANGED
|
@@ -22,6 +22,7 @@ export function ConfigCard() {
|
|
| 22 |
const isSavingConfig = useSettingsStore((state) => state.isSavingConfig);
|
| 23 |
const setRefreshAccountIntervalMinute = useSettingsStore((state) => state.setRefreshAccountIntervalMinute);
|
| 24 |
const setImageRetentionDays = useSettingsStore((state) => state.setImageRetentionDays);
|
|
|
|
| 25 |
const setAutoRemoveInvalidAccounts = useSettingsStore((state) => state.setAutoRemoveInvalidAccounts);
|
| 26 |
const setAutoRemoveRateLimitedAccounts = useSettingsStore((state) => state.setAutoRemoveRateLimitedAccounts);
|
| 27 |
const setLogLevel = useSettingsStore((state) => state.setLogLevel);
|
|
@@ -139,6 +140,16 @@ export function ConfigCard() {
|
|
| 139 |
/>
|
| 140 |
<p className="text-xs text-stone-500">自动删除多少天前的本地图片。</p>
|
| 141 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
<label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700">
|
| 143 |
<Checkbox
|
| 144 |
checked={Boolean(config?.auto_remove_invalid_accounts)}
|
|
|
|
| 22 |
const isSavingConfig = useSettingsStore((state) => state.isSavingConfig);
|
| 23 |
const setRefreshAccountIntervalMinute = useSettingsStore((state) => state.setRefreshAccountIntervalMinute);
|
| 24 |
const setImageRetentionDays = useSettingsStore((state) => state.setImageRetentionDays);
|
| 25 |
+
const setImagePollTimeoutSecs = useSettingsStore((state) => state.setImagePollTimeoutSecs);
|
| 26 |
const setAutoRemoveInvalidAccounts = useSettingsStore((state) => state.setAutoRemoveInvalidAccounts);
|
| 27 |
const setAutoRemoveRateLimitedAccounts = useSettingsStore((state) => state.setAutoRemoveRateLimitedAccounts);
|
| 28 |
const setLogLevel = useSettingsStore((state) => state.setLogLevel);
|
|
|
|
| 140 |
/>
|
| 141 |
<p className="text-xs text-stone-500">自动删除多少天前的本地图片。</p>
|
| 142 |
</div>
|
| 143 |
+
<div className="space-y-2">
|
| 144 |
+
<label className="text-sm text-stone-700">图片轮询超时</label>
|
| 145 |
+
<Input
|
| 146 |
+
value={String(config?.image_poll_timeout_secs || "")}
|
| 147 |
+
onChange={(event) => setImagePollTimeoutSecs(event.target.value)}
|
| 148 |
+
placeholder="120"
|
| 149 |
+
className="h-10 rounded-xl border-stone-200 bg-white"
|
| 150 |
+
/>
|
| 151 |
+
<p className="text-xs text-stone-500">单位秒,等待上游图片结果的最长时间。</p>
|
| 152 |
+
</div>
|
| 153 |
<label className="flex items-center gap-3 rounded-xl border border-stone-200 bg-white px-4 py-3 text-sm text-stone-700">
|
| 154 |
<Checkbox
|
| 155 |
checked={Boolean(config?.auto_remove_invalid_accounts)}
|
web/src/app/settings/store.ts
CHANGED
|
@@ -32,6 +32,7 @@ function normalizeConfig(config: SettingsConfig): SettingsConfig {
|
|
| 32 |
...config,
|
| 33 |
refresh_account_interval_minute: Number(config.refresh_account_interval_minute || 5),
|
| 34 |
image_retention_days: Number(config.image_retention_days || 30),
|
|
|
|
| 35 |
auto_remove_invalid_accounts: Boolean(config.auto_remove_invalid_accounts),
|
| 36 |
auto_remove_rate_limited_accounts: Boolean(config.auto_remove_rate_limited_accounts),
|
| 37 |
log_levels: Array.isArray(config.log_levels) ? config.log_levels : [],
|
|
@@ -101,6 +102,7 @@ type SettingsStore = {
|
|
| 101 |
saveConfig: () => Promise<void>;
|
| 102 |
setRefreshAccountIntervalMinute: (value: string) => void;
|
| 103 |
setImageRetentionDays: (value: string) => void;
|
|
|
|
| 104 |
setAutoRemoveInvalidAccounts: (value: boolean) => void;
|
| 105 |
setAutoRemoveRateLimitedAccounts: (value: boolean) => void;
|
| 106 |
setLogLevel: (level: string, enabled: boolean) => void;
|
|
@@ -208,6 +210,7 @@ export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
|
| 208 |
...config,
|
| 209 |
refresh_account_interval_minute: Math.max(1, Number(config.refresh_account_interval_minute) || 1),
|
| 210 |
image_retention_days: Math.max(1, Number(config.image_retention_days) || 30),
|
|
|
|
| 211 |
auto_remove_invalid_accounts: Boolean(config.auto_remove_invalid_accounts),
|
| 212 |
auto_remove_rate_limited_accounts: Boolean(config.auto_remove_rate_limited_accounts),
|
| 213 |
proxy: config.proxy.trim(),
|
|
@@ -250,6 +253,10 @@ export const useSettingsStore = create<SettingsStore>((set, get) => ({
|
|
| 250 |
set((state) => state.config ? { config: { ...state.config, image_retention_days: value } } : {});
|
| 251 |
},
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
setAutoRemoveInvalidAccounts: (value) => {
|
| 254 |
set((state) => state.config ? { config: { ...state.config, auto_remove_invalid_accounts: value } } : {});
|
| 255 |
},
|
|
|
|
| 32 |
...config,
|
| 33 |
refresh_account_interval_minute: Number(config.refresh_account_interval_minute || 5),
|
| 34 |
image_retention_days: Number(config.image_retention_days || 30),
|
| 35 |
+
image_poll_timeout_secs: Number(config.image_poll_timeout_secs || 120),
|
| 36 |
auto_remove_invalid_accounts: Boolean(config.auto_remove_invalid_accounts),
|
| 37 |
auto_remove_rate_limited_accounts: Boolean(config.auto_remove_rate_limited_accounts),
|
| 38 |
log_levels: Array.isArray(config.log_levels) ? config.log_levels : [],
|
|
|
|
| 102 |
saveConfig: () => Promise<void>;
|
| 103 |
setRefreshAccountIntervalMinute: (value: string) => void;
|
| 104 |
setImageRetentionDays: (value: string) => void;
|
| 105 |
+
setImagePollTimeoutSecs: (value: string) => void;
|
| 106 |
setAutoRemoveInvalidAccounts: (value: boolean) => void;
|
| 107 |
setAutoRemoveRateLimitedAccounts: (value: boolean) => void;
|
| 108 |
setLogLevel: (level: string, enabled: boolean) => void;
|
|
|
|
| 210 |
...config,
|
| 211 |
refresh_account_interval_minute: Math.max(1, Number(config.refresh_account_interval_minute) || 1),
|
| 212 |
image_retention_days: Math.max(1, Number(config.image_retention_days) || 30),
|
| 213 |
+
image_poll_timeout_secs: Math.max(1, Number(config.image_poll_timeout_secs) || 120),
|
| 214 |
auto_remove_invalid_accounts: Boolean(config.auto_remove_invalid_accounts),
|
| 215 |
auto_remove_rate_limited_accounts: Boolean(config.auto_remove_rate_limited_accounts),
|
| 216 |
proxy: config.proxy.trim(),
|
|
|
|
| 253 |
set((state) => state.config ? { config: { ...state.config, image_retention_days: value } } : {});
|
| 254 |
},
|
| 255 |
|
| 256 |
+
setImagePollTimeoutSecs: (value) => {
|
| 257 |
+
set((state) => state.config ? { config: { ...state.config, image_poll_timeout_secs: value } } : {});
|
| 258 |
+
},
|
| 259 |
+
|
| 260 |
setAutoRemoveInvalidAccounts: (value) => {
|
| 261 |
set((state) => state.config ? { config: { ...state.config, auto_remove_invalid_accounts: value } } : {});
|
| 262 |
},
|
web/src/lib/api.ts
CHANGED
|
@@ -63,6 +63,7 @@ export type SettingsConfig = {
|
|
| 63 |
};
|
| 64 |
refresh_account_interval_minute?: number | string;
|
| 65 |
image_retention_days?: number | string;
|
|
|
|
| 66 |
auto_remove_invalid_accounts?: boolean;
|
| 67 |
auto_remove_rate_limited_accounts?: boolean;
|
| 68 |
log_levels?: string[];
|
|
|
|
| 63 |
};
|
| 64 |
refresh_account_interval_minute?: number | string;
|
| 65 |
image_retention_days?: number | string;
|
| 66 |
+
image_poll_timeout_secs?: number | string;
|
| 67 |
auto_remove_invalid_accounts?: boolean;
|
| 68 |
auto_remove_rate_limited_accounts?: boolean;
|
| 69 |
log_levels?: string[];
|