summaryrefslogtreecommitdiffstats
path: root/g4f/client/helper.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/client/helper.py')
-rw-r--r--g4f/client/helper.py30
1 files changed, 0 insertions, 30 deletions
diff --git a/g4f/client/helper.py b/g4f/client/helper.py
index 93588c07..909cc132 100644
--- a/g4f/client/helper.py
+++ b/g4f/client/helper.py
@@ -1,10 +1,7 @@
from __future__ import annotations
import re
-import queue
-import threading
import logging
-import asyncio
from typing import AsyncIterator, Iterator, AsyncGenerator, Optional
@@ -53,33 +50,6 @@ async def safe_aclose(generator: AsyncGenerator) -> None:
except Exception as e:
logging.warning(f"Error while closing generator: {e}")
-# Helper function to convert an async generator to a synchronous iterator
-def to_sync_iter(async_gen: AsyncIterator) -> Iterator:
- q = queue.Queue()
- loop = asyncio.new_event_loop()
- done = object()
-
- def _run():
- asyncio.set_event_loop(loop)
-
- async def iterate():
- try:
- async for item in async_gen:
- q.put(item)
- finally:
- q.put(done)
-
- loop.run_until_complete(iterate())
- loop.close()
-
- threading.Thread(target=_run).start()
-
- while True:
- item = q.get()
- if item is done:
- break
- yield item
-
# Helper function to convert a synchronous iterator to an async iterator
async def to_async_iterator(iterator: Iterator) -> AsyncIterator:
for item in iterator: