Skip to content

Commit

Permalink
feat: change the visibility of evaluation entities (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
Icemap authored Dec 25, 2024
1 parent b7a2022 commit 1604ada
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
15 changes: 7 additions & 8 deletions backend/app/api/admin_routes/evaluation/evaluation_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ModifyEvaluationDatasetItem,
ParamsWithKeyword,
)
from app.api.admin_routes.evaluation.tools import must_get, must_get_and_belong
from app.api.admin_routes.evaluation.tools import must_get
from app.api.deps import SessionDep, CurrentSuperuserDep
from app.file_storage import default_file_storage
from app.models import Upload, EvaluationDataset, EvaluationDatasetItem
Expand Down Expand Up @@ -47,7 +47,7 @@ def create_evaluation_dataset(
if evaluation_dataset.upload_id is not None:
# If the evaluation_file_id is provided, validate the uploaded file
evaluation_file_id = evaluation_dataset.upload_id
upload = must_get_and_belong(session, Upload, evaluation_file_id, user.id)
upload = must_get(session, Upload, evaluation_file_id)

if upload.mime_type != MimeTypes.CSV:
raise HTTPException(
Expand Down Expand Up @@ -95,8 +95,8 @@ def create_evaluation_dataset(
def delete_evaluation_dataset(
evaluation_dataset_id: int, session: SessionDep, user: CurrentSuperuserDep
) -> bool:
evaluation_dataset = must_get_and_belong(
session, EvaluationDataset, evaluation_dataset_id, user.id
evaluation_dataset = must_get(
session, EvaluationDataset, evaluation_dataset_id
)

session.delete(evaluation_dataset)
Expand All @@ -112,8 +112,8 @@ def update_evaluation_dataset(
session: SessionDep,
user: CurrentSuperuserDep,
) -> EvaluationDataset:
evaluation_dataset = must_get_and_belong(
session, EvaluationDataset, evaluation_dataset_id, user.id
evaluation_dataset = must_get(
session, EvaluationDataset, evaluation_dataset_id
)

evaluation_dataset.name = updated_evaluation_dataset.name
Expand All @@ -133,7 +133,6 @@ def list_evaluation_dataset(
) -> Page[EvaluationDataset]:
stmt = (
select(EvaluationDataset)
.where(EvaluationDataset.user_id == user.id)
.order_by(desc(EvaluationDataset.id))
)

Expand Down Expand Up @@ -169,7 +168,7 @@ def delete_evaluation_dataset_item(
evaluation_dataset_item_id: int, session: SessionDep, user: CurrentSuperuserDep
) -> bool:
evaluation_dataset_item = must_get(
session, EvaluationDataset, evaluation_dataset_item_id
session, EvaluationDatasetItem, evaluation_dataset_item_id
)

session.delete(evaluation_dataset_item)
Expand Down
18 changes: 9 additions & 9 deletions backend/app/api/admin_routes/evaluation/evaluation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
EvaluationTaskSummary,
ParamsWithKeyword, EvaluationTaskOverview,
)
from app.api.admin_routes.evaluation.tools import must_get_and_belong
from app.api.admin_routes.evaluation.tools import must_get
from app.api.deps import SessionDep, CurrentSuperuserDep
from app.models import (
EvaluationTask,
Expand Down Expand Up @@ -53,8 +53,8 @@ def create_evaluation_task(
chat_engine = evaluation_task.chat_engine
run_size = evaluation_task.run_size

dataset = must_get_and_belong(
session, EvaluationDataset, evaluation_dataset_id, user.id
dataset = must_get(
session, EvaluationDataset, evaluation_dataset_id
)

if run_size is not None and run_size < len(dataset.evaluation_data_list):
Expand Down Expand Up @@ -94,7 +94,7 @@ def create_evaluation_task(
def cancel_evaluation_task(
evaluation_task_id: int, session: SessionDep, user: CurrentSuperuserDep
) -> Optional[bool]:
must_get_and_belong(session, EvaluationTask, evaluation_task_id, user.id)
must_get(session, EvaluationTask, evaluation_task_id)

session.exec(
update(EvaluationTaskItem)
Expand All @@ -107,19 +107,19 @@ def cancel_evaluation_task(


@router.get("/admin/evaluation/tasks/{evaluation_task_id}")
def list_evaluation_task(
def get_evaluation_task(
session: SessionDep,
user: CurrentSuperuserDep,
evaluation_task_id: int,
) -> EvaluationTask:
return must_get_and_belong(session, EvaluationTask, evaluation_task_id, user.id)
return must_get(session, EvaluationTask, evaluation_task_id)


@router.get("/admin/evaluation/tasks/{evaluation_task_id}/summary")
def get_evaluation_task_summary(
evaluation_task_id: int, session: SessionDep, user: CurrentSuperuserDep
) -> EvaluationTaskSummary:
task = must_get_and_belong(session, EvaluationTask, evaluation_task_id, user.id)
task = must_get(session, EvaluationTask, evaluation_task_id)
return get_evaluation_task_summary(task, session)


Expand All @@ -131,7 +131,6 @@ def list_evaluation_task(
) -> Page[EvaluationTaskSummary]:
stmt = (
select(EvaluationTask)
.where(EvaluationTask.user_id == user.id)
.order_by(desc(EvaluationTask.id))
)
if params.keyword:
Expand All @@ -158,7 +157,7 @@ def list_evaluation_task_items(
user: CurrentSuperuserDep,
params: ParamsWithKeyword = Depends(),
) -> Page[EvaluationTaskItem]:
must_get_and_belong(session, EvaluationTask, evaluation_task_id, user.id)
must_get(session, EvaluationTask, evaluation_task_id)
stmt = select(EvaluationTaskItem).where(
EvaluationTaskItem.evaluation_task_id == evaluation_task_id
)
Expand All @@ -169,6 +168,7 @@ def list_evaluation_task_items(
EvaluationTaskItem.reference.ilike(f"%{params.keyword}%"),
)
)
stmt.order_by(EvaluationTaskItem.id)

return paginate(session, stmt, params)

Expand Down

0 comments on commit 1604ada

Please sign in to comment.