我正在使用多种技术的聊天机器人上工作。下面的代码工作正常,我想将res ['path']转换为字典格式,以便可以使用javascript在chatbot上显示结果。我该怎么做。
if 'Sorry I could not understand' in xx:
index_dir = os.path.join(settings.STATICFILES_DIRS[0],"textdata")
ix= open_dir(index_dir)
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse(Input)
results= searcher.search(query, limit=3)
if len(results)!=0:
for res in results:
print('filepath:', res['path'])
return JsonResponse({"output": str(dict(res))}, status=200)
else:
return JsonResponse({"output": "No result found"},
status=200)
else:
return JsonResponse(xx, safe=False)
Actual result - filepath: D:\data\car1\carfinance.pdf
Expected result - In dictionary {filepath: D:\data\car1\carfinance.pdf}