diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-11-21 14:05:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-21 14:05:50 +0100 |
commit | e4bfd9db5cb6f8cc3c562519633eff2018236240 (patch) | |
tree | 647aef84b6705f51a110e79d401b7a2a1871b92b /g4f/gui | |
parent | Merge pull request #2396 from hlohaus/open (diff) | |
download | gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar.gz gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar.bz2 gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar.lz gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar.xz gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.tar.zst gpt4free-e4bfd9db5cb6f8cc3c562519633eff2018236240.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/gui/server/backend.py | 19 |
1 files changed, 2 insertions, 17 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index fe020bb8..102c5685 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -1,13 +1,13 @@ import json -import asyncio import flask import os from flask import request, Flask -from typing import AsyncGenerator, Generator +from typing import Generator from werkzeug.utils import secure_filename from g4f.image import is_allowed_extension, to_image from g4f.client.service import convert_to_provider +from g4f.providers.asyncio import to_sync_generator from g4f.errors import ProviderNotFoundError from g4f.cookies import get_cookies_dir from .api import Api @@ -19,21 +19,6 @@ def safe_iter_generator(generator: Generator) -> Generator: yield from generator return iter_generator() -def to_sync_generator(gen: AsyncGenerator) -> Generator: - loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - gen = gen.__aiter__() - async def get_next(): - try: - obj = await gen.__anext__() - return False, obj - except StopAsyncIteration: return True, None - while True: - done, obj = loop.run_until_complete(get_next()) - if done: - break - yield obj - class Backend_Api(Api): """ Handles various endpoints in a Flask application for backend operations. |