Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmabrouk committed Jan 23, 2024
1 parent efa25ba commit e4d6ccf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
12 changes: 8 additions & 4 deletions agenta-backend/agenta_backend/models/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ async def human_evaluation_db_to_pydantic(
variant = await db_manager.get_app_variant_instance_by_id(str(variant_id))
variant_name = variant.variant_name if variant else str(variant_id)
variant_names.append(str(variant_name))
revisions = []
for variant_revision_id in evaluation_db.variant_revisions:
variant_revision = await db_manager.get_app_variant_revision_by_id(
str(variant_revision_id)
)
revision = variant_revision.revision
revisions.append(str(revision))

return HumanEvaluation(
id=str(evaluation_db.id),
Expand All @@ -120,10 +127,7 @@ async def human_evaluation_db_to_pydantic(
str(variant_revision)
for variant_revision in evaluation_db.variant_revisions
],
revisions=[
str(variant_revision.revision)
for variant_revision in evaluation_db.variant_revisions
],
revisions=revisions,
testset_id=str(evaluation_db.testset.id),
testset_name=evaluation_db.testset.name,
created_at=evaluation_db.created_at,
Expand Down
21 changes: 20 additions & 1 deletion agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ async def update_variant_parameters(
raise ValueError("Issue updating variant parameters")


async def get_app_variant_instance_by_id(variant_id: str):
async def get_app_variant_instance_by_id(variant_id: str) -> AppVariantDB:
"""Get the app variant object from the database with the provided id.
Arguments:
Expand All @@ -1241,6 +1241,25 @@ async def get_app_variant_instance_by_id(variant_id: str):
return app_variant_db


async def get_app_variant_revision_by_id(
variant_revision_id: str, fetch_links=False
) -> AppVariantRevisionsDB:
"""Get the app variant revision object from the database with the provided id.
Arguments:
variant_revision_id (str): The app variant revision unique identifier
Returns:
AppVariantDB: instance of app variant object
"""

variant_revision_db = await AppVariantRevisionsDB.find_one(
AppVariantRevisionsDB.id == ObjectId(variant_revision_id),
fetch_links=fetch_links,
)
return variant_revision_db


async def fetch_testset_by_id(testset_id: str) -> Optional[TestSetDB]:
"""Fetches a testset by its ID.
Args:
Expand Down
12 changes: 9 additions & 3 deletions agenta-backend/agenta_backend/services/evaluation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,18 @@ async def create_new_human_evaluation(
)

variants = [ObjectId(variant_id) for variant_id in payload.variant_ids]
variant_dbs = [
await db_manager.fetch_app_variant_by_id(variant_id)
for variant_id in payload.variant_ids
]

testset = await db_manager.fetch_testset_by_id(testset_id=payload.testset_id)
# Initialize and save evaluation instance to database
variant_revisions = [
await db_manager.fetch_app_variant_revision_by_variant(
str(variant.id), int(variant.revision)
str(variant_db.id), int(variant_db.revision)
)
for variant in variants
for variant_db in variant_dbs
]
eval_instance = HumanEvaluationDB(
app=app,
Expand All @@ -638,7 +642,9 @@ async def create_new_human_evaluation(
status=payload.status,
evaluation_type=payload.evaluation_type,
variants=variants,
variant_revisions=variant_revisions,
variant_revisions=[
ObjectId(str(variant_revision.id)) for variant_revision in variant_revisions
],
testset=testset,
created_at=current_time,
updated_at=current_time,
Expand Down

0 comments on commit e4d6ccf

Please sign in to comment.