mirror of
https://github.com/NCBM/plyngent.git
synced 2026-11-07 15:37:55 +08:00
cli: fix limit prompt redundancy and line-break
This commit is contained in:
@@ -491,7 +491,7 @@ async def run_chat_loop( # noqa: C901, PLR0912 — multi-phase tool loop
|
||||
continue
|
||||
return
|
||||
|
||||
reason = f"tool loop reached {allowance} rounds (used {rounds_used})"
|
||||
reason = f"tool loop limit reached ({allowance} rounds)"
|
||||
if on_limit is not None and await _call_on_limit(on_limit, reason):
|
||||
yield MaxRoundsEvent(rounds=allowance, continued=True)
|
||||
allowance += max_rounds
|
||||
|
||||
@@ -98,9 +98,17 @@ def _echo_tool_confirm(name: str, reason: str) -> None:
|
||||
backend.echo()
|
||||
|
||||
|
||||
def _echo_continue_limit(reason: str) -> None:
|
||||
"""Echo the limit reason as a standalone line (not jammed into a confirm prompt)."""
|
||||
backend = get_prompt_backend()
|
||||
backend.secho(f"[limit] {reason}", fg="yellow")
|
||||
backend.echo()
|
||||
|
||||
|
||||
def _prompt_continue_limit_sync(reason: str) -> bool:
|
||||
try:
|
||||
return confirm(f"[limit] {reason}\nRaise limit and continue?", default=True)
|
||||
_echo_continue_limit(reason)
|
||||
return confirm("Raise limit and continue?", default=True)
|
||||
except NonInteractiveError:
|
||||
return False
|
||||
|
||||
@@ -114,10 +122,13 @@ def prompt_continue_limit(reason: str) -> bool:
|
||||
async def prompt_continue_limit_async(reason: str) -> bool:
|
||||
"""Async variant: confirm off the event loop so the turn is not cancelled."""
|
||||
try:
|
||||
return await confirm_async(
|
||||
f"[limit] {reason}\nRaise limit and continue?",
|
||||
default=True,
|
||||
)
|
||||
from plyngent.prompting import run_prompt_async
|
||||
|
||||
def _run() -> bool:
|
||||
_echo_continue_limit(reason)
|
||||
return confirm("Raise limit and continue?", default=True)
|
||||
|
||||
return await run_prompt_async(_run)
|
||||
except NonInteractiveError:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user