Skip to content

Commit 0bcb1b1

Browse files
committed
refactor(hf_demo_space): update streaming imports and cleanup actions
1 parent 4fb34ae commit 0bcb1b1

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

examples/hf_demo_space/app.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
os.environ.setdefault("CHAINLIT_APP_ROOT", str(Path(os.path.abspath(__file__)).parent))
77
os.environ.setdefault("SKIP_AUTH", "1")
88

9+
from codetide.agents.tide.streaming.service import run_concurrent_tasks, cancel_gen
910
from codetide.agents.tide.ui.defaults import AICORE_CONFIG_EXAMPLE, EXCEPTION_MESSAGE, MISSING_CONFIG_MESSAGE, STARTERS
1011
from codetide.agents.tide.ui.stream_processor import StreamProcessor, MarkerConfig
11-
from codetide.agents.tide.ui.utils import run_concurrent_tasks, send_reasoning_msg
12+
from codetide.agents.tide.ui.utils import send_reasoning_msg
1213
from codetide.agents.tide.ui.agent_tide_ui import AgentTideUi
1314
from codetide.core.defaults import DEFAULT_ENCODING
1415
from codetide.agents.tide.models import Step
@@ -364,7 +365,8 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
364365

365366
st = time.time()
366367
is_reasonig_sent = False
367-
async for chunk in run_concurrent_tasks(agent_tide_ui, codeIdentifiers):
368+
loop = run_concurrent_tasks(agent_tide_ui, codeIdentifiers)
369+
async for chunk in loop:
368370
if chunk == STREAM_START_TOKEN:
369371
is_reasonig_sent = await send_reasoning_msg(loading_msg, context_msg, agent_tide_ui, st)
370372
continue
@@ -375,17 +377,18 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
375377
elif chunk == STREAM_END_TOKEN:
376378
# Handle any remaining content
377379
await stream_processor.finalize()
378-
break
380+
await asyncio.sleep(0.5)
381+
await cancel_gen(loop)
379382

380383
await stream_processor.process_chunk(chunk)
381-
384+
382385
await asyncio.sleep(0.5)
383386
if agent_tide_ui.agent_tide.steps:
384387
cl.user_session.set("latest_step_message", msg)
385388
msg.actions = [
386389
cl.Action(
387390
name="stop_steps",
388-
tooltip="stop",
391+
tooltip="Stop",
389392
icon="octagon-x",
390393
payload={"msg_id": msg.id}
391394
),
@@ -407,15 +410,6 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
407410
)
408411
)
409412

410-
msg.actions.append(
411-
cl.Action(
412-
name="checkout_commit_push",
413-
tooltip="A new branch will be created and the changes made so far will be commited and pushed to the upstream repository",
414-
icon="circle-fading-arrow-up",
415-
payload={"msg_id": msg.id}
416-
)
417-
)
418-
419413
# Send the final message
420414
await msg.send()
421415

0 commit comments

Comments
 (0)