From f89fa7517654523024fe2eaed29d32b9f4189d79 Mon Sep 17 00:00:00 2001 From: Ramon Victor Cardoso Date: Tue, 27 Jun 2023 13:30:18 -0300 Subject: Fix: There is no current event loop in thread. --- g4f/Provider/Providers/Bing.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/g4f/Provider/Providers/Bing.py b/g4f/Provider/Providers/Bing.py index 1d33cda5..2ec2cf05 100644 --- a/g4f/Provider/Providers/Bing.py +++ b/g4f/Provider/Providers/Bing.py @@ -304,19 +304,20 @@ async def stream_generate(prompt: str, mode: optionsSets.optionSet = optionsSets await session.close() -def run(generator): - loop = asyncio.get_event_loop() - gen = generator.__aiter__() +def run(generator): + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + gen = generator.__aiter__() + + while True: + try: + next_val = loop.run_until_complete(gen.__anext__()) + yield next_val + + except StopAsyncIteration: + break + #print('Done') - while True: - try: - next_val = loop.run_until_complete(gen.__anext__()) - yield next_val - - except StopAsyncIteration: - break - - #print('Done') def convert(messages): -- cgit v1.2.3