Merge pull request #120 from SuanmoSuanyangTechnology/feature/workflow-release
fix(workflow): fix execution record insertion failure in released app
This commit is contained in:
@@ -466,7 +466,7 @@ async def chat(
|
||||
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||
user_id=str(new_end_user.id), # 转换为字符串
|
||||
variables=payload.variables,
|
||||
config= payload.agent_config,
|
||||
config=agent_config,
|
||||
web_search=payload.web_search,
|
||||
memory=payload.memory,
|
||||
storage_type=storage_type,
|
||||
@@ -565,11 +565,12 @@ async def chat(
|
||||
config = workflow_config_4_app_release(release)
|
||||
if payload.stream:
|
||||
async def event_generator():
|
||||
|
||||
async for event in app_chat_service.workflow_chat_stream(
|
||||
|
||||
message=payload.message,
|
||||
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||
user_id=new_end_user.id, # 转换为字符串
|
||||
user_id=end_user_id, # 转换为字符串
|
||||
variables=payload.variables,
|
||||
config=config,
|
||||
web_search=payload.web_search,
|
||||
@@ -601,7 +602,7 @@ async def chat(
|
||||
|
||||
message=payload.message,
|
||||
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||
user_id=new_end_user.id, # 转换为字符串
|
||||
user_id=end_user_id, # 转换为字符串
|
||||
variables=payload.variables,
|
||||
config=config,
|
||||
web_search=payload.web_search,
|
||||
|
||||
@@ -558,7 +558,7 @@ class AppChatService:
|
||||
config: WorkflowConfig,
|
||||
app_id: uuid.UUID,
|
||||
workspace_id: uuid.UUID,
|
||||
user_id: Optional[str] = None,
|
||||
user_id: str = None,
|
||||
variables: Optional[Dict[str, Any]] = None,
|
||||
web_search: bool = False,
|
||||
memory: bool = True,
|
||||
|
||||
@@ -8,9 +8,11 @@ import uuid
|
||||
from typing import Dict, Any, Optional, Union
|
||||
from datetime import datetime
|
||||
|
||||
from app.db import get_db_read
|
||||
from app.models import AppRelease, WorkflowConfig
|
||||
from app.models.agent_app_config_model import AgentConfig
|
||||
from app.models.multi_agent_model import MultiAgentConfig
|
||||
from app.repositories.workflow_repository import WorkflowConfigRepository
|
||||
|
||||
|
||||
def model_parameters_to_dict(model_parameters: Any) -> Optional[Dict[str, Any]]:
|
||||
@@ -24,18 +26,18 @@ def model_parameters_to_dict(model_parameters: Any) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
if model_parameters is None:
|
||||
return None
|
||||
|
||||
|
||||
if isinstance(model_parameters, dict):
|
||||
return model_parameters
|
||||
|
||||
|
||||
# Pydantic v2
|
||||
if hasattr(model_parameters, 'model_dump'):
|
||||
return model_parameters.model_dump()
|
||||
|
||||
|
||||
# Pydantic v1
|
||||
if hasattr(model_parameters, 'dict'):
|
||||
return model_parameters.dict()
|
||||
|
||||
|
||||
# 其他情况尝试转换
|
||||
try:
|
||||
return dict(model_parameters)
|
||||
@@ -54,17 +56,18 @@ def dict_to_model_parameters(data: Optional[Dict[str, Any]]) -> Optional[Any]:
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
|
||||
from app.schemas import ModelParameters
|
||||
|
||||
|
||||
if isinstance(data, ModelParameters):
|
||||
return data
|
||||
|
||||
|
||||
if isinstance(data, dict):
|
||||
return ModelParameters(**data)
|
||||
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class AgentConfigProxy:
|
||||
"""Proxy class for AgentConfig (legacy compatibility)"""
|
||||
|
||||
@@ -78,8 +81,7 @@ class AgentConfigProxy:
|
||||
self.default_model_config_id = release.default_model_config_id
|
||||
|
||||
|
||||
def agent_config_4_app_release(release: AppRelease ) -> AgentConfig:
|
||||
|
||||
def agent_config_4_app_release(release: AppRelease) -> AgentConfig:
|
||||
config_dict = release.config
|
||||
|
||||
agent_config = AgentConfig(
|
||||
@@ -95,11 +97,10 @@ def agent_config_4_app_release(release: AppRelease ) -> AgentConfig:
|
||||
|
||||
return agent_config
|
||||
|
||||
def multi_agent_config_4_app_release(release: AppRelease ) -> MultiAgentConfig:
|
||||
|
||||
def multi_agent_config_4_app_release(release: AppRelease) -> MultiAgentConfig:
|
||||
config_dict = release.config
|
||||
|
||||
|
||||
agent_config = MultiAgentConfig(
|
||||
app_id=release.app_id,
|
||||
default_model_config_id=release.default_model_config_id,
|
||||
@@ -116,24 +117,26 @@ def multi_agent_config_4_app_release(release: AppRelease ) -> MultiAgentConfig:
|
||||
|
||||
return agent_config
|
||||
|
||||
def workflow_config_4_app_release(release: AppRelease ) -> WorkflowConfig:
|
||||
|
||||
def workflow_config_4_app_release(release: AppRelease) -> WorkflowConfig:
|
||||
config_dict = release.config
|
||||
|
||||
with get_db_read() as db:
|
||||
source_config = WorkflowConfigRepository(db).get_by_app_id(release.app_id)
|
||||
source_config_id = source_config.id
|
||||
|
||||
config = WorkflowConfig(
|
||||
id=release.id,
|
||||
id=source_config_id,
|
||||
app_id=release.app_id,
|
||||
nodes=config_dict.get("nodes", []),
|
||||
edges=config_dict.get("edges", []),
|
||||
variables=config_dict.get("variables", []),
|
||||
execution_config=config_dict.get("execution_config", {}),
|
||||
triggers=config_dict.get("triggers", [])
|
||||
|
||||
)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def dict_to_multi_agent_config(config_dict: Dict[str, Any], app_id: Optional[uuid.UUID] = None):
|
||||
"""Convert dict to MultiAgentConfig model object
|
||||
|
||||
@@ -276,7 +279,8 @@ def agent_config_to_dict(agent_config) -> Dict[str, Any]:
|
||||
"id": str(agent_config.id),
|
||||
"app_id": str(agent_config.app_id),
|
||||
"system_prompt": agent_config.system_prompt,
|
||||
"default_model_config_id": str(agent_config.default_model_config_id) if agent_config.default_model_config_id else None,
|
||||
"default_model_config_id": str(
|
||||
agent_config.default_model_config_id) if agent_config.default_model_config_id else None,
|
||||
"model_parameters": agent_config.model_parameters,
|
||||
"knowledge_retrieval": agent_config.knowledge_retrieval,
|
||||
"memory": agent_config.memory,
|
||||
@@ -338,6 +342,3 @@ def workflow_config_to_dict(workflow_config) -> Dict[str, Any]:
|
||||
"created_at": workflow_config.created_at.isoformat() if workflow_config.created_at else None,
|
||||
"updated_at": workflow_config.updated_at.isoformat() if workflow_config.updated_at else None
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user