Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,216 Bytes
76df764 4a38fbc 76df764 4a38fbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from langchain.schema import SystemMessage, HumanMessage, AIMessage
from memory import memory
from agent import agent
def respond(message, history, system_message, max_tokens, temperature, top_p):
memory.chat_memory.add_message(SystemMessage(content=system_message))
for user_input, bot_response in history:
if user_input:
memory.chat_memory.add_message(HumanMessage(content=user_input))
if bot_response:
memory.chat_memory.add_message(AIMessage(content=bot_response))
memory.chat_memory.add_message(HumanMessage(content=message))
if "flight" in message.lower():
message = f"Use the 'Flight Booking' tool. {message}"
elif "hotel" in message.lower() or "stay" in message.lower():
message = f"Use the 'Hotel Booking' tool. {message}"
response_dict = agent.invoke({"input": message}) # Updated from .run to .invoke
response = response_dict["output"] if "output" in response_dict else str(response_dict)
if "β" in response:
response += "\n\nWould you like me to retry with different dates (e.g., 'hotels in Paris from March 1 2025 to March 4 2025') or assist with something else (e.g., flights)?"
return response |