Enhance workflow engine and frontend components with transition speech support
- Introduce edge transition speech functionality in the WorkflowEngine to provide optional speech during node transitions. - Update pipeline execution to utilize the new transition speech feature, enhancing user experience by masking delays during transitions. - Modify frontend components to support transition speech in edge specifications, allowing users to define and edit transition speech for edges. - Refactor edge handling logic in the WorkflowEditor to accommodate the new transition speech field, improving workflow management capabilities.
This commit is contained in:
@@ -346,9 +346,18 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
await emit_node_active(target)
|
||||
apply_node(target)
|
||||
|
||||
def make_transition_handler(target: str):
|
||||
async def speak_transition(edge: dict | None) -> None:
|
||||
"""切换瞬间播报过渡语(可选),掩盖切节点/新一轮生成的延迟。不写入上下文。"""
|
||||
speech = engine.edge_transition_speech(edge)
|
||||
if speech:
|
||||
await worker.queue_frame(TTSSpeakFrame(speech, append_to_context=False))
|
||||
|
||||
def make_transition_handler(edge: dict):
|
||||
target = edge.get("target")
|
||||
|
||||
async def handler(params):
|
||||
logger.info(f"LLM 触发转移 → {engine.name(target)}")
|
||||
await speak_transition(edge)
|
||||
await go_to_node(target)
|
||||
# 返回工具结果,pipecat 随即在新节点的提示/工具下继续生成
|
||||
await params.result_callback({"status": "ok"})
|
||||
@@ -372,6 +381,7 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
)
|
||||
if target and target != wf_state["current"]:
|
||||
logger.info(f"文本兜底触发转移 → {engine.name(target)}")
|
||||
await speak_transition(engine.find_edge(wf_state["current"], target))
|
||||
# 仅切换节点提示/工具,下一轮用户输入即在新节点处理
|
||||
await go_to_node(target)
|
||||
|
||||
@@ -379,10 +389,9 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
# 由各节点的 context.tools 控制当前可见哪些)。
|
||||
if workflow_active:
|
||||
for edge in engine.edges:
|
||||
target = edge.get("target")
|
||||
if target:
|
||||
if edge.get("target"):
|
||||
llm.register_function(
|
||||
engine.edge_fn_name(edge), make_transition_handler(target)
|
||||
engine.edge_fn_name(edge), make_transition_handler(edge)
|
||||
)
|
||||
apply_node(wf_state["current"]) # 设初始节点的提示与工具
|
||||
|
||||
|
||||
@@ -50,6 +50,18 @@ class WorkflowEngine:
|
||||
def edge_condition(self, edge: dict) -> str:
|
||||
return (edge.get("data") or {}).get("condition") or ""
|
||||
|
||||
def edge_transition_speech(self, edge: dict | None) -> str:
|
||||
"""命中该边、切换节点瞬间播报的过渡语(可选,掩盖延迟,不写入上下文)。"""
|
||||
if not edge:
|
||||
return ""
|
||||
return (edge.get("data") or {}).get("transition_speech") or ""
|
||||
|
||||
def find_edge(self, source: str | None, target: str | None) -> dict | None:
|
||||
for edge in self.edges:
|
||||
if edge.get("source") == source and edge.get("target") == target:
|
||||
return edge
|
||||
return None
|
||||
|
||||
def edge_description(self, edge: dict) -> str:
|
||||
"""作为转移函数的 description 交给 LLM:满足该条件时模型应调用此函数。"""
|
||||
cond = self.edge_condition(edge)
|
||||
|
||||
Reference in New Issue
Block a user