浏览代码

add recommended rag plugin endpoint

tags/2.0.0-beta.1
jyong 2 个月前
父节点
当前提交
d94e03c72b

+ 3
- 0
api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py 查看文件

pipeline=pipeline, node_id=node_id, user_inputs=inputs, account=current_user pipeline=pipeline, node_id=node_id, user_inputs=inputs, account=current_user
) )


if workflow_node_execution is None:
raise ValueError("Workflow node execution not found")

return workflow_node_execution return workflow_node_execution





+ 3
- 3
api/fields/workflow_run_fields.py 查看文件

"created_by_account": fields.Nested(simple_account_fields, attribute="created_by_account", allow_null=True), "created_by_account": fields.Nested(simple_account_fields, attribute="created_by_account", allow_null=True),
"created_by_end_user": fields.Nested(simple_end_user_fields, attribute="created_by_end_user", allow_null=True), "created_by_end_user": fields.Nested(simple_end_user_fields, attribute="created_by_end_user", allow_null=True),
"finished_at": TimestampField, "finished_at": TimestampField,
"inputs_truncated": fields.Boolean,
"outputs_truncated": fields.Boolean,
"process_data_truncated": fields.Boolean,
# "inputs_truncated": fields.Boolean,
# "outputs_truncated": fields.Boolean,
# "process_data_truncated": fields.Boolean,
} }


workflow_run_node_execution_list_fields = { workflow_run_node_execution_list_fields = {

+ 20
- 6
api/services/rag_pipeline/rag_pipeline.py 查看文件



from flask_login import current_user from flask_login import current_user
from sqlalchemy import func, or_, select from sqlalchemy import func, or_, select
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, sessionmaker


import contexts import contexts
from configs import dify_config from configs import dify_config
DatasourceErrorEvent, DatasourceErrorEvent,
DatasourceProcessingEvent, DatasourceProcessingEvent,
) )
from core.repositories.factory import DifyCoreRepositoryFactory
from core.repositories.sqlalchemy_workflow_node_execution_repository import SQLAlchemyWorkflowNodeExecutionRepository from core.repositories.sqlalchemy_workflow_node_execution_repository import SQLAlchemyWorkflowNodeExecutionRepository
from core.variables.variables import Variable from core.variables.variables import Variable
from core.workflow.entities.variable_pool import VariablePool from core.workflow.entities.variable_pool import VariablePool
WorkflowRun, WorkflowRun,
WorkflowType, WorkflowType,
) )
from repositories.factory import DifyAPIRepositoryFactory
from services.dataset_service import DatasetService from services.dataset_service import DatasetService
from services.datasource_provider_service import DatasourceProviderService from services.datasource_provider_service import DatasourceProviderService
from services.entities.knowledge_entities.rag_pipeline_entities import ( from services.entities.knowledge_entities.rag_pipeline_entities import (




class RagPipelineService: class RagPipelineService:


def __init__(self, session_maker: sessionmaker | None = None):
"""Initialize RagPipelineService with repository dependencies."""
if session_maker is None:
session_maker = sessionmaker(bind=db.engine, expire_on_commit=False)
self._node_execution_service_repo = DifyAPIRepositoryFactory.create_api_workflow_node_execution_repository(
session_maker
)

@classmethod @classmethod
def get_pipeline_templates(cls, type: str = "built-in", language: str = "en-US") -> dict: def get_pipeline_templates(cls, type: str = "built-in", language: str = "en-US") -> dict:
if type == "built-in": if type == "built-in":


def run_draft_workflow_node( def run_draft_workflow_node(
self, pipeline: Pipeline, node_id: str, user_inputs: dict, account: Account self, pipeline: Pipeline, node_id: str, user_inputs: dict, account: Account
) -> WorkflowNodeExecutionModel:
) -> WorkflowNodeExecutionModel | None:
""" """
Run draft workflow node Run draft workflow node
""" """
workflow_node_execution.workflow_id = draft_workflow.id workflow_node_execution.workflow_id = draft_workflow.id


# Create repository and save the node execution # Create repository and save the node execution
repository = SQLAlchemyWorkflowNodeExecutionRepository(
repository = DifyCoreRepositoryFactory.create_workflow_node_execution_repository(
session_factory=db.engine, session_factory=db.engine,
user=account, user=account,
app_id=pipeline.id, app_id=pipeline.id,
repository.save(workflow_node_execution) repository.save(workflow_node_execution)


# Convert node_execution to WorkflowNodeExecution after save # Convert node_execution to WorkflowNodeExecution after save
workflow_node_execution_db_model = repository.to_db_model(workflow_node_execution)
workflow_node_execution_db_model = self._node_execution_service_repo.get_execution_by_id(workflow_node_execution.id)


with Session(bind=db.engine) as session, session.begin(): with Session(bind=db.engine) as session, session.begin():
draft_var_saver = DraftVariableSaver( draft_var_saver = DraftVariableSaver(
session=session, session=session,
app_id=pipeline.id, app_id=pipeline.id,
node_id=workflow_node_execution_db_model.node_id,
node_type=NodeType(workflow_node_execution_db_model.node_type),
node_id=workflow_node_execution.node_id,
node_type=NodeType(workflow_node_execution.node_type),
enclosing_node_id=enclosing_node_id, enclosing_node_id=enclosing_node_id,
node_execution_id=workflow_node_execution.id, node_execution_id=workflow_node_execution.id,
user=account,
) )
draft_var_saver.save( draft_var_saver.save(
process_data=workflow_node_execution.process_data, process_data=workflow_node_execution.process_data,

正在加载...
取消
保存