Skip to content

Commit 3aa42a8

Browse files
authored
[AL-7584] Add ontology_id for model app (#1316)
1 parent eb04f7c commit 3aa42a8

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

labelbox/schema/foundry/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class App(_CamelCaseMixin, BaseModel):
1212
description: str
1313
inference_params: Dict[str, Any]
1414
class_to_schema_id: Dict[str, str]
15+
ontology_id: str
1516
created_by: Optional[str] = None
1617

1718
@classmethod

labelbox/schema/foundry/foundry_client.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ def _create_app(self, app: App) -> App:
1515
field_names_str = "\n".join(APP_FIELD_NAMES)
1616
query_str = f"""
1717
mutation CreateDataRowAttachmentPyApi(
18-
$name: String!, $modelId: ID!, $description: String, $inferenceParams: Json!, $classToSchemaId: Json!
18+
$name: String!, $modelId: ID!, $ontologyId: ID!, $description: String, $inferenceParams: Json!, $classToSchemaId: Json!
1919
){{
2020
createModelFoundryApp(input: {{
2121
name: $name
2222
modelId: $modelId
23+
ontologyId: $ontologyId
2324
description: $description
2425
inferenceParams: $inferenceParams
2526
classToSchemaId: $classToSchemaId
@@ -73,31 +74,9 @@ def _delete_app(self, id: str) -> None:
7374
raise exceptions.LabelboxError(f'Unable to delete app with id {id}',
7475
e)
7576

76-
def _get_model(self, id: str) -> Model:
77-
field_names_str = "\n".join(MODEL_FIELD_NAMES)
78-
79-
query_str = f"""
80-
query GetModelByIdPyApi($id: ID!) {{
81-
modelFoundryModel(where: {{id: $id}}) {{
82-
model {{
83-
{field_names_str}
84-
}}
85-
}}
86-
}}
87-
"""
88-
params = {"id": id}
89-
90-
try:
91-
response = self.client.execute(query_str, params)
92-
except Exception as e:
93-
raise exceptions.LabelboxError(f'Unable to get model with id {id}',
94-
e)
95-
return Model(**response["modelFoundryModel"]["model"])
96-
9777
def run_app(self, model_run_name: str,
9878
data_rows: Union[DataRowIds, GlobalKeys], app_id: str) -> Task:
9979
app = self._get_app(app_id)
100-
model = self._get_model(app.model_id)
10180

10281
data_rows_query = self.client.build_catalog_query(data_rows)
10382

@@ -110,7 +89,7 @@ def run_app(self, model_run_name: str,
11089
"query": [data_rows_query],
11190
"scope": None
11291
},
113-
"ontologyId": model.ontology_id
92+
"ontologyId": app.ontology_id
11493
}
11594

11695
query = """

tests/integration/test_foundry.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@ def foundry_client(client):
1919

2020

2121
@pytest.fixture()
22-
def unsaved_app(random_str):
23-
return App(
24-
model_id=TEST_MODEL_ID,
25-
name=f"Test App {random_str}",
26-
description="Test App Description",
27-
inference_params={"confidence": 0.2},
28-
class_to_schema_id={},
29-
)
22+
def ontology(client, random_str):
23+
object_features = [
24+
lb.Tool(tool=lb.Tool.Type.BBOX,
25+
name="text",
26+
color="#ff0000",
27+
classifications=[
28+
lb.Classification(class_type=lb.Classification.Type.TEXT,
29+
name="value")
30+
])
31+
]
32+
33+
ontology_builder = lb.OntologyBuilder(tools=object_features,)
34+
35+
ontology = client.create_ontology(
36+
f"Test ontology for tesseract model {random_str}",
37+
ontology_builder.asdict(),
38+
media_type=lb.MediaType.Image)
39+
return ontology
40+
41+
42+
@pytest.fixture()
43+
def unsaved_app(random_str, ontology):
44+
return App(model_id=TEST_MODEL_ID,
45+
name=f"Test App {random_str}",
46+
description="Test App Description",
47+
inference_params={"confidence": 0.2},
48+
class_to_schema_id={},
49+
ontology_id=ontology.uid)
3050

3151

3252
@pytest.fixture()
@@ -55,11 +75,6 @@ def test_get_app_with_invalid_id(foundry_client):
5575
foundry_client._get_app("invalid-id")
5676

5777

58-
def test_get_model_by_id(foundry_client):
59-
model = foundry_client._get_model(TEST_MODEL_ID)
60-
assert str(model.id) == TEST_MODEL_ID
61-
62-
6378
def test_run_foundry_app_with_data_row_id(foundry_client, data_row, app,
6479
random_str):
6580
data_rows = lb.DataRowIds([data_row.uid])

0 commit comments

Comments
 (0)