Skip to content

Commit 4091e92

Browse files
author
Val Brodsky
committed
Use _CoreProjectInput in create_model_evaluation_project
1 parent 3a6df99 commit 4091e92

File tree

3 files changed

+53
-38
lines changed

3 files changed

+53
-38
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import urllib.parse
99
from collections import defaultdict
1010
from types import MappingProxyType
11-
from typing import Any, Callable, Dict, List, Optional, Union, overload
11+
from typing import Any, Callable, Dict, List, Optional, Set, Union, overload
1212

1313
import lbox.exceptions
1414
import requests
@@ -597,7 +597,16 @@ def create_dataset(
597597
raise e
598598
return dataset
599599

600-
def create_project(self, **kwargs) -> Project:
600+
def create_project(
601+
self,
602+
name: str,
603+
media_type: MediaType,
604+
description: Optional[str] = None,
605+
auto_audit_percentage: Optional[float] = None,
606+
auto_audit_number_of_labels: Optional[int] = None,
607+
quality_modes: Optional[Set[QualityMode]] = {QualityMode.Benchmark, QualityMode.Consensus},
608+
is_benchmark_enabled: Optional[bool] = None,
609+
is_consensus_enabled: Optional[bool] = None) -> Project:
601610
"""Creates a Project object on the server.
602611
603612
Attribute values are passed as keyword arguments.
@@ -628,39 +637,30 @@ def create_project(self, **kwargs) -> Project:
628637
dataset_name_or_id, append_to_existing_dataset, data_row_count, editor_task_type
629638
They are not used for general projects and not supported in this method
630639
"""
631-
# The following arguments are not supported for general projects, only for chat model evaluation projects
632-
kwargs.pop("dataset_name_or_id", None)
633-
kwargs.pop("append_to_existing_dataset", None)
634-
kwargs.pop("data_row_count", None)
635-
kwargs.pop("editor_task_type", None)
636-
return self._create_project(_CoreProjectInput(**kwargs))
637-
638-
@overload
639-
def create_model_evaluation_project(
640-
self,
641-
dataset_name: str,
642-
dataset_id: str = None,
643-
data_row_count: int = 100,
644-
**kwargs,
645-
) -> Project:
646-
pass
647-
648-
@overload
649-
def create_model_evaluation_project(
650-
self,
651-
dataset_id: str,
652-
dataset_name: str = None,
653-
data_row_count: int = 100,
654-
**kwargs,
655-
) -> Project:
656-
pass
640+
input = {
641+
"name": name,
642+
"description": description,
643+
"media_type": media_type,
644+
"auto_audit_percentage": auto_audit_percentage,
645+
"auto_audit_number_of_labels": auto_audit_number_of_labels,
646+
"quality_modes": quality_modes,
647+
"is_benchmark_enabled": is_benchmark_enabled,
648+
"is_consensus_enabled": is_consensus_enabled,
649+
}
650+
return self._create_project(_CoreProjectInput(**input))
657651

658652
def create_model_evaluation_project(
659653
self,
654+
name: str,
655+
description: Optional[str] = None,
656+
auto_audit_percentage: Optional[float] = None,
657+
auto_audit_number_of_labels: Optional[int] = None,
658+
quality_modes: Optional[Set[QualityMode]] = {QualityMode.Benchmark, QualityMode.Consensus},
659+
is_benchmark_enabled: Optional[bool] = None,
660+
is_consensus_enabled: Optional[bool] = None,
660661
dataset_id: Optional[str] = None,
661662
dataset_name: Optional[str] = None,
662663
data_row_count: int = 100,
663-
**kwargs,
664664
) -> Project:
665665
"""
666666
Use this method exclusively to create a chat model evaluation project.
@@ -691,8 +691,6 @@ def create_model_evaluation_project(
691691
raise ValueError(
692692
"dataset_name or data_set_id must be present and not be an empty string."
693693
)
694-
if data_row_count <= 0:
695-
raise ValueError("data_row_count must be a positive integer.")
696694

697695
if dataset_id:
698696
append_to_existing_dataset = True
@@ -701,13 +699,24 @@ def create_model_evaluation_project(
701699
append_to_existing_dataset = False
702700
dataset_name_or_id = dataset_name
703701

704-
kwargs["media_type"] = MediaType.Conversational
705-
kwargs["dataset_name_or_id"] = dataset_name_or_id
706-
kwargs["append_to_existing_dataset"] = append_to_existing_dataset
707-
kwargs["data_row_count"] = data_row_count
708-
kwargs["editor_task_type"] = EditorTaskType.ModelChatEvaluation.value
702+
media_type = MediaType.Conversational
703+
editor_task_type = EditorTaskType.ModelChatEvaluation
709704

710-
return self._create_project(_CoreProjectInput(**kwargs))
705+
input = {
706+
"name": name,
707+
"description": description,
708+
"media_type": media_type,
709+
"auto_audit_percentage": auto_audit_percentage,
710+
"auto_audit_number_of_labels": auto_audit_number_of_labels,
711+
"quality_modes": quality_modes,
712+
"is_benchmark_enabled": is_benchmark_enabled,
713+
"is_consensus_enabled": is_consensus_enabled,
714+
"dataset_name_or_id": dataset_name_or_id,
715+
"append_to_existing_dataset": append_to_existing_dataset,
716+
"data_row_count": data_row_count,
717+
"editor_task_type": editor_task_type,
718+
}
719+
return self._create_project(_CoreProjectInput(**input))
711720

712721
def create_offline_model_evaluation_project(self, **kwargs) -> Project:
713722
"""

libs/labelbox/src/labelbox/project_validation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from typing import Optional, Set
22

33
from pydantic import BaseModel, ConfigDict, Field, model_validator
4+
from typing_extensions import Annotated
45

56
from labelbox.schema.media_type import MediaType
7+
from labelbox.schema.ontology_kind import EditorTaskType
68
from labelbox.schema.quality_mode import (
79
BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS,
810
BENCHMARK_AUTO_AUDIT_PERCENTAGE,
@@ -12,6 +14,8 @@
1214
)
1315
from labelbox.schema.queue_mode import QueueMode
1416

17+
PositiveInt = Annotated[int, Field(gt=0)]
18+
1519

1620
class _CoreProjectInput(BaseModel):
1721
name: str
@@ -27,6 +31,8 @@ class _CoreProjectInput(BaseModel):
2731
is_consensus_enabled: Optional[bool] = None
2832
dataset_name_or_id: Optional[str] = None
2933
append_to_existing_dataset: Optional[bool] = None
34+
data_row_count: Optional[PositiveInt] = None
35+
editor_task_type: Optional[EditorTaskType] = None
3036

3137
model_config = ConfigDict(extra="forbid")
3238

libs/labelbox/src/labelbox/schema/ontology_kind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def evaluate_ontology_kind_with_media_type(
5353
return media_type
5454

5555

56-
class EditorTaskType(Enum):
56+
class EditorTaskType(str, Enum):
5757
ModelChatEvaluation = "MODEL_CHAT_EVALUATION"
5858
ResponseCreation = "RESPONSE_CREATION"
5959
OfflineModelChatEvaluation = "OFFLINE_MODEL_CHAT_EVALUATION"

0 commit comments

Comments
 (0)