diff --git a/agenta-backend/agenta_backend/models/api/evaluation_model.py b/agenta-backend/agenta_backend/models/api/evaluation_model.py index 70e31cb6a7..88c3755900 100644 --- a/agenta-backend/agenta_backend/models/api/evaluation_model.py +++ b/agenta-backend/agenta_backend/models/api/evaluation_model.py @@ -89,7 +89,7 @@ class SimpleEvaluationOutput(BaseModel): evaluation_type: EvaluationType -class EvaluationUpdate(BaseModel): +class HumanEvaluationUpdate(BaseModel): status: Optional[EvaluationStatusEnum] evaluation_type_settings: Optional[EvaluationTypeSettings] diff --git a/agenta-backend/agenta_backend/routers/evaluation_router.py b/agenta-backend/agenta_backend/routers/evaluation_router.py index ce38e767f9..3cf1b45494 100644 --- a/agenta-backend/agenta_backend/routers/evaluation_router.py +++ b/agenta-backend/agenta_backend/routers/evaluation_router.py @@ -14,18 +14,12 @@ EvaluationScenario, CustomEvaluationOutput, CustomEvaluationDetail, - EvaluationScenarioScoreUpdate, - EvaluationScenarioUpdate, ExecuteCustomEvaluationCode, - HumanEvaluation, - HumanEvaluationScenarioUpdate, NewEvaluation, DeleteEvaluation, EvaluationType, CreateCustomEvaluation, - EvaluationUpdate, EvaluationWebhook, - NewHumanEvaluation, SimpleEvaluationOutput, ) from agenta_backend.services.evaluation_service import ( @@ -35,11 +29,9 @@ fetch_custom_evaluation_detail, get_evaluation_scenario_score, update_evaluation_scenario_score, - update_evaluation, create_custom_code_evaluation, update_custom_code_evaluation, execute_custom_code_evaluation, - update_human_evaluation_scenario, ) from agenta_backend.services import evaluation_service from agenta_backend.utils.common import check_access_to_app @@ -163,33 +155,6 @@ async def fetch_evaluation_results(evaluation_id: str, request: Request): raise HTTPException(status_code=500, detail=str(exc)) -@router.put("/{evaluation_id}/") -async def update_evaluation_router( - request: Request, - evaluation_id: str, - update_data: EvaluationUpdate = Body(...), -): - """Updates an evaluation's status. - - Raises: - HTTPException: If the columns in the test set do not match with the inputs in the variant. - - Returns: - None: A 204 No Content status code, indicating that the update was successful. - """ - try: - # Get user and organization id - user_org_data: dict = await get_user_and_org_id(request.state.user_id) - await update_evaluation(evaluation_id, update_data, **user_org_data) - return Response(status_code=status.HTTP_204_NO_CONTENT) - - except KeyError: - raise HTTPException( - status_code=400, - detail="columns in the test set should match the names of the inputs in the variant", - ) - - @router.get( "/{evaluation_id}/evaluation_scenarios/", response_model=List[EvaluationScenario], diff --git a/agenta-backend/agenta_backend/routers/human_evaluation_router.py b/agenta-backend/agenta_backend/routers/human_evaluation_router.py index 7397b9ed12..3bd37b7c67 100644 --- a/agenta-backend/agenta_backend/routers/human_evaluation_router.py +++ b/agenta-backend/agenta_backend/routers/human_evaluation_router.py @@ -13,6 +13,7 @@ HumanEvaluationScenario, HumanEvaluationScenarioUpdate, EvaluationType, + HumanEvaluationUpdate, NewHumanEvaluation, SimpleEvaluationOutput, ) @@ -28,6 +29,7 @@ get_evaluation_scenario_score, update_evaluation_scenario_score, update_human_evaluation_scenario, + update_human_evaluation_service, ) @@ -153,6 +155,35 @@ async def fetch_evaluation_scenarios( return eval_scenarios +@router.put("/{evaluation_id}/", operation_id="update_evaluation") +async def update_evaluation( + request: Request, + evaluation_id: str, + update_data: HumanEvaluationUpdate = Body(...), +): + """Updates an evaluation's status. + + Raises: + HTTPException: If the columns in the test set do not match with the inputs in the variant. + + Returns: + None: A 204 No Content status code, indicating that the update was successful. + """ + try: + # Get user and organization id + user_org_data: dict = await get_user_and_org_id(request.state.user_id) + await update_human_evaluation_service( + evaluation_id, update_data, **user_org_data + ) + return Response(status_code=status.HTTP_204_NO_CONTENT) + + except KeyError: + raise HTTPException( + status_code=400, + detail="columns in the test set should match the names of the inputs in the variant", + ) + + @router.put( "/{evaluation_id}/evaluation_scenario/{evaluation_scenario_id}/{evaluation_type}/" ) @@ -244,10 +275,8 @@ async def fetch_results( # Get user and organization id print("are we here") user_org_data: dict = await get_user_and_org_id(request.state.user_id) - evaluation = ( - await evaluation_service._fetch_human_evaluation_scenario_and_check_access( - evaluation_id, **user_org_data - ) + evaluation = await evaluation_service._fetch_human_evaluation_and_check_access( + evaluation_id, **user_org_data ) print("really???") if evaluation.evaluation_type == EvaluationType.human_a_b_testing: diff --git a/agenta-backend/agenta_backend/services/evaluation_service.py b/agenta-backend/agenta_backend/services/evaluation_service.py index 507dd1860b..a36d133858 100644 --- a/agenta-backend/agenta_backend/services/evaluation_service.py +++ b/agenta-backend/agenta_backend/services/evaluation_service.py @@ -14,12 +14,13 @@ CustomEvaluationDetail, EvaluationScenarioInput, EvaluationType, + EvaluationTypeSettings, HumanEvaluation, HumanEvaluationScenario, + HumanEvaluationUpdate, NewEvaluation, EvaluationScenarioUpdate, CreateCustomEvaluation, - EvaluationUpdate, EvaluationStatusEnum, NewHumanEvaluation, ) @@ -37,8 +38,6 @@ HumanEvaluationScenarioOutput, UserDB, AppDB, - EvaluationScenarioInputDB, - EvaluationScenarioOutputDB, CustomEvaluationDB, ) @@ -115,6 +114,9 @@ async def _fetch_human_evaluation_scenario_and_check_access( evaluation_scenario = await db_manager.fetch_human_evaluation_scenario_by_id( evaluation_scenario_id=evaluation_scenario_id ) + + print("evaluation_scenario") + print(evaluation_scenario) if evaluation_scenario is None: raise HTTPException( status_code=404, @@ -251,8 +253,8 @@ async def create_evaluation_scenario( await engine.save(new_eval_scenario) -async def update_evaluation( - evaluation_id: str, update_payload: EvaluationUpdate, **user_org_data: dict +async def update_human_evaluation_service( + evaluation_id: str, update_payload: HumanEvaluationUpdate, **user_org_data: dict ) -> None: """ Update an existing evaluation based on the provided payload. @@ -265,7 +267,7 @@ async def update_evaluation( HTTPException: If the evaluation is not found or access is denied. """ # Fetch the evaluation by ID - evaluation = await _fetch_evaluation_and_check_access( + evaluation = await _fetch_human_evaluation_and_check_access( evaluation_id=evaluation_id, **user_org_data, )