From abf1ce6d6cb6e25e915599a298623188c7a227b9 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Sat, 21 Oct 2023 23:30:49 +0800 Subject: [PATCH] fix bug --- bot_db.py | 11 +++++------ bot_whisper.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bot_db.py b/bot_db.py index a8aa58c..2ee2c5d 100644 --- a/bot_db.py +++ b/bot_db.py @@ -238,17 +238,16 @@ async def message_file(room: MatrixRoom, event: RoomMessageFile): assert isinstance(resp.body, bytes) md5 = hashlib.md5(resp.body).hexdigest() - document_fetch_result = await client.db.execute( - query="select content from documents where md5 = :md5;", values={"md5": md5} + document_fetch_result = await client.db.fetch_one( + query="select content from documents where md5 = :md5 lilmit 1;", + values={"md5": md5}, ) - document_alreadly_exists = len(document_fetch_result) == 0 # get content - content = "" + content = document_fetch_result[0] if document_fetch_result else "" # document not exists - if not document_alreadly_exists: + if content: print("document", md5, "alreadly exists") - content = document_fetch_result[0][0] else: if mimetype == "text/plain" or mimetype == "text/markdown": content = resp.body.decode() diff --git a/bot_whisper.py b/bot_whisper.py index 120afb8..904c9cb 100644 --- a/bot_whisper.py +++ b/bot_whisper.py @@ -33,7 +33,7 @@ async def message_callback(room: MatrixRoom, event: RoomMessageAudio): filelikeobj = io.BytesIO(resp.body) filelikeobj.name = "matrixaudio.ogg" # get prompt - rows = await client.db.execute( + rows = await client.db.fetch_all( query="""select content from ( select role, content, sum(token) over (partition by root order by id desc) as total_token from memories