Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from langchain.agents import AgentType, Tool, initialize_agent
|
| 2 |
from langchain.callbacks import StreamlitCallbackHandler
|
| 3 |
from langchain.chains import RetrievalQA
|
| 4 |
from langchain.chains.conversation.memory import ConversationBufferMemory
|
|
@@ -20,6 +20,8 @@ serp_token = os.environ['SERP_TOKEN']
|
|
| 20 |
repo_id = "sentence-transformers/all-mpnet-base-v2"
|
| 21 |
from datetime import datetime
|
| 22 |
from langchain.tools import Tool
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
|
@@ -135,22 +137,25 @@ def main():
|
|
| 135 |
mode = "Agent with AskHuman tool"
|
| 136 |
|
| 137 |
# initialize agent
|
| 138 |
-
agent = initialize_agent(
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
|
| 153 |
)
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
# question form
|
| 156 |
with st.form(key="form"):
|
|
@@ -162,7 +167,8 @@ def main():
|
|
| 162 |
if submit_clicked:
|
| 163 |
# st_callback = StreamlitCallbackHandler(st.container())
|
| 164 |
# response = agent.run(user_input,callbacks = [st_callback])
|
| 165 |
-
response =
|
|
|
|
| 166 |
st.write(response)
|
| 167 |
# output_container = output_container.container()
|
| 168 |
# output_container.chat_message("user").write(user_input)
|
|
|
|
| 1 |
+
from langchain.agents import AgentType, Tool, initialize_agent,AgentExecutor, create_react_agent
|
| 2 |
from langchain.callbacks import StreamlitCallbackHandler
|
| 3 |
from langchain.chains import RetrievalQA
|
| 4 |
from langchain.chains.conversation.memory import ConversationBufferMemory
|
|
|
|
| 20 |
repo_id = "sentence-transformers/all-mpnet-base-v2"
|
| 21 |
from datetime import datetime
|
| 22 |
from langchain.tools import Tool
|
| 23 |
+
from langchain import hub
|
| 24 |
+
prompt = hub.pull("hwchase17/react")
|
| 25 |
|
| 26 |
|
| 27 |
|
|
|
|
| 137 |
mode = "Agent with AskHuman tool"
|
| 138 |
|
| 139 |
# initialize agent
|
| 140 |
+
# agent = initialize_agent(
|
| 141 |
+
# agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
| 142 |
+
# tools=[db_search_tool,search_tool,datetime_tool],
|
| 143 |
+
# llm=llm,
|
| 144 |
+
# verbose=True,
|
| 145 |
+
# max_iterations=5,
|
| 146 |
+
# early_stopping_method="generate",
|
| 147 |
+
# memory=conversational_memory,
|
| 148 |
+
# agent_kwargs={
|
| 149 |
+
# "prefix": prefix,
|
| 150 |
+
# "format_instructions": format_instructions,
|
| 151 |
+
# "suffix": suffix,
|
| 152 |
+
# },
|
| 153 |
+
# handle_parsing_errors=True,
|
| 154 |
|
| 155 |
)
|
| 156 |
+
agent = create_react_agent(model = llm, tools=[db_search_tool,search_tool,datetime_tool], prompt = prompt)
|
| 157 |
+
tools = [db_search_tool,search_tool,datetime_tool]
|
| 158 |
+
agent_executor = AgentExecutor(agent=agent, tools=tools)
|
| 159 |
|
| 160 |
# question form
|
| 161 |
with st.form(key="form"):
|
|
|
|
| 167 |
if submit_clicked:
|
| 168 |
# st_callback = StreamlitCallbackHandler(st.container())
|
| 169 |
# response = agent.run(user_input,callbacks = [st_callback])
|
| 170 |
+
response = agent_executor.invoke({"input": user_input})
|
| 171 |
+
# response = agent.run(user_input)
|
| 172 |
st.write(response)
|
| 173 |
# output_container = output_container.container()
|
| 174 |
# output_container.chat_message("user").write(user_input)
|