mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-09-26 20:31:14 +08:00
Add BrowserConfig initialization in cookies.py and ensure directory creation in SharedTokenManager
This commit is contained in:
@@ -196,6 +196,7 @@ class SharedTokenManager(AuthFileMixin):
|
||||
max_attempts = 50
|
||||
attempt_interval = 200 # ms
|
||||
lock_id = str(uuid.uuid4())
|
||||
os.makedirs(lock_path.parent, exist_ok=True)
|
||||
|
||||
for _ in range(max_attempts):
|
||||
try:
|
||||
|
@@ -71,7 +71,6 @@ from g4f.providers.types import ProviderType
|
||||
from g4f.providers.response import AudioResponse
|
||||
from g4f.providers.any_provider import AnyProvider
|
||||
from g4f.providers.any_model_map import model_map, vision_models, image_models, audio_models, video_models
|
||||
from g4f.requests import BrowserConfig
|
||||
from g4f import Provider
|
||||
from g4f.gui import get_gui_app
|
||||
from .stubs import (
|
||||
@@ -103,11 +102,6 @@ async def lifespan(app: FastAPI):
|
||||
AppConfig.g4f_api_key = os.environ.get("G4F_API_KEY", AppConfig.g4f_api_key)
|
||||
AppConfig.timeout = os.environ.get("G4F_TIMEOUT", AppConfig.timeout)
|
||||
AppConfig.stream_timeout = os.environ.get("G4F_STREAM_TIMEOUT", AppConfig.stream_timeout)
|
||||
BrowserConfig.port = os.environ.get("G4F_BROWSER_PORT", BrowserConfig.port)
|
||||
BrowserConfig.host = os.environ.get("G4F_BROWSER_HOST", BrowserConfig.host)
|
||||
if BrowserConfig.port:
|
||||
BrowserConfig.port = int(BrowserConfig.port)
|
||||
print(f"Using browser: {BrowserConfig.host}:{BrowserConfig.port}")
|
||||
yield
|
||||
if has_nodriver:
|
||||
for browser in util.get_registered_instances():
|
||||
|
@@ -40,6 +40,7 @@ except ImportError:
|
||||
|
||||
from .typing import Dict, Cookies
|
||||
from .errors import MissingRequirementsError
|
||||
from .requests import BrowserConfig
|
||||
from .config import COOKIES_DIR, CUSTOM_COOKIES_DIR
|
||||
from . import debug
|
||||
|
||||
@@ -184,6 +185,12 @@ def read_cookie_files(dir_path: Optional[str] = None, domains_filter: Optional[L
|
||||
except ImportError:
|
||||
debug.error("Warning: 'python-dotenv' is not installed. Env vars not loaded.")
|
||||
|
||||
BrowserConfig.port = os.environ.get("G4F_BROWSER_PORT", BrowserConfig.port)
|
||||
BrowserConfig.host = os.environ.get("G4F_BROWSER_HOST", BrowserConfig.host)
|
||||
if BrowserConfig.port:
|
||||
BrowserConfig.port = int(BrowserConfig.port)
|
||||
debug.log(f"Using browser: {BrowserConfig.host}:{BrowserConfig.port}")
|
||||
|
||||
har_files, json_files = [], []
|
||||
for root, _, files in os.walk(dir_path):
|
||||
for file in files:
|
||||
|
Reference in New Issue
Block a user