feat: improve ai workflow runtime observability

This commit is contained in:
2026-06-22 10:11:05 +08:00
parent 9515a4d121
commit d954279c9c
4 changed files with 245 additions and 66 deletions
@@ -225,11 +225,10 @@ class TextToSqlNode(BaseNode):
error='请输入要查询的问题',
)
if not model_id:
return NodeResult(
success=False,
error='请选择 LLM 模型',
)
from ai_platform.services.llm_service import LLMService
llm_service = LLMService(context.db_session)
model_id = await llm_service.resolve_chat_model_id(model_id)
# Step 1: 获取数据库 Schema
@@ -248,10 +247,7 @@ class TextToSqlNode(BaseNode):
# Step 2: 调用 LLM 生成 SQL
from datetime import datetime
from ai_platform.services.llm_service import LLMService
db_type = await self._get_db_type(db_connection)
llm_service = LLMService(context.db_session)
llm_result = None
use_function_calling = self.config.get('use_function_calling', True)
@@ -354,6 +350,7 @@ class TextToSqlNode(BaseNode):
tokens_used=response.total_tokens,
elapsed_time=elapsed_time,
metadata={
'model_id': str(model_id),
'model': response.model,
'thought': thought,
'suggested_next_node': 'db_sql',
@@ -404,13 +401,22 @@ class TextToSqlNode(BaseNode):
)
return NodeResult(success=False, error='请输入要查询的问题')
if not model_id:
import asyncio
from ai_platform.services.llm_service import LLMService
llm_service = LLMService(context.db_session)
try:
model_id = asyncio.get_event_loop().run_until_complete(
llm_service.resolve_chat_model_id(model_id)
)
except Exception as e:
error_message = str(e)
yield TextToSqlStreamEvent(
event_type='error',
content='请选择 LLM 模型',
content=error_message,
is_finished=True,
)
return NodeResult(success=False, error='请选择 LLM 模型')
return NodeResult(success=False, error=error_message)
# Step 1: 获取数据库 Schema
yield TextToSqlStreamEvent(
@@ -420,7 +426,6 @@ class TextToSqlNode(BaseNode):
table_relations = self.config.get('table_relations', []) # 手动指定的表关系
import asyncio
schema_context = asyncio.get_event_loop().run_until_complete(
self._get_schema_context(
db_connection,
@@ -449,13 +454,10 @@ class TextToSqlNode(BaseNode):
)
from datetime import datetime
from ai_platform.services.llm_service import LLMService
db_type = asyncio.get_event_loop().run_until_complete(
self._get_db_type(db_connection)
)
llm_service = LLMService()
accumulated_content = ''
total_tokens = 0
llm_result = None
@@ -566,6 +568,7 @@ class TextToSqlNode(BaseNode):
tokens_used=total_tokens,
elapsed_time=elapsed_time,
metadata={
'model_id': str(model_id),
'thought': thought,
'suggested_next_node': 'db_sql',
},