2026-04-14 11:12:40 -07:00
|
|
|
from __future__ import annotations
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2026-05-24 15:59:16 +08:00
|
|
|
from uuid import UUID
|
2026-04-14 11:12:40 -07:00
|
|
|
|
|
|
|
|
from flask_restx import Resource
|
2026-07-03 01:00:47 +08:00
|
|
|
from sqlalchemy.orm import Session
|
2026-04-14 11:12:40 -07:00
|
|
|
|
2026-05-27 15:51:42 +09:00
|
|
|
from controllers.common.schema import register_response_schema_models, register_schema_models
|
2026-07-03 01:00:47 +08:00
|
|
|
from controllers.console.app.wraps import with_session
|
2026-06-19 00:35:29 +08:00
|
|
|
from controllers.console.wraps import RBACPermission, RBACResourceScope, rbac_permission_required
|
2026-05-27 15:51:42 +09:00
|
|
|
from fields.hit_testing_fields import HitTestingResponse
|
|
|
|
|
from libs.helper import dump_response
|
2025-12-08 15:31:19 +09:00
|
|
|
from libs.login import login_required
|
2026-06-11 10:30:31 +09:00
|
|
|
from models import Account
|
2025-12-08 15:31:19 +09:00
|
|
|
|
|
|
|
|
from .. import console_ns
|
|
|
|
|
from ..datasets.hit_testing_base import DatasetsHitTestingBase, HitTestingPayload
|
|
|
|
|
from ..wraps import (
|
2025-03-10 19:50:11 +08:00
|
|
|
account_initialization_required,
|
|
|
|
|
cloud_edition_billing_rate_limit_check,
|
|
|
|
|
setup_required,
|
2026-06-11 10:30:31 +09:00
|
|
|
with_current_tenant_id,
|
|
|
|
|
with_current_user,
|
2025-03-10 19:50:11 +08:00
|
|
|
)
|
2025-12-08 15:31:19 +09:00
|
|
|
|
2026-05-27 15:51:42 +09:00
|
|
|
register_schema_models(console_ns, HitTestingPayload)
|
|
|
|
|
register_response_schema_models(console_ns, HitTestingResponse)
|
2026-01-29 13:47:35 +08:00
|
|
|
|
|
|
|
|
|
2025-09-15 10:59:11 +08:00
|
|
|
@console_ns.route("/datasets/<uuid:dataset_id>/hit-testing")
|
2024-10-14 17:26:04 +08:00
|
|
|
class HitTestingApi(Resource, DatasetsHitTestingBase):
|
2025-11-24 11:04:11 +09:00
|
|
|
@console_ns.doc("test_dataset_retrieval")
|
|
|
|
|
@console_ns.doc(description="Test dataset knowledge retrieval")
|
|
|
|
|
@console_ns.doc(params={"dataset_id": "Dataset ID"})
|
2025-12-08 15:31:19 +09:00
|
|
|
@console_ns.expect(console_ns.models[HitTestingPayload.__name__])
|
2026-04-14 11:12:40 -07:00
|
|
|
@console_ns.response(
|
|
|
|
|
200,
|
|
|
|
|
"Hit testing completed successfully",
|
|
|
|
|
model=console_ns.models[HitTestingResponse.__name__],
|
|
|
|
|
)
|
2025-11-24 11:04:11 +09:00
|
|
|
@console_ns.response(404, "Dataset not found")
|
|
|
|
|
@console_ns.response(400, "Invalid parameters")
|
2023-05-15 08:51:32 +08:00
|
|
|
@setup_required
|
|
|
|
|
@login_required
|
|
|
|
|
@account_initialization_required
|
2025-03-10 19:50:11 +08:00
|
|
|
@cloud_edition_billing_rate_limit_check("knowledge")
|
2026-06-11 10:30:31 +09:00
|
|
|
@with_current_tenant_id
|
|
|
|
|
@with_current_user
|
2026-06-19 00:35:29 +08:00
|
|
|
@rbac_permission_required(RBACResourceScope.DATASET, RBACPermission.DATASET_PIPELINE_TEST)
|
2026-07-03 01:00:47 +08:00
|
|
|
@with_session
|
|
|
|
|
def post(
|
|
|
|
|
self, session: Session, current_user: Account, current_tenant_id: str, dataset_id: UUID
|
|
|
|
|
) -> dict[str, object]:
|
2023-05-15 08:51:32 +08:00
|
|
|
dataset_id_str = str(dataset_id)
|
|
|
|
|
|
2026-07-15 14:48:28 +08:00
|
|
|
dataset = self.get_and_validate_dataset(session, dataset_id_str, current_user, current_tenant_id)
|
2026-05-27 15:51:42 +09:00
|
|
|
args = self.parse_args(console_ns.payload)
|
2024-10-14 17:26:04 +08:00
|
|
|
self.hit_testing_args_check(args)
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2026-06-11 10:30:31 +09:00
|
|
|
return dump_response(
|
|
|
|
|
HitTestingResponse,
|
2026-07-03 01:00:47 +08:00
|
|
|
self.perform_hit_testing(session, dataset, args, current_user, current_tenant_id),
|
2026-06-11 10:30:31 +09:00
|
|
|
)
|