This commit is contained in:
1 parent
9cc6147c6f
commit
c5f7bb39e7
3 files changed
+99
-16
No files matched your search
+18
-6
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
import json
|
||||
import math
|
||||
import random
|
||||
import uuid
|
||||
from collections.abc import AsyncIterator, Awaitable, Callable
|
||||
from dataclasses import replace
|
||||
@@ -24,7 +25,13 @@ from livekit.agents.types import (
|
||||
|
||||
ProgressCallback = Callable[[dict[str, Any]], Awaitable[None]]
|
||||
WaitNoticeCallback = Callable[[str], Awaitable[None]]
|
||||
WAIT_NOTICE = "I'm working on that. I'll let you know when it's ready."
|
||||
WAIT_NOTICE_SECONDS = 12.0
|
||||
WAIT_NOTICES = (
|
||||
"I'm still working on that. I'll let you know when it's ready.",
|
||||
"This is taking a little longer. I'm on it.",
|
||||
"I'm still looking into that. I'll let you know what I find.",
|
||||
"I need a little more time on this. I'm still on it.",
|
||||
)
|
||||
|
||||
|
||||
class HermesLLMError(APIError):
|
||||
@@ -119,6 +126,7 @@ class HermesLLM(lk_llm.LLM):
|
||||
}
|
||||
self._on_progress = on_progress
|
||||
self._on_wait_notice = on_wait_notice
|
||||
self._last_wait_notice: str | None = None
|
||||
self._on_answer_start = on_answer_start
|
||||
self._timeout_seconds = timeout_seconds
|
||||
self._owns_client = http_client is None
|
||||
@@ -176,10 +184,17 @@ class HermesLLMStream(lk_llm.LLMStream):
|
||||
if self._noticed or self._has_answer or self._hermes._on_wait_notice is None:
|
||||
return
|
||||
self._noticed = True # latch before awaiting, including competing timer
|
||||
await self._callback(self._hermes._on_wait_notice, WAIT_NOTICE)
|
||||
notice = random.choice([
|
||||
text for text in WAIT_NOTICES if text != self._hermes._last_wait_notice
|
||||
])
|
||||
self._hermes._last_wait_notice = notice
|
||||
await self._callback(self._hermes._on_wait_notice, notice)
|
||||
|
||||
async def _latency_notice(self) -> None:
|
||||
await asyncio.sleep(3.0)
|
||||
# Status/tool-start events are not predictions of long latency: Hermes
|
||||
# emits them even for ordinary replies. Only elapsed time without an
|
||||
# answer warrants spoken feedback; UI progress remains independent.
|
||||
await asyncio.sleep(WAIT_NOTICE_SECONDS)
|
||||
if not self._has_answer:
|
||||
await self._progress("working", "Working on your request.")
|
||||
await self._notice()
|
||||
@@ -244,7 +259,6 @@ class HermesLLMStream(lk_llm.LLMStream):
|
||||
if item.get("status") in ("failed", "error"):
|
||||
raise HermesLLMError("upstream_error")
|
||||
await self._progress("working", "Working on your request.")
|
||||
await self._notice()
|
||||
continue
|
||||
if event == "hermes.tool.progress":
|
||||
status = item.get("status", "working")
|
||||
@@ -255,8 +269,6 @@ class HermesLLMStream(lk_llm.LLMStream):
|
||||
name = item.get("tool_name", item.get("tool", item.get("name")))
|
||||
message = f"Working on {name}." if isinstance(name, str) else "Working on your request."
|
||||
await self._progress("working", message)
|
||||
if status not in ("completed", "complete", "success", "finished"):
|
||||
await self._notice()
|
||||
continue
|
||||
choices = item.get("choices", [])
|
||||
if not isinstance(choices, list):
|
||||
|
||||
Reference in new issue
Block a user