mirror of
https://github.com/langgenius/dify.git
synced 2026-04-26 10:16:40 +08:00
fix(datasource): add datasource icon in tracing panel
This commit is contained in:
parent
c8d60f372d
commit
aa670c8982
@ -1,5 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from core.datasource.__base.datasource_runtime import DatasourceRuntime
|
from core.datasource.__base.datasource_runtime import DatasourceRuntime
|
||||||
from core.datasource.entities.datasource_entities import (
|
from core.datasource.entities.datasource_entities import (
|
||||||
DatasourceEntity,
|
DatasourceEntity,
|
||||||
@ -10,14 +11,17 @@ from core.datasource.entities.datasource_entities import (
|
|||||||
class DatasourcePlugin(ABC):
|
class DatasourcePlugin(ABC):
|
||||||
entity: DatasourceEntity
|
entity: DatasourceEntity
|
||||||
runtime: DatasourceRuntime
|
runtime: DatasourceRuntime
|
||||||
|
icon: str
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
entity: DatasourceEntity,
|
entity: DatasourceEntity,
|
||||||
runtime: DatasourceRuntime,
|
runtime: DatasourceRuntime,
|
||||||
|
icon: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.entity = entity
|
self.entity = entity
|
||||||
self.runtime = runtime
|
self.runtime = runtime
|
||||||
|
self.icon = icon
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def datasource_provider_type(self) -> str:
|
def datasource_provider_type(self) -> str:
|
||||||
@ -30,4 +34,8 @@ class DatasourcePlugin(ABC):
|
|||||||
return self.__class__(
|
return self.__class__(
|
||||||
entity=self.entity.model_copy(),
|
entity=self.entity.model_copy(),
|
||||||
runtime=runtime,
|
runtime=runtime,
|
||||||
|
icon=self.icon,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_icon_url(self, tenant_id: str) -> str:
|
||||||
|
return f"{dify_config.CONSOLE_API_URL}/console/api/workspaces/current/plugin/icon?tenant_id={tenant_id}&filename={self.icon}" # noqa: E501
|
||||||
|
|||||||
@ -8,7 +8,6 @@ from core.datasource.entities.datasource_entities import (
|
|||||||
|
|
||||||
class LocalFileDatasourcePlugin(DatasourcePlugin):
|
class LocalFileDatasourcePlugin(DatasourcePlugin):
|
||||||
tenant_id: str
|
tenant_id: str
|
||||||
icon: str
|
|
||||||
plugin_unique_identifier: str
|
plugin_unique_identifier: str
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -19,10 +18,12 @@ class LocalFileDatasourcePlugin(DatasourcePlugin):
|
|||||||
icon: str,
|
icon: str,
|
||||||
plugin_unique_identifier: str,
|
plugin_unique_identifier: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(entity, runtime)
|
super().__init__(entity, runtime, icon)
|
||||||
self.tenant_id = tenant_id
|
self.tenant_id = tenant_id
|
||||||
self.icon = icon
|
|
||||||
self.plugin_unique_identifier = plugin_unique_identifier
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
def datasource_provider_type(self) -> str:
|
def datasource_provider_type(self) -> str:
|
||||||
return DatasourceProviderType.LOCAL_FILE
|
return DatasourceProviderType.LOCAL_FILE
|
||||||
|
|
||||||
|
def get_icon_url(self, tenant_id: str) -> str:
|
||||||
|
return self.icon
|
||||||
|
|||||||
@ -15,7 +15,6 @@ from core.plugin.impl.datasource import PluginDatasourceManager
|
|||||||
|
|
||||||
class OnlineDocumentDatasourcePlugin(DatasourcePlugin):
|
class OnlineDocumentDatasourcePlugin(DatasourcePlugin):
|
||||||
tenant_id: str
|
tenant_id: str
|
||||||
icon: str
|
|
||||||
plugin_unique_identifier: str
|
plugin_unique_identifier: str
|
||||||
entity: DatasourceEntity
|
entity: DatasourceEntity
|
||||||
runtime: DatasourceRuntime
|
runtime: DatasourceRuntime
|
||||||
@ -28,9 +27,8 @@ class OnlineDocumentDatasourcePlugin(DatasourcePlugin):
|
|||||||
icon: str,
|
icon: str,
|
||||||
plugin_unique_identifier: str,
|
plugin_unique_identifier: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(entity, runtime)
|
super().__init__(entity, runtime, icon)
|
||||||
self.tenant_id = tenant_id
|
self.tenant_id = tenant_id
|
||||||
self.icon = icon
|
|
||||||
self.plugin_unique_identifier = plugin_unique_identifier
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
def get_online_document_pages(
|
def get_online_document_pages(
|
||||||
|
|||||||
@ -15,7 +15,6 @@ from core.plugin.impl.datasource import PluginDatasourceManager
|
|||||||
|
|
||||||
class OnlineDriveDatasourcePlugin(DatasourcePlugin):
|
class OnlineDriveDatasourcePlugin(DatasourcePlugin):
|
||||||
tenant_id: str
|
tenant_id: str
|
||||||
icon: str
|
|
||||||
plugin_unique_identifier: str
|
plugin_unique_identifier: str
|
||||||
entity: DatasourceEntity
|
entity: DatasourceEntity
|
||||||
runtime: DatasourceRuntime
|
runtime: DatasourceRuntime
|
||||||
@ -28,9 +27,8 @@ class OnlineDriveDatasourcePlugin(DatasourcePlugin):
|
|||||||
icon: str,
|
icon: str,
|
||||||
plugin_unique_identifier: str,
|
plugin_unique_identifier: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(entity, runtime)
|
super().__init__(entity, runtime, icon)
|
||||||
self.tenant_id = tenant_id
|
self.tenant_id = tenant_id
|
||||||
self.icon = icon
|
|
||||||
self.plugin_unique_identifier = plugin_unique_identifier
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
def online_drive_browse_files(
|
def online_drive_browse_files(
|
||||||
|
|||||||
@ -13,7 +13,6 @@ from core.plugin.impl.datasource import PluginDatasourceManager
|
|||||||
|
|
||||||
class WebsiteCrawlDatasourcePlugin(DatasourcePlugin):
|
class WebsiteCrawlDatasourcePlugin(DatasourcePlugin):
|
||||||
tenant_id: str
|
tenant_id: str
|
||||||
icon: str
|
|
||||||
plugin_unique_identifier: str
|
plugin_unique_identifier: str
|
||||||
entity: DatasourceEntity
|
entity: DatasourceEntity
|
||||||
runtime: DatasourceRuntime
|
runtime: DatasourceRuntime
|
||||||
@ -26,9 +25,8 @@ class WebsiteCrawlDatasourcePlugin(DatasourcePlugin):
|
|||||||
icon: str,
|
icon: str,
|
||||||
plugin_unique_identifier: str,
|
plugin_unique_identifier: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(entity, runtime)
|
super().__init__(entity, runtime, icon)
|
||||||
self.tenant_id = tenant_id
|
self.tenant_id = tenant_id
|
||||||
self.icon = icon
|
|
||||||
self.plugin_unique_identifier = plugin_unique_identifier
|
self.plugin_unique_identifier = plugin_unique_identifier
|
||||||
|
|
||||||
def get_website_crawl(
|
def get_website_crawl(
|
||||||
|
|||||||
@ -75,14 +75,17 @@ class DatasourceNode(Node):
|
|||||||
|
|
||||||
node_data = self._node_data
|
node_data = self._node_data
|
||||||
variable_pool = self.graph_runtime_state.variable_pool
|
variable_pool = self.graph_runtime_state.variable_pool
|
||||||
datasource_type = variable_pool.get(["sys", SystemVariableKey.DATASOURCE_TYPE.value])
|
datasource_type_segement = variable_pool.get(["sys", SystemVariableKey.DATASOURCE_TYPE.value])
|
||||||
if not datasource_type:
|
if not datasource_type_segement:
|
||||||
raise DatasourceNodeError("Datasource type is not set")
|
raise DatasourceNodeError("Datasource type is not set")
|
||||||
datasource_type = datasource_type.value
|
datasource_type = str(datasource_type_segement.value) if datasource_type_segement.value else None
|
||||||
datasource_info = variable_pool.get(["sys", SystemVariableKey.DATASOURCE_INFO.value])
|
datasource_info_segement = variable_pool.get(["sys", SystemVariableKey.DATASOURCE_INFO.value])
|
||||||
if not datasource_info:
|
if not datasource_info_segement:
|
||||||
raise DatasourceNodeError("Datasource info is not set")
|
raise DatasourceNodeError("Datasource info is not set")
|
||||||
datasource_info = datasource_info.value
|
datasource_info_value = datasource_info_segement.value
|
||||||
|
if not isinstance(datasource_info_value, dict):
|
||||||
|
raise DatasourceNodeError("Invalid datasource info format")
|
||||||
|
datasource_info: dict[str, Any] = datasource_info_value
|
||||||
# get datasource runtime
|
# get datasource runtime
|
||||||
try:
|
try:
|
||||||
from core.datasource.datasource_manager import DatasourceManager
|
from core.datasource.datasource_manager import DatasourceManager
|
||||||
@ -96,6 +99,7 @@ class DatasourceNode(Node):
|
|||||||
tenant_id=self.tenant_id,
|
tenant_id=self.tenant_id,
|
||||||
datasource_type=DatasourceProviderType.value_of(datasource_type),
|
datasource_type=DatasourceProviderType.value_of(datasource_type),
|
||||||
)
|
)
|
||||||
|
datasource_info["icon"] = datasource_runtime.get_icon_url(self.tenant_id)
|
||||||
except DatasourceNodeError as e:
|
except DatasourceNodeError as e:
|
||||||
yield StreamCompletedEvent(
|
yield StreamCompletedEvent(
|
||||||
node_run_result=NodeRunResult(
|
node_run_result=NodeRunResult(
|
||||||
@ -123,7 +127,7 @@ class DatasourceNode(Node):
|
|||||||
tenant_id=self.tenant_id,
|
tenant_id=self.tenant_id,
|
||||||
provider=node_data.provider_name,
|
provider=node_data.provider_name,
|
||||||
plugin_id=node_data.plugin_id,
|
plugin_id=node_data.plugin_id,
|
||||||
credential_id=datasource_info.get("credential_id"),
|
credential_id=datasource_info.get("credential_id", ""),
|
||||||
)
|
)
|
||||||
match datasource_type:
|
match datasource_type:
|
||||||
case DatasourceProviderType.ONLINE_DOCUMENT:
|
case DatasourceProviderType.ONLINE_DOCUMENT:
|
||||||
@ -134,9 +138,9 @@ class DatasourceNode(Node):
|
|||||||
datasource_runtime.get_online_document_page_content(
|
datasource_runtime.get_online_document_page_content(
|
||||||
user_id=self.user_id,
|
user_id=self.user_id,
|
||||||
datasource_parameters=GetOnlineDocumentPageContentRequest(
|
datasource_parameters=GetOnlineDocumentPageContentRequest(
|
||||||
workspace_id=datasource_info.get("workspace_id"),
|
workspace_id=datasource_info.get("workspace_id", ""),
|
||||||
page_id=datasource_info.get("page").get("page_id"),
|
page_id=datasource_info.get("page", {}).get("page_id", ""),
|
||||||
type=datasource_info.get("page").get("type"),
|
type=datasource_info.get("page", {}).get("type", ""),
|
||||||
),
|
),
|
||||||
provider_type=datasource_type,
|
provider_type=datasource_type,
|
||||||
)
|
)
|
||||||
@ -154,7 +158,7 @@ class DatasourceNode(Node):
|
|||||||
datasource_runtime.online_drive_download_file(
|
datasource_runtime.online_drive_download_file(
|
||||||
user_id=self.user_id,
|
user_id=self.user_id,
|
||||||
request=OnlineDriveDownloadFileRequest(
|
request=OnlineDriveDownloadFileRequest(
|
||||||
id=datasource_info.get("id"),
|
id=datasource_info.get("id", ""),
|
||||||
bucket=datasource_info.get("bucket"),
|
bucket=datasource_info.get("bucket"),
|
||||||
),
|
),
|
||||||
provider_type=datasource_type,
|
provider_type=datasource_type,
|
||||||
|
|||||||
@ -834,7 +834,9 @@ class WorkflowNodeExecutionModel(Base): # This model is expected to have `offlo
|
|||||||
provider_type=tool_info["provider_type"],
|
provider_type=tool_info["provider_type"],
|
||||||
provider_id=tool_info["provider_id"],
|
provider_id=tool_info["provider_id"],
|
||||||
)
|
)
|
||||||
|
elif self.node_type == NodeType.DATASOURCE.value and "datasource_info" in self.execution_metadata_dict:
|
||||||
|
datasource_info = self.execution_metadata_dict["datasource_info"]
|
||||||
|
extras["icon"] = datasource_info["icon"]
|
||||||
return extras
|
return extras
|
||||||
|
|
||||||
def _get_offload_by_type(self, type_: ExecutionOffLoadType) -> Optional["WorkflowNodeExecutionOffload"]:
|
def _get_offload_by_type(self, type_: ExecutionOffLoadType) -> Optional["WorkflowNodeExecutionOffload"]:
|
||||||
|
|||||||
@ -7,7 +7,6 @@ from configs import dify_config
|
|||||||
from services.rag_pipeline.pipeline_template.database.database_retrieval import DatabasePipelineTemplateRetrieval
|
from services.rag_pipeline.pipeline_template.database.database_retrieval import DatabasePipelineTemplateRetrieval
|
||||||
from services.rag_pipeline.pipeline_template.pipeline_template_base import PipelineTemplateRetrievalBase
|
from services.rag_pipeline.pipeline_template.pipeline_template_base import PipelineTemplateRetrievalBase
|
||||||
from services.rag_pipeline.pipeline_template.pipeline_template_type import PipelineTemplateType
|
from services.rag_pipeline.pipeline_template.pipeline_template_type import PipelineTemplateType
|
||||||
from services.recommend_app.buildin.buildin_retrieval import BuildInRecommendAppRetrieval
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user