File size: 791 Bytes
76df764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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