andrewgleave commited on
Commit
24fad8b
1 Parent(s): d0d4202
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -2,6 +2,7 @@ import json
2
  import os
3
  from pathlib import Path
4
 
 
5
  from langchain.docstore.document import Document
6
  from langchain.docstore.in_memory import InMemoryDocstore
7
  from langchain.embeddings import OpenAIEmbeddings
@@ -22,11 +23,6 @@ def load_store():
22
  def keys_to_int(x):
23
  return {int(k): v for k, v in x.items()}
24
 
25
- def _read_index(path):
26
- import faiss
27
-
28
- return faiss.read_index(str(path))
29
-
30
  index_path = list(Path(STORE_DIR).glob("*.faiss"))
31
  if len(index_path) == 0:
32
  raise ValueError("No index found in path")
@@ -43,7 +39,7 @@ def load_store():
43
  embeddings = OpenAIEmbeddings()
44
  return FAISS(
45
  embedding_function=embeddings.embed_query,
46
- index=_read_index(index_path),
47
  docstore=InMemoryDocstore(
48
  {index_to_id[i]: Document(**doc) for i, doc in enumerate(docs.values())}
49
  ),
@@ -67,7 +63,7 @@ def _to_embed(link):
67
  def chat(inp, history, agent):
68
  history = history or []
69
  if agent is None:
70
- history.append((inp, "Please paste your OpenAI key to use"))
71
  return history, history
72
  output = agent({"question": inp, "chat_history": history})
73
  answer = output["answer"]
 
2
  import os
3
  from pathlib import Path
4
 
5
+ import faiss
6
  from langchain.docstore.document import Document
7
  from langchain.docstore.in_memory import InMemoryDocstore
8
  from langchain.embeddings import OpenAIEmbeddings
 
23
  def keys_to_int(x):
24
  return {int(k): v for k, v in x.items()}
25
 
 
 
 
 
 
26
  index_path = list(Path(STORE_DIR).glob("*.faiss"))
27
  if len(index_path) == 0:
28
  raise ValueError("No index found in path")
 
39
  embeddings = OpenAIEmbeddings()
40
  return FAISS(
41
  embedding_function=embeddings.embed_query,
42
+ index=faiss.read_index(str(index_path)),
43
  docstore=InMemoryDocstore(
44
  {index_to_id[i]: Document(**doc) for i, doc in enumerate(docs.values())}
45
  ),
 
63
  def chat(inp, history, agent):
64
  history = history or []
65
  if agent is None:
66
+ history.append((inp, "Please paste your OpenAI key"))
67
  return history, history
68
  output = agent({"question": inp, "chat_history": history})
69
  answer = output["answer"]