diff --git a/apps/application/flow/tools.py b/apps/application/flow/tools.py index e9806b80f31..d9907ebc9c9 100644 --- a/apps/application/flow/tools.py +++ b/apps/application/flow/tools.py @@ -11,6 +11,7 @@ import queue import re import threading +from functools import reduce from typing import Iterator from maxkb.const import CONFIG from django.http import StreamingHttpResponse @@ -435,8 +436,8 @@ async def anext_async(agen): target_source_node_mapping = { 'TOOL': {'tool-lib-node': lambda n: [n.get('properties').get('node_data').get('tool_lib_id')], - 'ai-chat-node': lambda n: [...([n.get('properties').get('node_data').get('mcp_tool_ids')] or []), - ...([n.get('properties').get('node_data').get('tool_ids')] or [])]}, + 'ai-chat-node': lambda n: [*([n.get('properties').get('node_data').get('mcp_tool_ids')] or []), + *([n.get('properties').get('node_data').get('tool_ids')] or [])]}, 'MODEL': {'ai-chat-node': lambda n: [n.get('properties').get('node_data').get('model_id')], 'question-node': lambda n: [n.get('properties').get('node_data').get('model_id')], 'speech-to-text-node': lambda n: [n.get('properties').get('node_data').get('stt_model_id')], @@ -488,14 +489,28 @@ def get_workflow_resource(workflow, node_handle): return [] -def get_instance_resource(instance, source_type, source_id, target_type, field_call_list): +application_instance_field_call_dict = { + 'TOOL': [lambda instance: instance.mcp_tool_ids or [], lambda instance: instance.tool_ids or []], + 'MODEL': [lambda instance: [instance.model_id] if instance.model_id else [], + lambda instance: [instance.tts_model_id] if instance.tts_model_id else [], + lambda instance: [instance.stt_model_id] if instance.stt_model_id else []] +} +knowledge_instance_field_call_dict = { + 'MODEL': [lambda instance: [instance.model_id] if instance.model_id else [], + lambda instance: [instance.tts_model_id] if instance.tts_model_id else [], + lambda instance: [instance.stt_model_id] if instance.stt_model_id else []], +} + + +def get_instance_resource(instance, source_type, source_id, instance_field_call_dict): response = [] from system_manage.models.resource_mapping import ResourceMapping - for field_call in field_call_list: - target_id = field_call(instance) - if target_id: - response.append(ResourceMapping(source_type=source_type, target_type=target_type, source_id=source_id, - target_id=target_id)) + for target_type, call_list in instance_field_call_dict.items(): + target_id_list = reduce(lambda x, y: [*x, *y], [call(instance) for call in call_list], []) + if target_id_list: + for target_id in target_id_list: + response.append(ResourceMapping(source_type=source_type, target_type=target_type, source_id=source_id, + target_id=target_id)) return response @@ -508,85 +523,12 @@ def save_workflow_mapping(workflow, source_type, source_id, other_resource_mappi resource_mapping_list = get_workflow_resource(workflow, get_node_handle_callback(source_type, source_id)) + resource_mapping_list += other_resource_mapping if resource_mapping_list: - resource_mapping_list += other_resource_mapping QuerySet(ResourceMapping).bulk_create( {(str(item.target_type) + str(item.target_id)): item for item in resource_mapping_list}.values()) -def save_simple_mapping(application, source_type, source_id): - """ - 保存应用资源映射关系 - - Args: - application: 应用对象 - source_type: 源类型 - source_id: 源ID - """ - from system_manage.models.resource_mapping import ResourceMapping - from django.db.models import QuerySet - from application.models import ApplicationKnowledgeMapping # 假设模型在此处定义 - from system_manage.models.resource_mapping import ResourceType - # 删除原有映射关系 - QuerySet(ResourceMapping).filter(source_type=source_type, source_id=source_id).delete() - - # 构建资源映射列表 - resource_mapping_list = [] - - # 定义模型ID字段映射 - model_fields = ['model_id', 'tts_model_id', 'stt_model_id'] - for field in model_fields: - model_id = getattr(application, field, None) - if model_id: - resource_mapping_list.append(ResourceMapping( - source_type=source_type, - target_type=ResourceType.MODEL, - source_id=source_id, - target_id=model_id - )) - - # 定义工具ID字段映射 - tool_fields = ['mcp_tool_ids', 'tool_ids'] - for field in tool_fields: - tool_ids = getattr(application, field, []) or [] - resource_mapping_list.extend([ - ResourceMapping( - source_type=source_type, - target_type=ResourceType.TOOL, - source_id=source_id, - target_id=tool_id - ) for tool_id in tool_ids if tool_id - ]) - - # 处理知识库映射 - knowledge_mappings = ApplicationKnowledgeMapping.objects.filter( - application_id=application.id - ) - resource_mapping_list.extend([ - ResourceMapping( - source_type=source_type, - target_type=ResourceType.KNOWLEDGE, - source_id=source_id, - target_id=km.knowledge_id - ) for km in knowledge_mappings - ]) - - # 处理应用ID映射 - application_ids = getattr(application, 'application_ids', []) or [] - resource_mapping_list.extend([ - ResourceMapping( - source_type=source_type, - target_type=ResourceType.APPLICATION, - source_id=source_id, - target_id=app_id - ) for app_id in application_ids if app_id - ]) - - # 批量创建资源映射 - if resource_mapping_list: - QuerySet(ResourceMapping).bulk_create(resource_mapping_list) - - def get_tool_id_list(workflow): _result = [] for node in workflow.get('nodes', []): diff --git a/apps/application/serializers/application.py b/apps/application/serializers/application.py index 404a6e37a17..4110e2a1120 100644 --- a/apps/application/serializers/application.py +++ b/apps/application/serializers/application.py @@ -30,7 +30,7 @@ from rest_framework.utils.formatting import lazy_format from application.flow.common import Workflow -from application.models.application import Application, ApplicationTypeChoices, ApplicationKnowledgeMapping, \ +from application.models.application import Application, ApplicationTypeChoices, \ ApplicationFolder, ApplicationVersion from application.models.application_access_token import ApplicationAccessToken from application.serializers.common import update_resource_mapping_by_application @@ -541,7 +541,9 @@ def insert_workflow(self, instance: Dict): @staticmethod def to_application_knowledge_mapping(application_id: str, knowledge_id: str): - return ApplicationKnowledgeMapping(id=uuid.uuid7(), application_id=application_id, knowledge_id=knowledge_id) + return ResourceMapping(id=uuid.uuid7(), source_id=application_id, target_id=knowledge_id, + source_type="APPLICATION", + target_type="KNOWLEDGE") def insert_simple(self, instance: Dict): self.is_valid(raise_exception=True) @@ -560,7 +562,7 @@ def insert_simple(self, instance: Dict): ApplicationAccessToken(application_id=application_model.id, access_token=hashlib.md5(str(uuid.uuid7()).encode()).hexdigest()[8:24]).save() # 插入关联数据 - QuerySet(ApplicationKnowledgeMapping).bulk_create(application_knowledge_mapping_model_list) + QuerySet(ResourceMapping).bulk_create(application_knowledge_mapping_model_list) return ApplicationCreateSerializer.ApplicationResponse(application_model).data @transaction.atomic @@ -785,7 +787,6 @@ def delete(self, with_valid=True): self.is_valid() application_id = self.data.get('application_id') QuerySet(ApplicationVersion).filter(application_id=application_id).delete() - QuerySet(ApplicationKnowledgeMapping).filter(application_id=application_id).delete() QuerySet(ResourceMapping).filter( Q(target_id=application_id) | Q(source_id=application_id) ).delete() @@ -884,7 +885,6 @@ def publish(self, instance, with_valid=True): application_access_token.save() else: access_token = application_access_token.access_token - update_resource_mapping_by_application(self.data.get("application_id")) del_application_access_token(access_token) return self.one(with_valid=False) @@ -921,6 +921,19 @@ def update_work_flow_model(instance): if 'name' in node_data: instance['name'] = node_data['name'] break + knowledge_node_list = ApplicationOperateSerializer.get_search_node(instance.get('work_flow')) + for knowledge_node in knowledge_node_list: + node_data = knowledge_node.get('properties').get('node_data') + # 全部知识库id + all_knowledge_id_list = node_data.get('all_knowledge_id_list') or [] + # 用户修改的知识库id + knowledge_id_list = node_data.get('knowledge_id_list') or [] + # 用户可以看到的知识库 + knowledge_list = node_data.get('knowledge_list') or [] + view_knowledge_id_list = [knowledge.get('id') for knowledge in knowledge_list] + other_knowledge_id_list = [knowledge_id for knowledge_id in all_knowledge_id_list if + not view_knowledge_id_list.__contains__(knowledge_id)] + node_data['knowledge_id_list'] = other_knowledge_id_list + knowledge_id_list @transaction.atomic def edit(self, instance: Dict, with_valid=True): @@ -972,19 +985,25 @@ def edit(self, instance: Dict, with_valid=True): if update_key in instance and instance.get(update_key) is not None: application.__setattr__(update_key, instance.get(update_key)) application.save() - + # 当前用户可修改关联的知识库列表 + application_knowledge_id_list = [str(knowledge.get('id')) for knowledge in + self.list_knowledge(with_valid=False)] + knowledge_id_list = [] if 'knowledge_id_list' in instance: - knowledge_id_list = instance.get('knowledge_id_list') # 当前用户可修改关联的知识库列表 application_knowledge_id_list = [str(knowledge.get('id')) for knowledge in self.list_knowledge(with_valid=False)] + knowledge_id_list = instance.get('knowledge_id_list') for knowledge_id in knowledge_id_list: if not application_knowledge_id_list.__contains__(knowledge_id): message = lazy_format(_('Unknown knowledge base id {dataset_id}, unable to associate'), dataset_id=knowledge_id) raise AppApiException(500, str(message)) - self.save_application_knowledge_mapping(application_knowledge_id_list, knowledge_id_list, application_id) + update_resource_mapping_by_application(application_id, + self.get_application_knowledge_mapping(application_knowledge_id_list, + knowledge_id_list, + application_id)) return self.one(with_valid=False) def update_template_workflow(self, instance: Dict, app: Application): @@ -1074,9 +1093,11 @@ def one(self, with_valid=True): knowledge_list = [] knowledge_id_list = [] if application.type == 'SIMPLE': - mapping_knowledge_list = QuerySet(ApplicationKnowledgeMapping).filter(application_id=application_id) - knowledge_list = [available_knowledge_dict.get(str(km.knowledge_id)) for km in mapping_knowledge_list if - available_knowledge_dict.__contains__(str(km.knowledge_id))] + mapping_knowledge_list = QuerySet(ResourceMapping).filter(source_id=application_id, + source_type="APPLICATION", + target_type="KNOWLEDGE") + knowledge_list = [available_knowledge_dict.get(str(km.target_id)) for km in mapping_knowledge_list if + available_knowledge_dict.__contains__(str(km.target_id))] knowledge_id_list = [k.get('id') for k in knowledge_list] else: self.update_knowledge_node(application.work_flow, available_knowledge_dict) @@ -1089,7 +1110,17 @@ def one(self, with_valid=True): def get_search_node(work_flow): if work_flow is None: return [] - return [node for node in work_flow.get('nodes', []) if node.get('type', '') == 'search-knowledge-node'] + response = [] + if 'nodes' in work_flow: + for node in work_flow.get('nodes'): + if node.get('type', '') == 'search-knowledge-node': + response.append(node) + if node.get('type') == 'loop-node': + r = ApplicationOperateSerializer.get_search_node( + node.get('properties', {}).get('node_data', {}).get('loop_body')) + for rn in r: + response.append(rn) + return response def update_knowledge_node(self, workflow, available_knowledge_dict): """ @@ -1143,14 +1174,39 @@ def list_knowledge(self, with_valid=True): def save_application_knowledge_mapping(application_knowledge_id_list, knowledge_id_list, application_id): # 需要排除已删除的数据集 knowledge_id_list = [knowledge.id for knowledge in QuerySet(Knowledge).filter(id__in=knowledge_id_list)] + # 删除已经关联的id - QuerySet(ApplicationKnowledgeMapping).filter(knowledge_id__in=application_knowledge_id_list, - application_id=application_id).delete() + QuerySet(ResourceMapping).filter(target_id__in=application_knowledge_id_list, + source_id=application_id, + source_type='APPLICATION', + target_type="KNOWLEDGE").delete() # 插入 - QuerySet(ApplicationKnowledgeMapping).bulk_create( - [ApplicationKnowledgeMapping(application_id=application_id, knowledge_id=knowledge_id) for knowledge_id in + QuerySet(ResourceMapping).bulk_create( + [ResourceMapping(source_id=application_id, target_id=knowledge_id, source_type='APPLICATION', + target_type="KNOWLEDGE") for knowledge_id in knowledge_id_list]) if len(knowledge_id_list) > 0 else None + @staticmethod + def get_application_knowledge_mapping(application_knowledge_id_list, knowledge_id_list, application_id): + """ + + @param application_knowledge_id_list: 当前应用可修改的知识库列表 + @param knowledge_id_list: 用户修改的知识库列表 + @param application_id: 应用id + @return: + """ + # 当前知识库和应用已关联列表 + knowledge_application_mapping_list = QuerySet(ResourceMapping).filter(source_id=application_id, + source_type='APPLICATION', + target_type="KNOWLEDGE", + ).exclude( + target_id__in=application_knowledge_id_list) + edit_knowledge_list = [ResourceMapping(source_id=application_id, target_id=knowledge_id, + source_type='APPLICATION', + target_type="KNOWLEDGE") + for knowledge_id in knowledge_id_list] + return list(knowledge_application_mapping_list) + edit_knowledge_list + def speech_to_text(self, instance, debug=True, with_valid=True): if with_valid: self.is_valid(raise_exception=True) diff --git a/apps/application/serializers/common.py b/apps/application/serializers/common.py index 275385fb544..ef0867feeee 100644 --- a/apps/application/serializers/common.py +++ b/apps/application/serializers/common.py @@ -13,9 +13,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ -from application.flow.tools import save_simple_mapping -from application.models import Application, ChatRecord, Chat, ApplicationVersion, ChatUserType, ApplicationTypeChoices, \ - ApplicationKnowledgeMapping +from application.models import Application, ChatRecord, Chat, ApplicationVersion, ChatUserType, ApplicationTypeChoices from application.serializers.application_chat import ChatCountSerializer from common.constants.cache_version import Cache_Version from common.database_model_manage.database_model_manage import DatabaseModelManage @@ -23,6 +21,7 @@ from knowledge.models import Document from models_provider.models import Model from models_provider.tools import get_model_credential +from system_manage.models.resource_mapping import ResourceMapping class ChatInfo: @@ -77,9 +76,10 @@ def get_application(self): raise ChatException(500, _("The application has not been published. Please use it after publishing.")) if application.type == ApplicationTypeChoices.SIMPLE.value: # 数据集id列表 - knowledge_id_list = [str(row.knowledge_id) for row in - QuerySet(ApplicationKnowledgeMapping).filter( - application_id=self.application_id)] + knowledge_id_list = [str(row.target_id) for row in + QuerySet(ResourceMapping).filter(source_id=self.application_id, + source_type='APPLICATION', + target_type='KNOWLEDGE')] # 需要排除的文档 exclude_document_id_list = [str(document.id) for document in @@ -116,18 +116,19 @@ def get_chat_user(self, asker=None): return self.chat_user def get_chat_user_group(self, asker=None): - chat_user = self.get_chat_user(asker=asker) + chat_user = self.get_chat_user(asker=asker) chat_user_id = chat_user.get('id') if not chat_user_id: - return [] + return [] user_group_relation_model = DatabaseModelManage.get_model("user_group_relation") if user_group_relation_model: return [{ - 'id': user_group_relation.group_id, - 'name': user_group_relation.group.name - } for user_group_relation in QuerySet(user_group_relation_model).select_related('group').filter(user_id=chat_user_id)] + 'id': user_group_relation.group_id, + 'name': user_group_relation.group.name + } for user_group_relation in + QuerySet(user_group_relation_model).select_related('group').filter(user_id=chat_user_id)] return [] def to_base_pipeline_manage_params(self): @@ -336,16 +337,19 @@ def get_cache(chat_id): return None -def update_resource_mapping_by_application(application_id: str): - from application.flow.tools import get_instance_resource, save_workflow_mapping +def update_resource_mapping_by_application(application_id: str, other_resource_mapping=None): + from application.flow.tools import get_instance_resource, save_workflow_mapping, \ + application_instance_field_call_dict from system_manage.models.resource_mapping import ResourceType + if other_resource_mapping is None: + other_resource_mapping = [] application = QuerySet(Application).filter(id=application_id).first() instance_mapping = get_instance_resource(application, ResourceType.APPLICATION, str(application.id), - ResourceType.MODEL, - [lambda i: i.tts_model_id, lambda i: i.stt_model_id, ]) + application_instance_field_call_dict) if application.type == 'WORK_FLOW': save_workflow_mapping(application.work_flow, ResourceType.APPLICATION, str(application_id), - instance_mapping) + instance_mapping + other_resource_mapping) return else: - save_simple_mapping(application, ResourceType.APPLICATION, str(application_id)) + save_workflow_mapping({}, ResourceType.APPLICATION, str(application_id), + instance_mapping + other_resource_mapping) diff --git a/apps/chat/serializers/chat.py b/apps/chat/serializers/chat.py index befab5d0009..712e0964850 100644 --- a/apps/chat/serializers/chat.py +++ b/apps/chat/serializers/chat.py @@ -28,7 +28,7 @@ from application.flow.i_step_node import WorkFlowPostHandler from application.flow.tools import to_stream_response_simple from application.flow.workflow_manage import WorkflowManage -from application.models import Application, ApplicationTypeChoices, ApplicationKnowledgeMapping, \ +from application.models import Application, ApplicationTypeChoices, \ ChatUserType, ApplicationChatUserStats, ApplicationAccessToken, ChatRecord, Chat, ApplicationVersion from application.serializers.application import ApplicationOperateSerializer from application.serializers.common import ChatInfo @@ -42,6 +42,7 @@ from maxkb.conf import PROJECT_DIR from models_provider.models import Model, Status from models_provider.tools import get_model_instance_by_model_workspace_id +from system_manage.models.resource_mapping import ResourceMapping class ChatMessagesSerializers(serializers.Serializer): @@ -470,9 +471,10 @@ def re_open_chat(self, chat_id: str): def re_open_chat_simple(self, chat_id, application): # 数据集id列表 - knowledge_id_list = [str(row.knowledge_id) for row in - QuerySet(ApplicationKnowledgeMapping).filter( - application_id=application.id)] + knowledge_id_list = [str(row.target_id) for row in + QuerySet(ResourceMapping).filter(source_id=str(application.id), + source_type='APPLICATION', + target_type='KNOWLEDGE')] # 需要排除的文档 exclude_document_id_list = [str(document.id) for document in @@ -547,9 +549,11 @@ def open_simple(self, application): chat_user_id = self.data.get("chat_user_id") chat_user_type = self.data.get("chat_user_type") debug = self.data.get("debug") - knowledge_id_list = [str(row.knowledge_id) for row in - QuerySet(ApplicationKnowledgeMapping).filter( - application_id=application_id)] + knowledge_id_list = [str(row.target_id) for row in + QuerySet(ResourceMapping).filter(source_id=str(application_id), + source_type='APPLICATION', + target_type='KNOWLEDGE')] + chat_id = str(uuid.uuid7()) ChatInfo(chat_id, chat_user_id, chat_user_type, knowledge_id_list, [str(document.id) for document in diff --git a/apps/knowledge/serializers/common.py b/apps/knowledge/serializers/common.py index 1980d186563..2f9f14d71c0 100644 --- a/apps/knowledge/serializers/common.py +++ b/apps/knowledge/serializers/common.py @@ -16,7 +16,7 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers -from application.flow.tools import save_workflow_mapping +from application.flow.tools import save_workflow_mapping, get_instance_resource, knowledge_instance_field_call_dict from common.config.embedding_config import ModelManage from common.db.search import native_search from common.db.sql_execute import sql_execute, update_execute @@ -281,20 +281,16 @@ def drop_knowledge_index(knowledge_id=None, document_id=None): def update_resource_mapping_by_knowledge(knowledge_id: str): knowledge = QuerySet(Knowledge).filter(id=knowledge_id).first() + instance_mapping = get_instance_resource(knowledge, ResourceType.KNOWLEDGE, str(knowledge.id), + knowledge_instance_field_call_dict) if knowledge.type == KnowledgeType.WORKFLOW: - knowledge_workflow_version = QuerySet(KnowledgeWorkflowVersion).filter( - knowledge_id=knowledge_id).order_by( + knowledge_workflow = QuerySet(KnowledgeWorkflow).filter( + id=knowledge_id).order_by( '-create_time')[0:1].first() - if knowledge_workflow_version: - other = ResourceMapping(source_type=ResourceType.KNOWLEDGE, target_type=ResourceType.MODEL, - source_id=knowledge.id, - target_id=knowledge.embedding_model_id) - save_workflow_mapping(knowledge_workflow_version.work_flow, ResourceType.KNOWLEDGE, - str(knowledge_id), [other]) + if knowledge_workflow: + save_workflow_mapping(knowledge_workflow.work_flow, ResourceType.KNOWLEDGE, + str(knowledge_id), instance_mapping) return - - QuerySet(ResourceMapping).filter(source_type=ResourceType.KNOWLEDGE, - source_id=knowledge.id).delete() - ResourceMapping(source_type=ResourceType.KNOWLEDGE, target_type=ResourceType.MODEL, - source_id=knowledge.id, - target_id=knowledge.embedding_model_id).save() + else: + save_workflow_mapping({}, ResourceType.KNOWLEDGE, + str(knowledge_id), instance_mapping) diff --git a/apps/knowledge/serializers/knowledge.py b/apps/knowledge/serializers/knowledge.py index 00614b9a50c..b895d0dfe95 100644 --- a/apps/knowledge/serializers/knowledge.py +++ b/apps/knowledge/serializers/knowledge.py @@ -22,7 +22,6 @@ from django.utils.translation import gettext_lazy as _ from rest_framework import serializers -from application.models import ApplicationKnowledgeMapping from common.config.embedding_config import VectorStore from common.database_model_manage.database_model_manage import DatabaseModelManage from common.db.search import native_search, get_dynamics_model, native_page_search @@ -368,7 +367,9 @@ def one(self): str( application_knowledge_mapping.application_id ) for application_knowledge_mapping in - QuerySet(ApplicationKnowledgeMapping).filter(knowledge_id=self.data.get('knowledge_id')) + QuerySet(ResourceMapping).filter(source_type='APPLICATION', + target_type='KNOWLEDGE', + target_id=self.data.get('knowledge_id')) ] )) } @@ -408,14 +409,19 @@ def edit(self, instance: Dict, select_one=True): ).format(knowledge_id=knowledge_id) ) - QuerySet(ApplicationKnowledgeMapping).filter( - application_id__in=application_knowledge_id_list, - knowledge_id=self.data.get("knowledge_id") + QuerySet(ResourceMapping).filter( + source_id__in=application_knowledge_id_list, + source_type='APPLICATION', + target_type='KNOWLEDGE', + target_id=self.data.get("knowledge_id") ).delete() # 插入 - QuerySet(ApplicationKnowledgeMapping).bulk_create([ - ApplicationKnowledgeMapping( - application_id=application_id, knowledge_id=self.data.get('knowledge_id') + QuerySet(ResourceMapping).bulk_create([ + ResourceMapping( + source_id=application_id, + source_type='APPLICATION', + target_type='KNOWLEDGE', + target_id=self.data.get('knowledge_id') ) for application_id in application_id_list ]) if len(application_id_list) > 0 else None knowledge.save() @@ -432,7 +438,6 @@ def delete(self): QuerySet(Paragraph).filter(knowledge=knowledge).delete() QuerySet(Problem).filter(knowledge=knowledge).delete() QuerySet(WorkspaceUserResourcePermission).filter(target=knowledge.id).delete() - QuerySet(ApplicationKnowledgeMapping).filter(knowledge_id=knowledge.id).delete() drop_knowledge_index(knowledge_id=knowledge.id) knowledge.delete() File.objects.filter( diff --git a/apps/system_manage/migrations/0005_resourcemapping.py b/apps/system_manage/migrations/0005_resourcemapping.py index 59f0cdb00f6..a6d07678a08 100644 --- a/apps/system_manage/migrations/0005_resourcemapping.py +++ b/apps/system_manage/migrations/0005_resourcemapping.py @@ -15,6 +15,7 @@ def get_initialization_resource_mapping(): from system_manage.models.resource_mapping import ResourceType from application.models import Application from knowledge.models import KnowledgeWorkflow + from application.flow.tools import application_instance_field_call_dict, knowledge_instance_field_call_dict resource_mapping_list = [] ids = list(Application.objects.values_list('id', flat=True)) for app_id in ids: @@ -24,8 +25,7 @@ def get_initialization_resource_mapping(): get_node_handle_callback(ResourceType.APPLICATION, application.id)) instance_mapping = get_instance_resource(application, ResourceType.APPLICATION, str(application.id), - ResourceType.MODEL, - [lambda i: i.tts_model_id, lambda i: i.stt_model_id, ]) + application_instance_field_call_dict) resource_mapping_list += workflow_mapping resource_mapping_list += instance_mapping except: @@ -42,8 +42,7 @@ def get_initialization_resource_mapping(): str(knowledge_workflow.knowledge_id))) resource_mapping_list += workflow_mapping instance_mapping = get_instance_resource(knowledge, ResourceType.KNOWLEDGE, str(knowledge.id), - ResourceType.MODEL, - [lambda i: i.embedding_model_id]) + knowledge_instance_field_call_dict) resource_mapping_list += instance_mapping except: