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

XFEstudio/gpt4free

Refactor ApiAirforce class to enhance async generator and improve rate limit handling; update setup.py dependencies

867b3e8c
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +32 -6
Modified g4f/Provider/ApiAirforce.py +28 -2
@@ -1,7 +1,8 @@
1 1 from __future__ import annotations
2 2
3 from ..typing import Messages, AsyncResult
3 4 from .template import OpenaiTemplate
4 from ..config import DEFAULT_MODEL
5 from ..errors import RateLimitError
5 6
6 7 class ApiAirforce(OpenaiTemplate):
7 8 label = "Api.Airforce"
@@ -10,4 +11,29 @@ class ApiAirforce(OpenaiTemplate):
10 11 api_base = "https://api.airforce/v1"
11 12 working = True
12 13 active_by_default = True
13 use_image_size = True
14 use_image_size = True
15
16 @classmethod
17 async def create_async_generator(
18 cls,
19 model: str,
20 messages: Messages = None,
21 **kwargs
22 ) -> AsyncResult:
23 ratelimit_message = "Ratelimit Exceeded!"
24 buffer = ""
25 async for chunk in super().create_async_generator(
26 model=model,
27 messages=messages,
28 **kwargs
29 ):
30 if not isinstance(chunk, str):
31 yield chunk
32 continue
33 buffer += chunk
34 if ratelimit_message in buffer:
35 raise RateLimitError(ratelimit_message)
36 if ratelimit_message.startswith(buffer):
37 continue
38 yield buffer
39 buffer = ""
Modified setup.py +4 -4
@@ -34,8 +34,6 @@ EXTRA_REQUIRE = {
34 34 "nodriver",
35 35 "python-multipart",
36 36 "a2wsgi",
37 "pywebview",
38 "plyer",
39 37 "setuptools",
40 38 "markitdown[all]",
41 39 "python-dotenv",
@@ -52,10 +50,12 @@ EXTRA_REQUIRE = {
52 50 "werkzeug", "flask", # gui
53 51 "fastapi", # api
54 52 "uvicorn", # api
53 "nodriver",
55 54 "python-multipart",
56 55 "a2wsgi",
57 "markitdown[all]",
58 "python-dotenv"
56 "markitdown[docx,pdf,pptx]",
57 "python-dotenv",
58 "aiofile"
59 59 ],
60 60 "image": [
61 61 "pillow",