Travel_AI_V1 / chatbot.py
Ritvik
Save local changes before pull
76df764
raw
history blame
791 Bytes
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):
# Ensure system message is in memory
memory.chat_memory.add_message(SystemMessage(content=system_message))
# Add conversation history to memory
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))
# Process new message
memory.chat_memory.add_message(HumanMessage(content=message))
# Generate response using the agent
response = agent.run(message)
return response