Hello! Currently, I am in the process of developing an artificial intelligence bot, and one of the crucial aspects I’m working on is implementing a robust memory system. Specifically, my objective is to create a unique key for each user based on their ID and subsequently append their messages to this designated key. Unfortunately, I have encountered some errors during this process. If anyone has the expertise and can offer assistance, I would greatly appreciate it. Your input and guidance would be invaluable in overcoming these obstacles and ensuring the successful implementation of the memory system.
That snippet isn’t exactly enough. Can you send the link to your Repl? uid seems to be "<uid>", so we’ll need to see where you defined it. By the way, there’s no need for the f string.
Traceback (most recent call last):
File "/home/runner/AI/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "main.py", line 84, in on_message
conversation.ask(ctx.author.id, ctx.content)
File "main.py", line 54, in ask
*self.get_messages(uid)
File "main.py", line 41, in get_messages
return db[uid]["messages"]
File "/home/runner/AI/.pythonlibs/lib/python3.10/site-packages/replit/database/database.py", line 464, in __getitem__
raw_val = self.get_raw(key)
File "/home/runner/AI/.pythonlibs/lib/python3.10/site-packages/replit/database/database.py", line 500, in get_raw
r = self.sess.get(self.db_url + "/" + urllib.parse.quote(key))
File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/urllib/parse.py", line 869, in quote
return quote_from_bytes(string, safe)
File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/urllib/parse.py", line 894, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
Replit’s database keys must only be strings (or bytes I think).
So either convert your uid to a string when interacting with the database, or have all uids be strings instead of ints.
If your database key is not a string, it will give a very convoluted error message that’s hard to understand (which needs to be fixed).