瀏覽代碼

fix: correct run history tracing sequence

tags/2.0.0-beta.1
Novice 2 月之前
父節點
當前提交
7896eeec5b
共有 1 個檔案被更改,包括 20 行新增19 行删除
  1. 20
    19
      api/services/rag_pipeline/rag_pipeline.py

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





class RagPipelineService: class RagPipelineService:


def __init__(self, session_maker: sessionmaker | None = None): def __init__(self, session_maker: sessionmaker | None = None):
"""Initialize RagPipelineService with repository dependencies.""" """Initialize RagPipelineService with repository dependencies."""
if session_maker is None: if session_maker is None:
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 = DifyCoreRepositoryFactory.create_workflow_node_execution_repository( repository = DifyCoreRepositoryFactory.create_workflow_node_execution_repository(
session_factory=db.engine, session_factory=db.engine,
user=account, user=account,
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 = self._node_execution_service_repo.get_execution_by_id(workflow_node_execution.id)
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(
) )


# Use the repository to get the node executions with ordering # Use the repository to get the node executions with ordering
order_config = OrderConfig(order_by=["index"], order_direction="desc")
order_config = OrderConfig(order_by=["created_at"], order_direction="asc")
node_executions = repository.get_db_models_by_workflow_run( node_executions = repository.get_db_models_by_workflow_run(
workflow_run_id=run_id, workflow_run_id=run_id,
order_config=order_config, order_config=order_config,
.order_by(PipelineRecommendedPlugin.position.asc()) .order_by(PipelineRecommendedPlugin.position.asc())
.all() .all()
) )
if not pipeline_recommended_plugins: if not pipeline_recommended_plugins:
return { return {
"installed_recommended_plugins": [], "installed_recommended_plugins": [],
"uninstalled_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( providers = BuiltinToolManageService.list_builtin_tools(
user_id=current_user.id,
tenant_id=current_user.current_tenant_id,
)
user_id=current_user.id,
tenant_id=current_user.current_tenant_id,
)
providers_map = {provider.plugin_id: provider.to_dict() for provider in providers} 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)
else: else:
plugin_manifest = plugin_manifests_map.get(plugin_id) plugin_manifest = plugin_manifests_map.get(plugin_id)
if plugin_manifest: 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,
})

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, "installed_recommended_plugins": installed_plugin_list,
"uninstalled_recommended_plugins": uninstalled_plugin_list, "uninstalled_recommended_plugins": uninstalled_plugin_list,
}
}

Loading…
取消
儲存