mirror of
https://github.com/langgenius/dify.git
synced 2025-11-10 16:32:46 +00:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <xh001x@hotmail.com>
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
from flask_restx import ( # type: ignore
|
|
Resource, # type: ignore
|
|
reqparse,
|
|
)
|
|
from werkzeug.exceptions import Forbidden
|
|
|
|
from controllers.console import api
|
|
from controllers.console.datasets.wraps import get_rag_pipeline
|
|
from controllers.console.wraps import account_initialization_required, setup_required
|
|
from libs.login import current_user, login_required
|
|
from models import Account
|
|
from models.dataset import Pipeline
|
|
from services.rag_pipeline.rag_pipeline import RagPipelineService
|
|
|
|
|
|
class DataSourceContentPreviewApi(Resource):
|
|
@setup_required
|
|
@login_required
|
|
@account_initialization_required
|
|
@get_rag_pipeline
|
|
def post(self, pipeline: Pipeline, node_id: str):
|
|
"""
|
|
Run datasource content preview
|
|
"""
|
|
if not isinstance(current_user, Account):
|
|
raise Forbidden()
|
|
|
|
parser = reqparse.RequestParser()
|
|
parser.add_argument("inputs", type=dict, required=True, nullable=False, location="json")
|
|
parser.add_argument("datasource_type", type=str, required=True, location="json")
|
|
parser.add_argument("credential_id", type=str, required=False, location="json")
|
|
args = parser.parse_args()
|
|
|
|
inputs = args.get("inputs")
|
|
if inputs is None:
|
|
raise ValueError("missing inputs")
|
|
datasource_type = args.get("datasource_type")
|
|
if datasource_type is None:
|
|
raise ValueError("missing datasource_type")
|
|
|
|
rag_pipeline_service = RagPipelineService()
|
|
preview_content = rag_pipeline_service.run_datasource_node_preview(
|
|
pipeline=pipeline,
|
|
node_id=node_id,
|
|
user_inputs=inputs,
|
|
account=current_user,
|
|
datasource_type=datasource_type,
|
|
is_published=True,
|
|
credential_id=args.get("credential_id"),
|
|
)
|
|
return preview_content, 200
|
|
|
|
|
|
api.add_resource(
|
|
DataSourceContentPreviewApi,
|
|
"/rag/pipelines/<uuid:pipeline_id>/workflows/published/datasource/nodes/<string:node_id>/preview",
|
|
)
|