fix bug
This commit is contained in:
11
bot_db.py
11
bot_db.py
@@ -238,17 +238,16 @@ async def message_file(room: MatrixRoom, event: RoomMessageFile):
|
|||||||
assert isinstance(resp.body, bytes)
|
assert isinstance(resp.body, bytes)
|
||||||
md5 = hashlib.md5(resp.body).hexdigest()
|
md5 = hashlib.md5(resp.body).hexdigest()
|
||||||
|
|
||||||
document_fetch_result = await client.db.execute(
|
document_fetch_result = await client.db.fetch_one(
|
||||||
query="select content from documents where md5 = :md5;", values={"md5": md5}
|
query="select content from documents where md5 = :md5 lilmit 1;",
|
||||||
|
values={"md5": md5},
|
||||||
)
|
)
|
||||||
document_alreadly_exists = len(document_fetch_result) == 0
|
|
||||||
|
|
||||||
# get content
|
# get content
|
||||||
content = ""
|
content = document_fetch_result[0] if document_fetch_result else ""
|
||||||
# document not exists
|
# document not exists
|
||||||
if not document_alreadly_exists:
|
if content:
|
||||||
print("document", md5, "alreadly exists")
|
print("document", md5, "alreadly exists")
|
||||||
content = document_fetch_result[0][0]
|
|
||||||
else:
|
else:
|
||||||
if mimetype == "text/plain" or mimetype == "text/markdown":
|
if mimetype == "text/plain" or mimetype == "text/markdown":
|
||||||
content = resp.body.decode()
|
content = resp.body.decode()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ async def message_callback(room: MatrixRoom, event: RoomMessageAudio):
|
|||||||
filelikeobj = io.BytesIO(resp.body)
|
filelikeobj = io.BytesIO(resp.body)
|
||||||
filelikeobj.name = "matrixaudio.ogg"
|
filelikeobj.name = "matrixaudio.ogg"
|
||||||
# get prompt
|
# get prompt
|
||||||
rows = await client.db.execute(
|
rows = await client.db.fetch_all(
|
||||||
query="""select content from (
|
query="""select content from (
|
||||||
select role, content, sum(token) over (partition by root order by id desc) as total_token
|
select role, content, sum(token) over (partition by root order by id desc) as total_token
|
||||||
from memories
|
from memories
|
||||||
|
|||||||
Reference in New Issue
Block a user