Commit
·
e960d9b
1
Parent(s):
8daf606
Update app.py
Browse files
app.py
CHANGED
@@ -12,17 +12,6 @@ class ChatWrapper:
|
|
12 |
def __init__(self):
|
13 |
self.lock = Lock()
|
14 |
|
15 |
-
def set_openai_api_key(self, api_key: str):
|
16 |
-
with open("vectorstore.pkl", "rb") as f:
|
17 |
-
vectorstore = pickle.load(f)
|
18 |
-
"""Set the api key and return chain.
|
19 |
-
If no api_key, then None is returned.
|
20 |
-
"""
|
21 |
-
if api_key:
|
22 |
-
os.environ["OPENAI_API_KEY"] = api_key
|
23 |
-
chain = get_chain(vectorstore)
|
24 |
-
os.environ["OPENAI_API_KEY"] = ""
|
25 |
-
return chain
|
26 |
|
27 |
def __call__(self, inp: str, history: Optional[Tuple[str, str]]):
|
28 |
self.lock.acquire()
|
@@ -41,14 +30,30 @@ class ChatWrapper:
|
|
41 |
qa_chain = get_chain(vectorstore)
|
42 |
|
43 |
print("Chat with your docs!")
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
while True:
|
45 |
print("Human:")
|
46 |
-
|
47 |
-
output = qa_chain({"question":
|
48 |
-
|
49 |
print("AI:")
|
50 |
-
print(
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
except Exception as e:
|
54 |
raise e
|
|
|
12 |
def __init__(self):
|
13 |
self.lock = Lock()
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def __call__(self, inp: str, history: Optional[Tuple[str, str]]):
|
17 |
self.lock.acquire()
|
|
|
30 |
qa_chain = get_chain(vectorstore)
|
31 |
|
32 |
print("Chat with your docs!")
|
33 |
+
|
34 |
+
with open("vectorstore.pkl", "rb") as f:
|
35 |
+
vectorstore = pickle.load(f)
|
36 |
+
qa_chain = get_chain(vectorstore)
|
37 |
+
chat_history = []
|
38 |
+
print("Chat with your docs!")
|
39 |
while True:
|
40 |
print("Human:")
|
41 |
+
question = inp
|
42 |
+
output = qa_chain({"question": question, "chat_history": chat_history})
|
43 |
+
chat_history.append((question, output["answer"]))
|
44 |
print("AI:")
|
45 |
+
print(result["answer"])
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
# while True:
|
50 |
+
# print("Human:")
|
51 |
+
# history = history or []
|
52 |
+
# output = qa_chain({"question": inp, "chat_history": history})["answer"]
|
53 |
+
#history.append((inp, output))
|
54 |
+
# print("AI:")
|
55 |
+
#print(output["answer"])
|
56 |
+
chatResult = (output, chat_history)
|
57 |
|
58 |
except Exception as e:
|
59 |
raise e
|