feat: Add "type" field to PipelineRecommendedPlugin model; Add query param "type" to recommended-plugins api. (#29736)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com>
This commit is contained in:
FFXN 2025-12-17 11:26:08 +08:00 committed by GitHub
parent 86131d4bd8
commit a93eecaeee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from typing import Any, Literal, cast
from uuid import UUID from uuid import UUID
from flask import abort, request from flask import abort, request
from flask_restx import Resource, marshal_with # type: ignore from flask_restx import Resource, marshal_with, reqparse # type: ignore
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from werkzeug.exceptions import Forbidden, InternalServerError, NotFound from werkzeug.exceptions import Forbidden, InternalServerError, NotFound
@ -975,6 +975,11 @@ class RagPipelineRecommendedPluginApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self): def get(self):
parser = reqparse.RequestParser()
parser.add_argument("type", type=str, location="args", required=False, default="all")
args = parser.parse_args()
type = args["type"]
rag_pipeline_service = RagPipelineService() rag_pipeline_service = RagPipelineService()
recommended_plugins = rag_pipeline_service.get_recommended_plugins() recommended_plugins = rag_pipeline_service.get_recommended_plugins(type)
return recommended_plugins return recommended_plugins

View File

@ -0,0 +1,31 @@
"""add type column not null default tool
Revision ID: 03ea244985ce
Revises: d57accd375ae
Create Date: 2025-12-16 18:17:12.193877
"""
from alembic import op
import models as models
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '03ea244985ce'
down_revision = 'd57accd375ae'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pipeline_recommended_plugins', schema=None) as batch_op:
batch_op.add_column(sa.Column('type', sa.String(length=50), server_default=sa.text("'tool'"), nullable=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('pipeline_recommended_plugins', schema=None) as batch_op:
batch_op.drop_column('type')
# ### end Alembic commands ###

View File

@ -1532,6 +1532,7 @@ class PipelineRecommendedPlugin(TypeBase):
) )
plugin_id: Mapped[str] = mapped_column(LongText, nullable=False) plugin_id: Mapped[str] = mapped_column(LongText, nullable=False)
provider_name: Mapped[str] = mapped_column(LongText, nullable=False) provider_name: Mapped[str] = mapped_column(LongText, nullable=False)
type: Mapped[str] = mapped_column(sa.String(50), nullable=False, server_default=sa.text("'tool'"))
position: Mapped[int] = mapped_column(sa.Integer, nullable=False, default=0) position: Mapped[int] = mapped_column(sa.Integer, nullable=False, default=0)
active: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, default=True) active: Mapped[bool] = mapped_column(sa.Boolean, nullable=False, default=True)
created_at: Mapped[datetime] = mapped_column( created_at: Mapped[datetime] = mapped_column(

View File

@ -1248,14 +1248,13 @@ class RagPipelineService:
session.commit() session.commit()
return workflow_node_execution_db_model return workflow_node_execution_db_model
def get_recommended_plugins(self) -> dict: def get_recommended_plugins(self, type: str) -> dict:
# Query active recommended plugins # Query active recommended plugins
pipeline_recommended_plugins = ( query = db.session.query(PipelineRecommendedPlugin).where(PipelineRecommendedPlugin.active == True)
db.session.query(PipelineRecommendedPlugin) if type and type != "all":
.where(PipelineRecommendedPlugin.active == True) query = query.where(PipelineRecommendedPlugin.type == type)
.order_by(PipelineRecommendedPlugin.position.asc())
.all() pipeline_recommended_plugins = query.order_by(PipelineRecommendedPlugin.position.asc()).all()
)
if not pipeline_recommended_plugins: if not pipeline_recommended_plugins:
return { return {