mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
Merge branch 'feat/rag-2' of https://github.com/langgenius/dify into feat/rag-2
This commit is contained in:
commit
1522fd50df
@ -11,6 +11,7 @@ from core.workflow.nodes.answer.answer_node import AnswerNode
|
|||||||
from core.workflow.nodes.base.node import Node
|
from core.workflow.nodes.base.node import Node
|
||||||
from core.workflow.nodes.base.template import Template
|
from core.workflow.nodes.base.template import Template
|
||||||
from core.workflow.nodes.end.end_node import EndNode
|
from core.workflow.nodes.end.end_node import EndNode
|
||||||
|
from core.workflow.nodes.knowledge_index import KnowledgeIndexNode
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -39,7 +40,7 @@ class ResponseSession:
|
|||||||
Raises:
|
Raises:
|
||||||
TypeError: If node is not an AnswerNode or EndNode
|
TypeError: If node is not an AnswerNode or EndNode
|
||||||
"""
|
"""
|
||||||
if not isinstance(node, AnswerNode | EndNode):
|
if not isinstance(node, AnswerNode | EndNode | KnowledgeIndexNode):
|
||||||
raise TypeError
|
raise TypeError
|
||||||
return cls(
|
return cls(
|
||||||
node_id=node.id,
|
node_id=node.id,
|
||||||
|
|||||||
@ -11,10 +11,11 @@ from core.rag.index_processor.index_processor_factory import IndexProcessorFacto
|
|||||||
from core.rag.retrieval.retrieval_methods import RetrievalMethod
|
from core.rag.retrieval.retrieval_methods import RetrievalMethod
|
||||||
from core.workflow.entities.variable_pool import VariablePool
|
from core.workflow.entities.variable_pool import VariablePool
|
||||||
from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus
|
from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus
|
||||||
from core.workflow.enums import ErrorStrategy, NodeType, SystemVariableKey
|
from core.workflow.enums import ErrorStrategy, NodeExecutionType, NodeType, SystemVariableKey
|
||||||
from core.workflow.node_events import NodeRunResult
|
from core.workflow.node_events import NodeRunResult
|
||||||
from core.workflow.nodes.base.entities import BaseNodeData, RetryConfig
|
from core.workflow.nodes.base.entities import BaseNodeData, RetryConfig
|
||||||
from core.workflow.nodes.base.node import Node
|
from core.workflow.nodes.base.node import Node
|
||||||
|
from core.workflow.nodes.base.template import Template
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from models.dataset import Dataset, Document, DocumentSegment
|
from models.dataset import Dataset, Document, DocumentSegment
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ default_retrieval_model = {
|
|||||||
class KnowledgeIndexNode(Node):
|
class KnowledgeIndexNode(Node):
|
||||||
_node_data: KnowledgeIndexNodeData
|
_node_data: KnowledgeIndexNodeData
|
||||||
node_type = NodeType.KNOWLEDGE_INDEX
|
node_type = NodeType.KNOWLEDGE_INDEX
|
||||||
|
execution_type = NodeExecutionType.RESPONSE
|
||||||
|
|
||||||
def init_node_data(self, data: Mapping[str, Any]) -> None:
|
def init_node_data(self, data: Mapping[str, Any]) -> None:
|
||||||
self._node_data = KnowledgeIndexNodeData.model_validate(data)
|
self._node_data = KnowledgeIndexNodeData.model_validate(data)
|
||||||
@ -181,3 +183,13 @@ class KnowledgeIndexNode(Node):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def version(cls) -> str:
|
def version(cls) -> str:
|
||||||
return "1"
|
return "1"
|
||||||
|
|
||||||
|
|
||||||
|
def get_streaming_template(self) -> Template:
|
||||||
|
"""
|
||||||
|
Get the template for streaming.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Template instance for this knowledge index node
|
||||||
|
"""
|
||||||
|
return Template(segments=[])
|
||||||
@ -1244,7 +1244,7 @@ class RagPipelineService:
|
|||||||
session.commit()
|
session.commit()
|
||||||
return workflow_node_execution_db_model
|
return workflow_node_execution_db_model
|
||||||
|
|
||||||
def get_recommended_plugins(self) -> list[dict]:
|
def get_recommended_plugins(self) -> dict:
|
||||||
# Query active recommended plugins
|
# Query active recommended plugins
|
||||||
pipeline_recommended_plugins = (
|
pipeline_recommended_plugins = (
|
||||||
db.session.query(PipelineRecommendedPlugin)
|
db.session.query(PipelineRecommendedPlugin)
|
||||||
@ -1254,26 +1254,40 @@ class RagPipelineService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not pipeline_recommended_plugins:
|
if not pipeline_recommended_plugins:
|
||||||
return []
|
return {
|
||||||
|
"installed_recommended_plugins": [],
|
||||||
|
"uninstalled_recommended_plugins": [],
|
||||||
|
}
|
||||||
|
|
||||||
# Batch fetch plugin manifests
|
# Batch fetch plugin manifests
|
||||||
plugin_ids = [plugin.plugin_id for plugin in pipeline_recommended_plugins]
|
plugin_ids = [plugin.plugin_id for plugin in pipeline_recommended_plugins]
|
||||||
|
providers = BuiltinToolManageService.list_builtin_tools(
|
||||||
|
user_id=current_user.id,
|
||||||
|
tenant_id=current_user.current_tenant_id,
|
||||||
|
)
|
||||||
|
providers_map = {provider.plugin_id: provider.to_dict() for provider in providers}
|
||||||
|
|
||||||
plugin_manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids)
|
plugin_manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids)
|
||||||
|
plugin_manifests_map = {manifest.plugin_id: manifest for manifest in plugin_manifests}
|
||||||
builtin_tools = BuiltinToolManageService.list_builtin_tools(
|
|
||||||
user_id=current_user.id,
|
installed_plugin_list = []
|
||||||
tenant_id=current_user.current_tenant_id,
|
uninstalled_plugin_list = []
|
||||||
)
|
for plugin_id in plugin_ids:
|
||||||
installed_plugin_ids = {tool.plugin_id for tool in builtin_tools}
|
if providers_map.get(plugin_id):
|
||||||
|
installed_plugin_list.append(providers_map.get(plugin_id))
|
||||||
|
else:
|
||||||
|
plugin_manifest = plugin_manifests_map.get(plugin_id)
|
||||||
|
if plugin_manifest:
|
||||||
|
uninstalled_plugin_list.append({
|
||||||
|
"plugin_id": plugin_id,
|
||||||
|
"name": plugin_manifest.name,
|
||||||
|
"icon": plugin_manifest.icon,
|
||||||
|
"plugin_unique_identifier": plugin_manifest.latest_package_identifier,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Build recommended plugins list
|
# Build recommended plugins list
|
||||||
return [
|
return {
|
||||||
{
|
"installed_recommended_plugins": installed_plugin_list,
|
||||||
"plugin_id": manifest.plugin_id,
|
"uninstalled_recommended_plugins": uninstalled_plugin_list,
|
||||||
"name": manifest.name,
|
}
|
||||||
"icon": manifest.icon,
|
|
||||||
"plugin_unique_identifier": manifest.latest_package_identifier,
|
|
||||||
"installed": manifest.plugin_id in installed_plugin_ids,
|
|
||||||
}
|
|
||||||
for manifest in plugin_manifests
|
|
||||||
]
|
|
||||||
Loading…
Reference in New Issue
Block a user