Spaces:
Sleeping
Sleeping
removed async calls and WORKS
Browse files- app.py +25 -29
- requirements.txt +2 -1
app.py
CHANGED
@@ -14,9 +14,6 @@ from langchain.agents import ZeroShotAgent, AgentExecutor
|
|
14 |
from langchain.chat_models import ChatOpenAI
|
15 |
from langchain import LLMChain
|
16 |
|
17 |
-
import os
|
18 |
-
os.environ["OPENAI_API_KEY"] = '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'
|
19 |
-
|
20 |
@cl.author_rename
|
21 |
def rename(orig_author: str):
|
22 |
rename_dict = {"RetrievalQA": "Consulting The Barbenheimer"}
|
@@ -193,7 +190,7 @@ async def init():
|
|
193 |
tools=tools,
|
194 |
verbose=True )
|
195 |
# create execution agent
|
196 |
-
barbenheimer_agent_chain =
|
197 |
agent=barbenheimer_agent,
|
198 |
tools=tools,
|
199 |
verbose=True )
|
@@ -210,36 +207,35 @@ async def main(message):
|
|
210 |
# await msg.send()
|
211 |
|
212 |
chain = cl.user_session.get("chain")
|
213 |
-
cb = cl.
|
214 |
stream_final_answer=False, answer_prefix_tokens=["FINAL", "ANSWER"]
|
215 |
)
|
216 |
cb.answer_reached = True
|
217 |
-
res =
|
218 |
|
219 |
-
#
|
220 |
-
# await msg.send()
|
221 |
|
222 |
-
answer = res["
|
223 |
source_elements = []
|
224 |
-
visited_sources = set()
|
225 |
-
|
226 |
-
# Get the documents from the user session
|
227 |
-
docs = res["source_documents"]
|
228 |
-
metadatas = [doc.metadata for doc in docs]
|
229 |
-
all_sources = [m["source"] for m in metadatas]
|
230 |
-
|
231 |
-
for source in all_sources:
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
if source_elements:
|
241 |
-
|
242 |
-
else:
|
243 |
-
|
244 |
|
245 |
await cl.Message(content=answer, elements=source_elements).send()
|
|
|
14 |
from langchain.chat_models import ChatOpenAI
|
15 |
from langchain import LLMChain
|
16 |
|
|
|
|
|
|
|
17 |
@cl.author_rename
|
18 |
def rename(orig_author: str):
|
19 |
rename_dict = {"RetrievalQA": "Consulting The Barbenheimer"}
|
|
|
190 |
tools=tools,
|
191 |
verbose=True )
|
192 |
# create execution agent
|
193 |
+
barbenheimer_agent_chain = AgentExecutor.from_agent_and_tools(
|
194 |
agent=barbenheimer_agent,
|
195 |
tools=tools,
|
196 |
verbose=True )
|
|
|
207 |
# await msg.send()
|
208 |
|
209 |
chain = cl.user_session.get("chain")
|
210 |
+
cb = cl.LangchainCallbackHandler(
|
211 |
stream_final_answer=False, answer_prefix_tokens=["FINAL", "ANSWER"]
|
212 |
)
|
213 |
cb.answer_reached = True
|
214 |
+
res = chain.__call__(message, callbacks=[cb], )
|
215 |
|
216 |
+
# print(res.keys()) # keys are "input" and "output"
|
|
|
217 |
|
218 |
+
answer = res["output"]
|
219 |
source_elements = []
|
220 |
+
# visited_sources = set()
|
221 |
+
|
222 |
+
# # Get the documents from the user session
|
223 |
+
# docs = res["source_documents"]
|
224 |
+
# metadatas = [doc.metadata for doc in docs]
|
225 |
+
# all_sources = [m["source"] for m in metadatas]
|
226 |
+
|
227 |
+
# for source in all_sources:
|
228 |
+
# if source in visited_sources:
|
229 |
+
# continue
|
230 |
+
# visited_sources.add(source)
|
231 |
+
# # Create the text element referenced in the message
|
232 |
+
# source_elements.append(
|
233 |
+
# cl.Text(content="https://www.imdb.com" + source, name="Review URL")
|
234 |
+
# )
|
235 |
+
|
236 |
+
# if source_elements:
|
237 |
+
# answer += f"\nSources: {', '.join([e.content.decode('utf-8') for e in source_elements])}"
|
238 |
+
# else:
|
239 |
+
# answer += "\nNo sources found"
|
240 |
|
241 |
await cl.Message(content=answer, elements=source_elements).send()
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ langchain==0.0.265
|
|
3 |
tiktoken==0.4.0
|
4 |
openai==0.27.8
|
5 |
faiss-cpu==1.7.4
|
6 |
-
wikipedia==1.4.0
|
|
|
|
3 |
tiktoken==0.4.0
|
4 |
openai==0.27.8
|
5 |
faiss-cpu==1.7.4
|
6 |
+
wikipedia==1.4.0
|
7 |
+
rank_bm25
|