Spaces:
Build error
Build error
Hải Huỳnh
commited on
Commit
•
ba1338f
1
Parent(s):
42a99f1
Update app.py
Browse files
app.py
CHANGED
@@ -8,22 +8,6 @@ from langchain_community.chat_message_histories import ChatMessageHistory
|
|
8 |
from langchain_core.chat_history import BaseChatMessageHistory
|
9 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
10 |
|
11 |
-
store = {}
|
12 |
-
|
13 |
-
def get_session_history(session_id: str) -> BaseChatMessageHistory:
|
14 |
-
if session_id not in store:
|
15 |
-
store[session_id] = ChatMessageHistory()
|
16 |
-
return store[session_id]
|
17 |
-
|
18 |
-
|
19 |
-
agent_with_chat_history = RunnableWithMessageHistory(
|
20 |
-
agent_executor,
|
21 |
-
get_session_history,
|
22 |
-
input_messages_key="input",
|
23 |
-
history_messages_key="chat_history",
|
24 |
-
)
|
25 |
-
|
26 |
-
# agent_with_chat_history.invoke("Have any company recruit Machine Learning jobs?")
|
27 |
|
28 |
|
29 |
@cl.on_chat_start
|
@@ -55,10 +39,8 @@ async def on_message(message: cl.Message):
|
|
55 |
|
56 |
llm_chain = cl.user_session.get("runnable")
|
57 |
|
58 |
-
response = llm_chain.
|
59 |
-
"input": message.content
|
60 |
-
},
|
61 |
-
callbacks = [cl.LangchainCallbackHandler()]
|
62 |
)
|
63 |
|
64 |
await cl.Message(response["output"].replace("`", "")).send()
|
|
|
8 |
from langchain_core.chat_history import BaseChatMessageHistory
|
9 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
@cl.on_chat_start
|
|
|
39 |
|
40 |
llm_chain = cl.user_session.get("runnable")
|
41 |
|
42 |
+
response = await llm_chain.ainvoke(
|
43 |
+
{"input": message.content}, callbacks = [cl.LangchainCallbackHandler()]
|
|
|
|
|
44 |
)
|
45 |
|
46 |
await cl.Message(response["output"].replace("`", "")).send()
|