Poojashetty357 commited on
Commit
903b676
·
verified ·
1 Parent(s): dba1c8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -69,7 +69,7 @@ def retrieve(query: str, index, category: str = None, k: int = 5) -> List[str]:
69
  if category:
70
  kwargs["filter"] = {"category": {"$eq": category}}
71
  res = index.query(vector=embed, **kwargs)
72
- return [m["metadata"]["text"] for m in res["matches"] if "text" in m["metadata"]]
73
 
74
  # Generate final answer
75
  def generate_answer(query: str, docs: List[str]) -> str:
@@ -98,7 +98,8 @@ if __name__ == "__main__":
98
  documents = load_documents(".")
99
  index_documents(pinecone_index, documents)
100
 
101
- categories = sorted({Path(p).parts[0] for p in glob.glob('*/*.txt')})
 
102
  recommended = {
103
  "all": [
104
  "Where can I find benefits information?",
 
69
  if category:
70
  kwargs["filter"] = {"category": {"$eq": category}}
71
  res = index.query(vector=embed, **kwargs)
72
+ return [m["metadata"].get("text", "") for m in res["matches"] if "metadata" in m and m["metadata"].get("text")]
73
 
74
  # Generate final answer
75
  def generate_answer(query: str, docs: List[str]) -> str:
 
98
  documents = load_documents(".")
99
  index_documents(pinecone_index, documents)
100
 
101
+ categories = sorted(set(Path(p).parts[0] for p in glob.glob('*/*.txt')) | set(recommended.keys()) - {"all"})
102
+
103
  recommended = {
104
  "all": [
105
  "Where can I find benefits information?",