XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

Fix unittests (#1472)

* Fix unittests * Fix missing distutils, install setuptools * Fix version not found * Remove deprecation in get_event_loop

42709f55
H Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

6 个文件 +16 -14
Modified .github/workflows/unittest.yml +2 -2
@@ -14,6 +14,6 @@ jobs:
14 14 python-version: "3.x"
15 15 cache: 'pip'
16 16 - name: Install requirements
17 - run: pip install -r requirements.txt
17 run: pip install -r requirements.txt
18 18 - name: Run tests
19 - run: python -m etc.unittest.main
19 run: python -m etc.unittest.main
Modified etc/unittest/main.py +1 -0
@@ -11,6 +11,7 @@ from g4f.gui.server.backend import Backend_Api, get_error_message
11 11 from g4f.base_provider import BaseProvider
12 12
13 13 g4f.debug.logging = False
14 g4f.debug.version_check = False
14 15
15 16 class MockProvider(BaseProvider):
16 17 working = True
Modified g4f/Provider/helper.py +4 -10
@@ -5,7 +5,7 @@ import os
5 5 import random
6 6 import secrets
7 7 import string
8 from asyncio import AbstractEventLoop, BaseEventLoop
8 from asyncio import AbstractEventLoop
9 9 from platformdirs import user_config_dir
10 10 from browser_cookie3 import (
11 11 chrome, chromium, opera, opera_gx,
@@ -27,19 +27,13 @@ def get_event_loop() -> AbstractEventLoop:
27 27 AbstractEventLoop: The current or new event loop.
28 28 """
29 29 try:
30 loop = asyncio.get_event_loop()
31 if isinstance(loop, BaseEventLoop):
32 loop._check_closed()
33 except RuntimeError:
34 loop = asyncio.new_event_loop()
35 asyncio.set_event_loop(loop)
36 try:
37 asyncio.get_running_loop()
30 loop = asyncio.get_running_loop()
38 31 if not hasattr(loop.__class__, "_nest_patched"):
39 32 import nest_asyncio
40 33 nest_asyncio.apply(loop)
41 34 except RuntimeError:
42 pass
35 loop = asyncio.new_event_loop()
36 asyncio.set_event_loop(loop)
43 37 except ImportError:
44 38 raise RuntimeError(
45 39 'Use "create_async" instead of "create" function in a running event loop. Or install "nest_asyncio" package.'
Modified g4f/gui/server/backend.py +6 -1
@@ -5,6 +5,7 @@ from typing import Generator
5 5 from g4f import debug, version, models
6 6 from g4f import _all_models, get_last_provider, ChatCompletion
7 7 from g4f.image import is_allowed_extension, to_image
8 from g4f.errors import VersionNotFoundError
8 9 from g4f.Provider import __providers__
9 10 from g4f.Provider.bing.create_images import patch_provider
10 11 from .internet import get_search_message
@@ -91,8 +92,12 @@ class Backend_Api:
91 92 Returns:
92 93 dict: A dictionary containing the current and latest version.
93 94 """
95 try:
96 current_version = version.utils.current_version
97 except VersionNotFoundError:
98 current_version = None
94 99 return {
95 "version": version.utils.current_version,
100 "version": current_version,
96 101 "latest_version": version.get_latest_version(),
97 102 }
98 103
Modified requirements.txt +2 -1
@@ -20,4 +20,5 @@ asyncstdlib
20 20 async-property
21 21 undetected-chromedriver
22 22 brotli
23 beautifulsoup4
23 beautifulsoup4
24 setuptools
Modified setup.py +1 -0
@@ -32,6 +32,7 @@ install_requires = [
32 32 "undetected-chromedriver",
33 33 "brotli",
34 34 "beautifulsoup4",
35 "setuptools",
35 36 ]
36 37
37 38 DESCRIPTION = (