From 0acd9a28902433b81a8eef2cfc2e6f4bd932e965 Mon Sep 17 00:00:00 2001 From: aserrador Date: Wed, 11 Feb 2026 18:38:45 -0500 Subject: [PATCH] feat: Add AgentClient with timeout 60. --- ui/src/ui/agent_client.py | 18 ++++++++++++++++++ ui/src/ui/app.py | 36 ++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 ui/src/ui/agent_client.py diff --git a/ui/src/ui/agent_client.py b/ui/src/ui/agent_client.py new file mode 100644 index 0000000..8129ae0 --- /dev/null +++ b/ui/src/ui/agent_client.py @@ -0,0 +1,18 @@ +import httpx +from logger import logger + + +class AgentClient: + def __init__(self): + self._client = httpx.AsyncClient() + + async def send_message(self, message): + logger.info(f"Sending message to agent: {message}") + + response = await self._client.post( + "http://localhost:8010/chat", + json={"messages": message}, + timeout=60 + ) + + return response diff --git a/ui/src/ui/app.py b/ui/src/ui/app.py index 641d8b4..279de0f 100644 --- a/ui/src/ui/app.py +++ b/ui/src/ui/app.py @@ -1,22 +1,20 @@ import streamlit as st +from agent_client import AgentClient +from logger import logger import random import time -def response_generator(): - response = random.choice( - [ - "Hello there! How can I assist you today?", - "Hi, human! Is there anything I can help you with?", - "Do you need help?", - ] - ) - for word in response.split(): - yield word + " " - time.sleep(0.05) +def response_generator(response: str = ""): + logger.info(f"Generating response stream for: {response}") -def main(): - st.image("./assets/logo-naliia.png", width=100, caption="NaliiaBot") + if response: + for word in response.split(): + yield word + " " + time.sleep(0.05) + +async def main(): + st.image("src/ui/assets/logo-naliia.png", width=100, caption="NaliiaBot") if "messages" not in st.session_state: st.session_state.messages = [] @@ -30,11 +28,13 @@ def main(): st.chat_message("user").markdown(prompt) st.session_state.messages.append({"role": "user", "content": prompt}) - response = f"Echo: {prompt}" + agent_client = AgentClient() + response = await agent_client.send_message(prompt) + + formated_response = response.json()['response']['messages'][-1]['content'] with st.chat_message("assistant"): - response = st.write_stream(response_generator()) + response = st.write_stream(response_generator(formated_response)) + st.session_state.messages.append({"role": "assistant", "content": formated_response}) - st.session_state.messages.append({"role": "assistant", "content": response}) - -if __name__ == "__main__": main() \ No newline at end of file +if __name__ == "__main__": import asyncio; asyncio.run(main())