Skip to content

Commit 67e5907

Browse files
committed
added new function
1 parent 63a373d commit 67e5907

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

src/superannotate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44

55

6-
__version__ = "4.4.28"
6+
__version__ = "4.4.29dev1"
77

88
os.environ.update({"sa_version": __version__})
99
sys.path.append(os.path.split(os.path.realpath(__file__))[0])

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ def retrieve_context(
310310
return False, None
311311

312312
project = (
313-
self.controller.get_project(project)
313+
self.controller.get_project_by_id(project).data
314314
if isinstance(project, int)
315-
else self.controller.get_project_by_id(project)
315+
else self.controller.get_project(project)
316316
)
317317
if project.type != ProjectType.MULTIMODAL:
318318
raise AppException(
@@ -2926,7 +2926,7 @@ def list_items(
29262926
project=project, item_ids=[i.id for i in res]
29272927
)
29282928
for i in res:
2929-
i["custom_metadata"] = item_custom_fields[i.id]
2929+
i.custom_metadata = item_custom_fields[i.id]
29302930
exclude = {"meta", "annotator_email", "qa_email"}
29312931
if include:
29322932
if "custom_metadata" not in include:

src/superannotate/lib/infrastructure/services/item_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
class ItemService(SuperannotateServiceProvider):
17-
MAX_URI_LENGTH = 16_000
17+
MAX_URI_LENGTH = 15_000
1818
URL_LIST = "items"
1919
URL_GET = "items/{item_id}"
2020

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"components": [
3+
{
4+
"id": "web_1",
5+
"type": "webComponent",
6+
"permissions": [],
7+
"hasTooltip": false,
8+
"exclude": true,
9+
"value": "",
10+
"code": "<!-- V11 -->\n<!DOCTYPE html>\n<html lang=\"en\">\n\n<head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Custom Component</title>\n</head>\n<body>\n <div id=\"saContainer\"></div>\n\n <script>\n const containerEl = document.getElementById(\"saContainer\");\n let contextValue = window.SA_CONTEXT;\n if (window.IS_BUILDER && window.IS_CONFIG_MODE) {\n const contextValueEl = document.createElement(\"input\");\n contextValueEl.setAttribute(\"type\", \"text\");\n contextValueEl.value = contextValue;\n contextValueEl.setAttribute(\"id\", \"contextValue\");\n\n const setContextBtn = document.createElement(\"button\");\n setContextBtn.innerHTML = \"Set Context\";\n setContextBtn.setAttribute(\"id\", \"setContextBtn\");\n \n containerEl.appendChild(contextValueEl);\n containerEl.appendChild(setContextBtn);\n\n setContextBtn.addEventListener(\"click\", async () => {\n const value = contextValueEl.value;\n console.log(\"> > > > \", value)\n await window.SA.setContext(value);\n });\n } else {\n containerEl.innerHTML = `Contect value: ${contextValue}`;\n }\n </script>\n</body>\n\n</html>",
11+
"context": "\"12121121212\""
12+
}
13+
],
14+
"code": [
15+
[
16+
"__init__",
17+
"from typing import List, Union\n# import requests.asyncs as requests\nimport requests\nimport sa\n\nwebComponent_web_1 = ['web_1']\n\ndef before_save_hook(old_status: str, new_status: str) -> bool:\n # Your code goes here\n return\n\ndef on_saved_hook():\n # Your code goes here\n return\n\ndef before_status_change_hook(old_status: str, new_status: str) -> bool:\n # Your code goes here\n return\n\ndef on_status_changed_hook(old_status: str, new_status: str):\n # Your code goes here\n return\n\ndef post_hook():\n # Your code goes here\n return\n\ndef on_session_start():\n # Your code goes here\n return\n\ndef on_session_end():\n # Your code goes here\n return\n\ndef on_web_1_message(path: List[Union[str, int]], value):\n # The path is a list of strings and integers, the length of which is always an odd number and not less than 1.\n # The last value is the identifier of the form element and the pairs preceding it are\n # the group identifiers and the subgroup index, respectively\n # value is current value of the form element\n\n # Your code goes here\n return\n\ndef on_web_1_wcevent(path: List[Union[str, int]], value):\n # The path is a list of strings and integers, the length of which is always an odd number and not less than 1.\n # The last value is the identifier of the form element and the pairs preceding it are\n # the group identifiers and the subgroup index, respectively\n # value is current value of the form element\n\n # Your code goes here\n return\n"
18+
]
19+
],
20+
"environments": []
21+
}

tests/integration/custom_fields/test_custom_schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def test_upload_delete_custom_values_search_items(self):
101101
self.PROJECT_NAME, name_contains=item_name, include_custom_metadata=True
102102
)
103103
assert data[0]["custom_metadata"] == payload
104+
data = sa.list_items(
105+
self.PROJECT_NAME, came__contains=item_name, include=["custom_metadata"]
106+
)
107+
assert data[0]["custom_metadata"] == payload
104108
sa.delete_custom_values(self.PROJECT_NAME, [{item_name: ["test"]}])
105109
data = sa.search_items(
106110
self.PROJECT_NAME, name_contains=item_name, include_custom_metadata=True
@@ -115,6 +119,7 @@ def test_search_items(self):
115119
sa.upload_custom_values(self.PROJECT_NAME, [{item_name: payload}] * 10000)
116120
items = sa.search_items(self.PROJECT_NAME, include_custom_metadata=True)
117121
assert items[0]["custom_metadata"] == payload
122+
items = sa.list_items(self.PROJECT_NAME, include=["custom_metadata"])
118123

119124
def test_search_items_without_custom_metadata(self):
120125
item_name = "test"

tests/integration/items/test_item_context.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,42 @@ def test_overwrite_false(self):
8585
# test from folder by project and folder ids as tuple and item id
8686
item = sa.search_items(f"{self.PROJECT_NAME}/folder", "dummy")[0]
8787
self._base_test((self._project["id"], folder["id"]), item["id"])
88+
89+
90+
class TestEditorContext(BaseTestCase):
91+
PROJECT_NAME = "TestEditorContext"
92+
PROJECT_TYPE = "Multimodal"
93+
PROJECT_DESCRIPTION = "DESCRIPTION"
94+
COMPONENT_ID = "web_1"
95+
EDITOR_TEMPLATE_PATH = os.path.join(
96+
Path(__file__).parent.parent.parent,
97+
"data_set/sample_llm_editor_context/form.json",
98+
)
99+
100+
def setUp(self, *args, **kwargs):
101+
102+
self._project = sa.create_project(
103+
self.PROJECT_NAME,
104+
self.PROJECT_DESCRIPTION,
105+
self.PROJECT_TYPE,
106+
settings=[{"attribute": "TemplateState", "value": 1}],
107+
)
108+
team = sa.controller.team
109+
project = sa.controller.get_project(self.PROJECT_NAME)
110+
time.sleep(10)
111+
with open(self.EDITOR_TEMPLATE_PATH) as f:
112+
res = sa.controller.service_provider.projects.attach_editor_template(
113+
team, project, template=json.load(f)
114+
)
115+
assert res.ok
116+
...
117+
118+
def tearDown(self) -> None:
119+
try:
120+
sa.delete_project(self.PROJECT_NAME)
121+
except Exception:
122+
...
123+
124+
def test_(self):
125+
val = sa.get_editor_context(self.PROJECT_NAME, self.COMPONENT_ID)
126+
assert val == "12121121212"

0 commit comments

Comments
 (0)