|
import gradio as gr |
|
from langchain_core.messages import HumanMessage |
|
from agent import assistant, AgentState |
|
|
|
def respond(message, history=None): |
|
history = history or [] |
|
|
|
messages = history + [HumanMessage(content=message)] |
|
|
|
state = {"messages": messages} |
|
result = assistant(state) |
|
|
|
|
|
response_msg = result["messages"][-1].content |
|
|
|
|
|
history.append(HumanMessage(content=message)) |
|
history.append(HumanMessage(content=response_msg)) |
|
|
|
return response_msg, history |
|
|
|
demo = gr.ChatInterface(respond) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|