From 56bae32e4ad7840f968049809276447e0490478f Mon Sep 17 00:00:00 2001 From: BrunoV21 Date: Mon, 1 Sep 2025 19:19:50 +0100 Subject: [PATCH] refactored send_reasoning_msg into utils --- codetide/agents/tide/ui/app.py | 31 +++++++------------------------ codetide/agents/tide/ui/utils.py | 26 +++++++++++++++++++++++++- examples/hf_demo_space/app.py | 3 +-- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/codetide/agents/tide/ui/app.py b/codetide/agents/tide/ui/app.py index dc16624..b53be52 100644 --- a/codetide/agents/tide/ui/app.py +++ b/codetide/agents/tide/ui/app.py @@ -9,9 +9,9 @@ from aicore.config import Config from aicore.llm import Llm, LlmConfig from aicore.models import AuthenticationError, ModelError - from aicore.const import STREAM_END_TOKEN, STREAM_START_TOKEN#, REASONING_START_TOKEN, REASONING_STOP_TOKEN + from aicore.const import STREAM_END_TOKEN, STREAM_START_TOKEN#, REASONING_START_TOKEN, REASONING_STOP_TOKEN + from codetide.agents.tide.ui.utils import process_thread, run_concurrent_tasks, send_reasoning_msg from codetide.agents.tide.ui.stream_processor import StreamProcessor, MarkerConfig - from codetide.agents.tide.ui.utils import process_thread, run_concurrent_tasks from codetide.agents.tide.ui.defaults import AGENT_TIDE_PORT, STARTERS from codetide.agents.tide.ui.agent_tide_ui import AgentTideUi from chainlit.data.sql_alchemy import SQLAlchemyDataLayer @@ -265,28 +265,6 @@ async def on_inspect_context(action :cl.Action): await inspect_msg.send() -async def send_reasoning_msg(loading_msg :cl.message, context_msg :cl.Message, agent_tide_ui :AgentTideUi, st :float)->bool: - await loading_msg.remove() - - context_data = { - key: value for key in ["contextIdentifiers", "modifyIdentifiers"] - if (value := getattr(agent_tide_ui.agent_tide, key, None)) - } - context_msg.elements.append( - cl.CustomElement( - name="ReasoningMessage", - props={ - "reasoning": agent_tide_ui.agent_tide.reasoning, - "data": context_data, - "title": f"Thought for {time.time()-st:.2f} seconds", - "defaultExpanded": False, - "showControls": False - } - ) - ) - await context_msg.send() - return True - @cl.on_message async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Optional[list] = None, agent_tide_ui :Optional[AgentTideUi]=None): @@ -510,3 +488,8 @@ def main(): # TODO need to test project path is working as expected... # TODO need to revisit logic + # TODO there's a bug that is leaving step messages holding for some reason + # TODO check initialzie codetide logic, seems to be deserialzied a bit too often + # TODO review codetide check for updat4es - continously readding untracked files + + # TODO check why HF-DEMO-SPACE Auth is being triggereds diff --git a/codetide/agents/tide/ui/utils.py b/codetide/agents/tide/ui/utils.py index 1606800..8b4e4f1 100644 --- a/codetide/agents/tide/ui/utils.py +++ b/codetide/agents/tide/ui/utils.py @@ -4,8 +4,10 @@ from chainlit.types import ThreadDict from aicore.logger import _logger from aicore.llm import LlmConfig +import chainlit as cl import asyncio import orjson +import time def process_thread(thread :ThreadDict)->Tuple[List[dict], Optional[LlmConfig], str]: ### type: tool @@ -69,4 +71,26 @@ async def run_concurrent_tasks(agent_tide_ui: AgentTideUi, codeIdentifiers :Opti asyncio.create_task(_logger.distribute()) while True: async for chunk in _logger.get_session_logs(agent_tide_ui.agent_tide.llm.session_id): - yield chunk \ No newline at end of file + yield chunk + +async def send_reasoning_msg(loading_msg :cl.message, context_msg :cl.Message, agent_tide_ui :AgentTideUi, st :float)->bool: + await loading_msg.remove() + + context_data = { + key: value for key in ["contextIdentifiers", "modifyIdentifiers"] + if (value := getattr(agent_tide_ui.agent_tide, key, None)) + } + context_msg.elements.append( + cl.CustomElement( + name="ReasoningMessage", + props={ + "reasoning": agent_tide_ui.agent_tide.reasoning, + "data": context_data, + "title": f"Thought for {time.time()-st:.2f} seconds", + "defaultExpanded": False, + "showControls": False + } + ) + ) + await context_msg.send() + return True \ No newline at end of file diff --git a/examples/hf_demo_space/app.py b/examples/hf_demo_space/app.py index bc3bc69..c587a6d 100644 --- a/examples/hf_demo_space/app.py +++ b/examples/hf_demo_space/app.py @@ -7,9 +7,8 @@ from codetide.agents.tide.ui.defaults import AICORE_CONFIG_EXAMPLE, EXCEPTION_MESSAGE, MISSING_CONFIG_MESSAGE, STARTERS from codetide.agents.tide.ui.stream_processor import StreamProcessor, MarkerConfig -from codetide.agents.tide.ui.utils import run_concurrent_tasks +from codetide.agents.tide.ui.utils import run_concurrent_tasks, send_reasoning_msg from codetide.agents.tide.ui.agent_tide_ui import AgentTideUi -from codetide.agents.tide.ui.app import send_reasoning_msg from codetide.core.defaults import DEFAULT_ENCODING from codetide.core.logs import logger from codetide.agents.tide.models import Step