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
|
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||||
user_id=str(new_end_user.id), # 转换为字符串
|
user_id=str(new_end_user.id), # 转换为字符串
|
||||||
variables=payload.variables,
|
variables=payload.variables,
|
||||||
config= payload.agent_config,
|
config=agent_config,
|
||||||
web_search=payload.web_search,
|
web_search=payload.web_search,
|
||||||
memory=payload.memory,
|
memory=payload.memory,
|
||||||
storage_type=storage_type,
|
storage_type=storage_type,
|
||||||
@@ -565,11 +565,12 @@ async def chat(
|
|||||||
config = workflow_config_4_app_release(release)
|
config = workflow_config_4_app_release(release)
|
||||||
if payload.stream:
|
if payload.stream:
|
||||||
async def event_generator():
|
async def event_generator():
|
||||||
|
|
||||||
async for event in app_chat_service.workflow_chat_stream(
|
async for event in app_chat_service.workflow_chat_stream(
|
||||||
|
|
||||||
message=payload.message,
|
message=payload.message,
|
||||||
conversation_id=conversation.id, # 使用已创建的会话 ID
|
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||||
user_id=new_end_user.id, # 转换为字符串
|
user_id=end_user_id, # 转换为字符串
|
||||||
variables=payload.variables,
|
variables=payload.variables,
|
||||||
config=config,
|
config=config,
|
||||||
web_search=payload.web_search,
|
web_search=payload.web_search,
|
||||||
@@ -601,7 +602,7 @@ async def chat(
|
|||||||
|
|
||||||
message=payload.message,
|
message=payload.message,
|
||||||
conversation_id=conversation.id, # 使用已创建的会话 ID
|
conversation_id=conversation.id, # 使用已创建的会话 ID
|
||||||
user_id=new_end_user.id, # 转换为字符串
|
user_id=end_user_id, # 转换为字符串
|
||||||
variables=payload.variables,
|
variables=payload.variables,
|
||||||
config=config,
|
config=config,
|
||||||
web_search=payload.web_search,
|
web_search=payload.web_search,
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ class AppChatService:
|
|||||||
config: WorkflowConfig,
|
config: WorkflowConfig,
|
||||||
app_id: uuid.UUID,
|
app_id: uuid.UUID,
|
||||||
workspace_id: uuid.UUID,
|
workspace_id: uuid.UUID,
|
||||||
user_id: Optional[str] = None,
|
user_id: str = None,
|
||||||
variables: Optional[Dict[str, Any]] = None,
|
variables: Optional[Dict[str, Any]] = None,
|
||||||
web_search: bool = False,
|
web_search: bool = False,
|
||||||
memory: bool = True,
|
memory: bool = True,
|
||||||
|
|||||||
@@ -8,9 +8,11 @@ import uuid
|
|||||||
from typing import Dict, Any, Optional, Union
|
from typing import Dict, Any, Optional, Union
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from app.db import get_db_read
|
||||||
from app.models import AppRelease, WorkflowConfig
|
from app.models import AppRelease, WorkflowConfig
|
||||||
from app.models.agent_app_config_model import AgentConfig
|
from app.models.agent_app_config_model import AgentConfig
|
||||||
from app.models.multi_agent_model import MultiAgentConfig
|
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]]:
|
def model_parameters_to_dict(model_parameters: Any) -> Optional[Dict[str, Any]]:
|
||||||
@@ -65,6 +67,7 @@ def dict_to_model_parameters(data: Optional[Dict[str, Any]]) -> Optional[Any]:
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class AgentConfigProxy:
|
class AgentConfigProxy:
|
||||||
"""Proxy class for AgentConfig (legacy compatibility)"""
|
"""Proxy class for AgentConfig (legacy compatibility)"""
|
||||||
|
|
||||||
@@ -78,8 +81,7 @@ class AgentConfigProxy:
|
|||||||
self.default_model_config_id = release.default_model_config_id
|
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
|
config_dict = release.config
|
||||||
|
|
||||||
agent_config = AgentConfig(
|
agent_config = AgentConfig(
|
||||||
@@ -95,11 +97,10 @@ def agent_config_4_app_release(release: AppRelease ) -> AgentConfig:
|
|||||||
|
|
||||||
return agent_config
|
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
|
config_dict = release.config
|
||||||
|
|
||||||
|
|
||||||
agent_config = MultiAgentConfig(
|
agent_config = MultiAgentConfig(
|
||||||
app_id=release.app_id,
|
app_id=release.app_id,
|
||||||
default_model_config_id=release.default_model_config_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
|
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
|
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(
|
config = WorkflowConfig(
|
||||||
id=release.id,
|
id=source_config_id,
|
||||||
app_id=release.app_id,
|
app_id=release.app_id,
|
||||||
nodes=config_dict.get("nodes", []),
|
nodes=config_dict.get("nodes", []),
|
||||||
edges=config_dict.get("edges", []),
|
edges=config_dict.get("edges", []),
|
||||||
variables=config_dict.get("variables", []),
|
variables=config_dict.get("variables", []),
|
||||||
execution_config=config_dict.get("execution_config", {}),
|
execution_config=config_dict.get("execution_config", {}),
|
||||||
triggers=config_dict.get("triggers", [])
|
triggers=config_dict.get("triggers", [])
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def dict_to_multi_agent_config(config_dict: Dict[str, Any], app_id: Optional[uuid.UUID] = None):
|
def dict_to_multi_agent_config(config_dict: Dict[str, Any], app_id: Optional[uuid.UUID] = None):
|
||||||
"""Convert dict to MultiAgentConfig model object
|
"""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),
|
"id": str(agent_config.id),
|
||||||
"app_id": str(agent_config.app_id),
|
"app_id": str(agent_config.app_id),
|
||||||
"system_prompt": agent_config.system_prompt,
|
"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,
|
"model_parameters": agent_config.model_parameters,
|
||||||
"knowledge_retrieval": agent_config.knowledge_retrieval,
|
"knowledge_retrieval": agent_config.knowledge_retrieval,
|
||||||
"memory": agent_config.memory,
|
"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,
|
"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
|
"updated_at": workflow_config.updated_at.isoformat() if workflow_config.updated_at else None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user