menikev commited on
Commit
9086088
·
verified ·
1 Parent(s): ef77a2c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -7,6 +7,7 @@ from langchain_huggingface import HuggingFacePipeline
7
  from langchain.agents import create_react_agent, AgentExecutor, Tool
8
  from langchain.prompts import PromptTemplate
9
  from langchain.memory import ConversationBufferMemory
 
10
 
11
  # Email configuration
12
  SENDER_EMAIL = "[email protected]" # Replace with your email
@@ -86,7 +87,11 @@ prompt = PromptTemplate.from_template(
86
 
87
  agent = create_react_agent(local_llm, tools, prompt)
88
  agent_executor = AgentExecutor.from_agent_and_tools(
89
- agent=agent, tools=tools, verbose=True, memory=ConversationBufferMemory(memory_key="chat_history", return_messages=True)
 
 
 
 
90
  )
91
 
92
  # Streamlit interface
@@ -108,9 +113,19 @@ if prompt := st.chat_input("Your message"):
108
 
109
  with st.chat_message("assistant"):
110
  with st.spinner("Thinking..."):
111
- response = agent_executor.run(prompt)
112
- st.markdown(response)
113
- st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
 
 
 
 
 
 
114
 
115
  st.sidebar.title("About")
116
  st.sidebar.info("This is an interactive CyberSecurity Program Meeting Scheduler. Chat with the AI to schedule your meeting. It will collect your information and send a meeting invitation via email.")
 
7
  from langchain.agents import create_react_agent, AgentExecutor, Tool
8
  from langchain.prompts import PromptTemplate
9
  from langchain.memory import ConversationBufferMemory
10
+ from langchain.schema import AgentAction, AgentFinish
11
 
12
  # Email configuration
13
  SENDER_EMAIL = "[email protected]" # Replace with your email
 
87
 
88
  agent = create_react_agent(local_llm, tools, prompt)
89
  agent_executor = AgentExecutor.from_agent_and_tools(
90
+ agent=agent,
91
+ tools=tools,
92
+ verbose=True,
93
+ memory=ConversationBufferMemory(memory_key="chat_history", return_messages=True),
94
+ handle_parsing_errors=True
95
  )
96
 
97
  # Streamlit interface
 
113
 
114
  with st.chat_message("assistant"):
115
  with st.spinner("Thinking..."):
116
+ try:
117
+ response = agent_executor({"input": prompt})
118
+ if isinstance(response, dict) and "output" in response:
119
+ assistant_response = response["output"]
120
+ elif isinstance(response, (AgentAction, AgentFinish)):
121
+ assistant_response = response.return_values.get("output", str(response))
122
+ else:
123
+ assistant_response = str(response)
124
+
125
+ st.markdown(assistant_response)
126
+ st.session_state.messages.append({"role": "assistant", "content": assistant_response})
127
+ except Exception as e:
128
+ st.error(f"An error occurred: {str(e)}")
129
 
130
  st.sidebar.title("About")
131
  st.sidebar.info("This is an interactive CyberSecurity Program Meeting Scheduler. Chat with the AI to schedule your meeting. It will collect your information and send a meeting invitation via email.")