janar commited on
Commit
c224647
1 Parent(s): df41eed
Files changed (2) hide show
  1. api/routes/search.py +2 -1
  2. fe/app.py +7 -4
api/routes/search.py CHANGED
@@ -30,7 +30,8 @@ async def answer(name: str, query: str):
30
  docs = _db.similarity_search_with_score(query=query)
31
  print(docs)
32
  answer = _chain.run(input_documents=[tup[0] for tup in docs], question=query)
33
- return JSONResponse(status_code=200, content={"answer": answer, "file_score": [[f"{d[0].metadata['file']} : {d[0].metadata['page']}", d[1]] for d in docs]})
 
34
 
35
 
36
  @router.get("/v1/datasets")
 
30
  docs = _db.similarity_search_with_score(query=query)
31
  print(docs)
32
  answer = _chain.run(input_documents=[tup[0] for tup in docs], question=query)
33
+ return JSONResponse(status_code=200, content={"answer": answer, "metadata": [
34
+ {"file": d[0].metadata['file'], "page" : d[0].metadata['page'], "score": d[1]} for d in docs]})
35
 
36
 
37
  @router.get("/v1/datasets")
fe/app.py CHANGED
@@ -16,10 +16,13 @@ if ds:
16
  query = st.text_input("Enter your search query",
17
  placeholder="Ask your question")
18
  if query:
19
- answer = requests.get(f"http://localhost:8080/v1/datasets/{ds}/answer?query={query}",
20
- timeout=5000 )
 
21
 
22
- print(answer.json()["answer"])
23
- st.write(answer.json()["answer"])
 
 
24
  else:
25
  st.write("Choose your dataset!")
 
16
  query = st.text_input("Enter your search query",
17
  placeholder="Ask your question")
18
  if query:
19
+ res = requests.get(f"http://localhost:8080/v1/datasets/{ds}/answer?query={query}",
20
+ timeout=5000 ).json()
21
+ answer = res["answer"]
22
 
23
+ st.write(answer)
24
+ files = [f"{f['file']}, page {f['page']}" for f in res["metadata"]]
25
+ for fi in files:
26
+ st.markdown(f"- {fi}")
27
  else:
28
  st.write("Choose your dataset!")