mirror of
https://github.com/langgenius/dify.git
synced 2025-11-17 20:05:16 +00:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
from collections.abc import Callable
|
|
from functools import wraps
|
|
|
|
from controllers.console.datasets.error import PipelineNotFoundError
|
|
from extensions.ext_database import db
|
|
from libs.login import current_account_with_tenant
|
|
from models.dataset import Pipeline
|
|
|
|
|
|
def get_rag_pipeline(
|
|
view: Callable | None = None,
|
|
):
|
|
def decorator(view_func):
|
|
@wraps(view_func)
|
|
def decorated_view(*args, **kwargs):
|
|
if not kwargs.get("pipeline_id"):
|
|
raise ValueError("missing pipeline_id in path parameters")
|
|
|
|
_, current_tenant_id = current_account_with_tenant()
|
|
|
|
pipeline_id = kwargs.get("pipeline_id")
|
|
pipeline_id = str(pipeline_id)
|
|
|
|
del kwargs["pipeline_id"]
|
|
|
|
pipeline = (
|
|
db.session.query(Pipeline)
|
|
.where(Pipeline.id == pipeline_id, Pipeline.tenant_id == current_tenant_id)
|
|
.first()
|
|
)
|
|
|
|
if not pipeline:
|
|
raise PipelineNotFoundError()
|
|
|
|
kwargs["pipeline"] = pipeline
|
|
|
|
return view_func(*args, **kwargs)
|
|
|
|
return decorated_view
|
|
|
|
if view is None:
|
|
return decorator
|
|
else:
|
|
return decorator(view)
|