feat: jev 接入,判断创建、修改、问答、不明确四类意图

This commit is contained in:
2026-09-22 20:14:10 +08:00
parent 94faffca18
commit 417772b007
7 changed files with 346 additions and 17 deletions
+21
View File
@@ -1,4 +1,5 @@
import logging
import inspect
import time
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, TypeVar
@@ -30,6 +31,8 @@ class BaseNode(ABC):
def __call__(self, state: T) -> T:
"""执行节点,统一记录日志、耗时并保留业务异常类型"""
if inspect.iscoroutinefunction(self.process):
return self._acall(state)
start_time = time.perf_counter()
self.logger.info("--- %s 开始 ---", self.name)
try:
@@ -52,6 +55,24 @@ class BaseNode(ABC):
def process(self, state: T) -> T:
"""子类实现节点核心逻辑,返回状态更新"""
async def _acall(self, state: T) -> T:
"""异步节点等待执行完成后再记录结果和耗时"""
start_time = time.perf_counter()
self.logger.info("--- %s 开始 ---", self.name)
try:
result = await self.process(state)
except (AppError, ValidationError):
self.logger.exception("%s 执行失败", self.name)
raise
except Exception as error:
self.logger.exception("%s 执行失败", self.name)
raise ImportProcessError(str(error), node_name=self.name) from error
else:
self.logger.info("--- %s 完成 ---", self.name)
return result
finally:
self.logger.info("%s 耗时 %.3f 秒", self.name, time.perf_counter() - start_time)
def log_step(self, step_name: str, message: str = ""):
"""记录步骤日志。"""
log_msg = f"[{step_name}]"