mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
fix: optimize browser memory
This commit is contained in:
@@ -15,7 +15,7 @@ import threading
|
|||||||
from typing import Optional, Dict, Any, List, Callable
|
from typing import Optional, Dict, Any, List, Callable
|
||||||
|
|
||||||
from common.log import logger
|
from common.log import logger
|
||||||
from common.utils import expand_path
|
from common.utils import expand_path, is_cloud_deployment
|
||||||
|
|
||||||
|
|
||||||
_DEFAULT_USER_DATA_DIR = "~/.cow/browser_profile"
|
_DEFAULT_USER_DATA_DIR = "~/.cow/browser_profile"
|
||||||
@@ -436,6 +436,20 @@ class BrowserService:
|
|||||||
if self._headless:
|
if self._headless:
|
||||||
launch_args.append("--no-sandbox")
|
launch_args.append("--no-sandbox")
|
||||||
|
|
||||||
|
if is_cloud_deployment():
|
||||||
|
launch_args.extend([
|
||||||
|
"--disable-gpu",
|
||||||
|
"--disable-software-rasterizer",
|
||||||
|
"--disable-extensions",
|
||||||
|
"--disable-background-networking",
|
||||||
|
"--disable-background-timer-throttling",
|
||||||
|
"--disable-renderer-backgrounding",
|
||||||
|
"--disable-features=site-per-process,TranslateUI,IsolateOrigins",
|
||||||
|
"--no-zygote",
|
||||||
|
"--js-flags=--max-old-space-size=384",
|
||||||
|
"--memory-pressure-off",
|
||||||
|
])
|
||||||
|
|
||||||
extra_args = self._config.get("launch_args", [])
|
extra_args = self._config.get("launch_args", [])
|
||||||
if extra_args:
|
if extra_args:
|
||||||
launch_args.extend(extra_args)
|
launch_args.extend(extra_args)
|
||||||
|
|||||||
@@ -117,6 +117,18 @@ def expand_path(path: str) -> str:
|
|||||||
return expanded
|
return expanded
|
||||||
|
|
||||||
|
|
||||||
|
def is_cloud_deployment() -> bool:
|
||||||
|
if os.environ.get("CLOUD_DEPLOYMENT_ID"):
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
from config import conf
|
||||||
|
if conf().get("cloud_deployment_id"):
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_cloud_headers(api_key: str) -> dict:
|
def get_cloud_headers(api_key: str) -> dict:
|
||||||
"""
|
"""
|
||||||
Build standard headers for LinkAI API requests,
|
Build standard headers for LinkAI API requests,
|
||||||
|
|||||||
Reference in New Issue
Block a user