mirror of
https://github.com/xtekky/gpt4free.git
synced 2026-04-22 23:57:17 +08:00
Catch import errors
This commit is contained in:
+65
-42
@@ -4,48 +4,71 @@ from ..providers.types import BaseProvider, ProviderType
|
||||
from ..providers.retry_provider import RetryProvider, IterListProvider
|
||||
from ..providers.base_provider import AsyncProvider, AsyncGeneratorProvider
|
||||
from ..providers.create_images import CreateImagesProvider
|
||||
|
||||
from .deprecated import *
|
||||
from .. import debug
|
||||
try:
|
||||
from .deprecated import *
|
||||
except ImportError as e:
|
||||
debug.error("Deprecated providers not loaded:", e)
|
||||
from .needs_auth import *
|
||||
from .not_working import *
|
||||
from .local import *
|
||||
from .hf import HuggingFace, HuggingChat, HuggingFaceAPI, HuggingFaceInference, HuggingFaceMedia
|
||||
from .hf_space import *
|
||||
from .mini_max import HailuoAI, MiniMax
|
||||
from .template import OpenaiTemplate, BackendApi
|
||||
from .hf import HuggingFace, HuggingChat, HuggingFaceAPI, HuggingFaceInference, HuggingFaceMedia
|
||||
try:
|
||||
from .not_working import *
|
||||
except ImportError as e:
|
||||
debug.error("Not working providers not loaded:", e)
|
||||
try:
|
||||
from .local import *
|
||||
except ImportError as e:
|
||||
debug.error("Local providers not loaded:", e)
|
||||
try:
|
||||
from .hf_space import *
|
||||
except ImportError as e:
|
||||
debug.error("HuggingFace Space providers not loaded:", e)
|
||||
try:
|
||||
from .mini_max import HailuoAI, MiniMax
|
||||
except ImportError as e:
|
||||
debug.error("MiniMax providers not loaded:", e)
|
||||
|
||||
from .AllenAI import AllenAI
|
||||
from .ARTA import ARTA
|
||||
from .Blackbox import Blackbox
|
||||
from .ChatGLM import ChatGLM
|
||||
from .ChatGpt import ChatGpt
|
||||
from .ChatGptEs import ChatGptEs
|
||||
from .Cloudflare import Cloudflare
|
||||
from .Copilot import Copilot
|
||||
from .DDG import DDG
|
||||
from .DeepInfraChat import DeepInfraChat
|
||||
from .Dynaspark import Dynaspark
|
||||
from .Free2GPT import Free2GPT
|
||||
from .FreeGpt import FreeGpt
|
||||
from .GizAI import GizAI
|
||||
from .Glider import Glider
|
||||
from .Goabror import Goabror
|
||||
from .ImageLabs import ImageLabs
|
||||
from .Jmuz import Jmuz
|
||||
from .LambdaChat import LambdaChat
|
||||
from .Liaobots import Liaobots
|
||||
from .OIVSCode import OIVSCode
|
||||
from .PerplexityLabs import PerplexityLabs
|
||||
from .Pi import Pi
|
||||
from .Pizzagpt import Pizzagpt
|
||||
from .PollinationsAI import PollinationsAI
|
||||
from .PollinationsImage import PollinationsImage
|
||||
from .TeachAnything import TeachAnything
|
||||
from .TypeGPT import TypeGPT
|
||||
from .You import You
|
||||
from .Websim import Websim
|
||||
from .Yqcloud import Yqcloud
|
||||
|
||||
try:
|
||||
from .AllenAI import AllenAI
|
||||
from .ARTA import ARTA
|
||||
from .Blackbox import Blackbox
|
||||
from .ChatGLM import ChatGLM
|
||||
from .ChatGpt import ChatGpt
|
||||
from .ChatGptEs import ChatGptEs
|
||||
from .Cloudflare import Cloudflare
|
||||
from .Copilot import Copilot
|
||||
from .DDG import DDG
|
||||
from .DeepInfraChat import DeepInfraChat
|
||||
from .Dynaspark import Dynaspark
|
||||
except ImportError as e:
|
||||
debug.error("Providers not loaded (A-D):", e)
|
||||
try:
|
||||
from .Free2GPT import Free2GPT
|
||||
from .FreeGpt import FreeGpt
|
||||
from .GizAI import GizAI
|
||||
from .Glider import Glider
|
||||
from .Goabror import Goabror
|
||||
from .ImageLabs import ImageLabs
|
||||
from .Jmuz import Jmuz
|
||||
from .LambdaChat import LambdaChat
|
||||
from .Liaobots import Liaobots
|
||||
from .OIVSCode import OIVSCode
|
||||
except ImportError as e:
|
||||
debug.error("Providers not loaded (F-L):", e)
|
||||
try:
|
||||
from .PerplexityLabs import PerplexityLabs
|
||||
from .Pi import Pi
|
||||
from .Pizzagpt import Pizzagpt
|
||||
from .PollinationsAI import PollinationsAI
|
||||
from .PollinationsImage import PollinationsImage
|
||||
from .TeachAnything import TeachAnything
|
||||
from .TypeGPT import TypeGPT
|
||||
from .You import You
|
||||
from .Websim import Websim
|
||||
from .Yqcloud import Yqcloud
|
||||
except ImportError as e:
|
||||
debug.error("Providers not loaded (M-Z):", e)
|
||||
|
||||
import sys
|
||||
|
||||
@@ -61,9 +84,9 @@ __providers__: list[ProviderType] = [
|
||||
__all__: list[str] = [
|
||||
provider.__name__ for provider in __providers__
|
||||
]
|
||||
__map__: dict[str, ProviderType] = dict([
|
||||
(provider.__name__, provider) for provider in __providers__
|
||||
])
|
||||
__map__: dict[str, ProviderType] = {
|
||||
provider.__name__: provider for provider in __providers__
|
||||
}
|
||||
|
||||
class ProviderUtils:
|
||||
convert: dict[str, ProviderType] = __map__
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import ssl
|
||||
try:
|
||||
import ssl
|
||||
has_ssl = True
|
||||
except ImportError:
|
||||
has_ssl = False
|
||||
import time
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
@@ -80,19 +84,19 @@ class GigaChat(AsyncGeneratorProvider, ProviderModelMixin):
|
||||
model = cls.get_model(model)
|
||||
if not api_key:
|
||||
raise MissingAuthError('Missing "api_key"')
|
||||
|
||||
|
||||
# Create certificate file in cookies directory
|
||||
cookies_dir = Path(get_cookies_dir())
|
||||
cert_file = cookies_dir / 'russian_trusted_root_ca.crt'
|
||||
|
||||
|
||||
# Write certificate if it doesn't exist
|
||||
if not cert_file.exists():
|
||||
cert_file.write_text(RUSSIAN_CA_CERT)
|
||||
|
||||
ssl_context = ssl.create_default_context(cafile=str(cert_file))
|
||||
if connector is None:
|
||||
|
||||
if has_ssl and connector is None:
|
||||
ssl_context = ssl.create_default_context(cafile=str(cert_file))
|
||||
connector = TCPConnector(ssl_context=ssl_context)
|
||||
|
||||
|
||||
async with ClientSession(connector=get_connector(connector, proxy)) as session:
|
||||
if token_expires_at - int(time.time() * 1000) < 60000:
|
||||
async with session.post(url="https://ngw.devices.sberbank.ru:9443/api/v2/oauth",
|
||||
|
||||
+5
-8
@@ -1,21 +1,18 @@
|
||||
import sys
|
||||
from typing import Callable, List, Optional, Any
|
||||
|
||||
# Warning: name could conflict with Python's built-in logging module
|
||||
logging: bool = False
|
||||
version_check: bool = True
|
||||
version: Optional[str] = None
|
||||
log_handler: Callable = print # More specifically: Callable[[Any, Optional[Any]], None]
|
||||
logs: List[str] = []
|
||||
|
||||
def log(text: Any, file: Optional[Any] = None) -> None:
|
||||
def log(*text: Any, file: Optional[Any] = None) -> None:
|
||||
"""Log a message if logging is enabled."""
|
||||
if logging:
|
||||
log_handler(text, file=file)
|
||||
log_handler(*text, file=file)
|
||||
|
||||
def error(error: Any, name: Optional[str] = None) -> None:
|
||||
def error(*error: Any, name: Optional[str] = None) -> None:
|
||||
"""Log an error message to stderr."""
|
||||
log(
|
||||
error if isinstance(error, str) else f"{type(error).__name__ if name is None else name}: {error}",
|
||||
file=sys.stderr
|
||||
)
|
||||
error = [e if isinstance(e, str) else f"{type(e).__name__ if name is None else name}: {e}" for e in error]
|
||||
log(*error, file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user