Update app.py
Browse files
app.py
CHANGED
@@ -92,20 +92,21 @@ class ChatWrapper:
|
|
92 |
def __init__(self):
|
93 |
self.lock = Lock()
|
94 |
def __call__(
|
95 |
-
self,
|
96 |
):
|
97 |
"""Execute the chat functionality."""
|
98 |
self.lock.acquire()
|
99 |
try:
|
100 |
history = history or []
|
101 |
# If chain is None, that is because no API key was provided.
|
102 |
-
if chain is None:
|
103 |
-
|
104 |
-
|
105 |
# Set OpenAI key
|
106 |
import openai
|
107 |
-
openai.api_key =
|
108 |
# Run chain and append input.
|
|
|
109 |
output = chain({"question": inp, "chat_history": history})["answer"]
|
110 |
history.append((inp, output))
|
111 |
except Exception as e:
|
@@ -136,8 +137,6 @@ with block:
|
|
136 |
|
137 |
vectorstore = load_vectorstore(embeddings.value)
|
138 |
|
139 |
-
print(vectorstore)
|
140 |
-
|
141 |
chatbot = gr.Chatbot()
|
142 |
|
143 |
with gr.Row():
|
|
|
92 |
def __init__(self):
|
93 |
self.lock = Lock()
|
94 |
def __call__(
|
95 |
+
self, inp: str, history: Optional[Tuple[str, str]], chain
|
96 |
):
|
97 |
"""Execute the chat functionality."""
|
98 |
self.lock.acquire()
|
99 |
try:
|
100 |
history = history or []
|
101 |
# If chain is None, that is because no API key was provided.
|
102 |
+
# if chain is None:
|
103 |
+
# history.append((inp, "Please paste your OpenAI key to use"))
|
104 |
+
# return history, history
|
105 |
# Set OpenAI key
|
106 |
import openai
|
107 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
108 |
# Run chain and append input.
|
109 |
+
chain = get_chain(vectorstore)
|
110 |
output = chain({"question": inp, "chat_history": history})["answer"]
|
111 |
history.append((inp, output))
|
112 |
except Exception as e:
|
|
|
137 |
|
138 |
vectorstore = load_vectorstore(embeddings.value)
|
139 |
|
|
|
|
|
140 |
chatbot = gr.Chatbot()
|
141 |
|
142 |
with gr.Row():
|