Add workflow support and enhance runtime configuration in models and services
- Introduce RuntimeModelResource and RuntimeKnowledgeBase classes to manage workflow resources. - Update AssistantConfig to include workflow_model_resources and workflow_knowledge_bases for better integration. - Refactor validation and processing logic in routes and services to accommodate workflow types. - Implement dynamic variable support for workflow assistants and enhance graph normalization. - Add ToolExecutor for reusable tool execution across different assistant types. - Update various services to ensure compatibility with new workflow features and improve error handling.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import uuid
|
||||
|
||||
from db.models import (
|
||||
Assistant,
|
||||
AssistantModelBinding,
|
||||
InterfaceDefinition,
|
||||
KnowledgeBase,
|
||||
@@ -20,6 +21,7 @@ from services.auth import require_admin
|
||||
from services.interface_catalog import validate_fields
|
||||
from services.masking import mask_secrets, merge_secrets
|
||||
from services.model_resource_tester import test_model_resource
|
||||
from services.node_specs import graph_references
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -102,6 +104,14 @@ async def _clear_incompatible_references(
|
||||
) -> None:
|
||||
if capability == resource.capability:
|
||||
return
|
||||
workflows = (
|
||||
await session.execute(select(Assistant).where(Assistant.type == "workflow"))
|
||||
).scalars().all()
|
||||
if any(
|
||||
resource.id in graph_references(assistant.graph or {})["model_resources"]
|
||||
for assistant in workflows
|
||||
):
|
||||
raise HTTPException(409, "模型资源正被 Workflow 节点引用,不能修改能力类型")
|
||||
await session.execute(
|
||||
delete(AssistantModelBinding).where(
|
||||
AssistantModelBinding.model_resource_id == resource.id
|
||||
@@ -263,6 +273,14 @@ async def delete_model_resource(
|
||||
).scalar_one_or_none()
|
||||
if in_use:
|
||||
raise HTTPException(409, "该模型资源仍被助手引用")
|
||||
workflows = (
|
||||
await session.execute(select(Assistant).where(Assistant.type == "workflow"))
|
||||
).scalars().all()
|
||||
if any(
|
||||
resource_id in graph_references(assistant.graph or {})["model_resources"]
|
||||
for assistant in workflows
|
||||
):
|
||||
raise HTTPException(409, "该模型资源仍被 Workflow 节点引用")
|
||||
await session.delete(row)
|
||||
await session.commit()
|
||||
return {"ok": True}
|
||||
|
||||
Reference in New Issue
Block a user