|
|
|
@ -50,6 +50,7 @@ class ChatCompleteTask:
|
|
|
|
|
self.chat_complete_service = ChatCompleteService(self.dbs, self.page_title)
|
|
|
|
|
self.chat_complete = await self.chat_complete_service.__aenter__()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if await self.chat_complete.page_index_exists():
|
|
|
|
|
question_tokens = await self.tiktoken.get_tokens(question)
|
|
|
|
|
|
|
|
|
@ -68,8 +69,10 @@ class ChatCompleteTask:
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
else:
|
|
|
|
|
await self._exit()
|
|
|
|
|
raise MediaWikiPageNotFoundException("Page %s not found." % self.page_title)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
await self.end()
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
async def _on_message(self, delta_message: str):
|
|
|
|
|
self.chunks.append(delta_message)
|
|
|
|
@ -122,9 +125,9 @@ class ChatCompleteTask:
|
|
|
|
|
|
|
|
|
|
await self._on_error(e)
|
|
|
|
|
finally:
|
|
|
|
|
await self._exit()
|
|
|
|
|
await self.end()
|
|
|
|
|
|
|
|
|
|
async def _exit(self):
|
|
|
|
|
async def end(self):
|
|
|
|
|
await self.chat_complete_service.__aexit__(None, None, None)
|
|
|
|
|
del chat_complete_tasks[self.task_id]
|
|
|
|
|
self.is_finished = True
|
|
|
|
|