Fix/json format (#465)

This commit is contained in:
Jyong 2023-06-27 17:15:03 +08:00 committed by GitHub
parent d5b42c09ee
commit c67ecff3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -36,8 +36,9 @@ class ExcelLoader(BaseLoader):
if keys == []:
keys = list(map(str, row))
else:
row_dict = dict(zip(keys, row))
row_dict = dict(zip(keys, list(map(str, row))))
row_dict = {k: v for k, v in row_dict.items() if v}
data.append(json.dumps(row_dict, ensure_ascii=False))
item = ''.join(f'{k}:{v}\n' for k, v in row_dict.items())
data.append(item)
return [Document(page_content='\n\n'.join(data))]

View File

@ -134,6 +134,16 @@ class NotionLoader(BaseLoader):
else:
value = property_value[type]
data[property_name] = value
row_dict = {k: v for k, v in data.items() if v}
row_content = ''
for key, value in row_dict.items():
if isinstance(value, dict):
value_dict = {k: v for k, v in value.items() if v}
value_content = ''.join(f'{k}:{v} ' for k, v in value_dict.items())
row_content = row_content + f'{key}:{value_content}\n'
else:
row_content = row_content + f'{key}:{value}\n'
database_content_list.append(row_content)
database_content_list.append(json.dumps(data, ensure_ascii=False))
return "\n\n".join(database_content_list)