Closed hemangsrr closed 1 year ago
For now I managed to fix it with the following changes to my code
async def BardResponse(sorted_data):
global bard
token = <My-Token>
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
future_bard = loop.run_in_executor(None, create_chatbot, token)
# Wait for the future to complete and get the Chatbot instance
bard = await future_bard
bard_data = []
print(sorted_data)
for data in sorted_data:
print("Data passed to Bard --------------------------")
print(data["sentence"])
Answer = bard.ask('Summarize this: ' + data["sentence"])
response = Answer["content"]
bard_data.append({'response': response})
return bard_data
and changed the function where this was being called to async as well
and added the following to the call
await BardResponse(sorted_data)
to make this work with flask, i also had to reinstall Flask with the 'async' extra
I'm leaving this here as reference in case anyone else comes across a similar issue
from Bard import AsyncChatbot
async def BardResponse(sorted_data):
token = <My-Token>
bard = await AsyncChatbot(token)
bard_data = []
print(sorted_data)
for data in sorted_data:
print("Data passed to Bard --------------------------")
print(data["sentence"])
Answer = await bard.ask('Summarize this: ' + data["sentence"])
response = Answer["content"]
bard_data.append({'response': response})
return bard_data
That will definitely make my code cleaner and avoid unnecessary async loop creation. I'll try it out
I am getting the following error when calling Bard
RuntimeError: There is no current event loop in thread 'Thread-77 (process_request_thread)'.
This was working until a couple days ago, and then I'm getting this error