Skip to content

Commit

Permalink
fix results and update evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
aakrem committed Jan 2, 2024
1 parent 6136099 commit 92e5c14
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SimpleEvaluationOutput(BaseModel):
evaluation_type: EvaluationType


class EvaluationUpdate(BaseModel):
class HumanEvaluationUpdate(BaseModel):
status: Optional[EvaluationStatusEnum]
evaluation_type_settings: Optional[EvaluationTypeSettings]

Expand Down
35 changes: 0 additions & 35 deletions agenta-backend/agenta_backend/routers/evaluation_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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],
Expand Down
37 changes: 33 additions & 4 deletions agenta-backend/agenta_backend/routers/human_evaluation_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
HumanEvaluationScenario,
HumanEvaluationScenarioUpdate,
EvaluationType,
HumanEvaluationUpdate,
NewHumanEvaluation,
SimpleEvaluationOutput,
)
Expand All @@ -28,6 +29,7 @@
get_evaluation_scenario_score,
update_evaluation_scenario_score,
update_human_evaluation_scenario,
update_human_evaluation_service,
)


Expand Down Expand Up @@ -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}/"
)
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions agenta-backend/agenta_backend/services/evaluation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
CustomEvaluationDetail,
EvaluationScenarioInput,
EvaluationType,
EvaluationTypeSettings,
HumanEvaluation,
HumanEvaluationScenario,
HumanEvaluationUpdate,
NewEvaluation,
EvaluationScenarioUpdate,
CreateCustomEvaluation,
EvaluationUpdate,
EvaluationStatusEnum,
NewHumanEvaluation,
)
Expand All @@ -37,8 +38,6 @@
HumanEvaluationScenarioOutput,
UserDB,
AppDB,
EvaluationScenarioInputDB,
EvaluationScenarioOutputDB,
CustomEvaluationDB,
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
)
Expand Down

0 comments on commit 92e5c14

Please sign in to comment.