Find answers from the community

Updated 2 months ago

anyone know why `index =

anyone know why index = VectorStoreIndex.from_documents(documents) might be raising a TypeError: Object of type datetime is not JSON serializable exception when tring to serialize the documents from:

Plain Text
reader = DiscordReader(discord_token=discord_token)
documents = reader.load_data(channel_ids=channel_ids)
L
s
5 comments
Seems like the metadata needs to be a string, and it sounds like the discord loader is inserting datetime objects into the metadata
oh so i have to modify the discord loader possibly then @Logan M ? I was trying to find any mention of date time in the discord loader source but i could not find any
update:
in order to fix this issue (which is caused by a bug in the library)
I had to itterate the documents and convert the dates to strings

Plain Text
# fix date time encoding
for doc in documents:
    doc.metadata['created_at'] = json.dumps(doc.metadata['created_at'],default=str)
    doc.metadata['edited_at'] = json.dumps(doc.metadata['edited_at'],default=str)
Yea the latter is more what I meant as a fix πŸ‘
i should probably make a pr for the discord data connector
Add a reply
Sign up and join the conversation on Discord