Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DIA-1451: return list instead of generator #268

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions adala/skills/collection/label_studio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import pandas as pd
from typing import Type, Iterator, Optional
from typing import List, Optional, Type
from functools import cached_property
from copy import deepcopy
from collections import defaultdict
Expand Down Expand Up @@ -44,26 +44,31 @@ def label_interface(self) -> LabelInterface:
return LabelInterface(self.label_config)

@cached_property
def ner_tags(self) -> Iterator[ControlTag]:
def ner_tags(self) -> List[ControlTag]:
# check if the input config has NER tag (<Labels> + <Text>), and return its `from_name` and `to_name`
control_tag_names = self.allowed_control_tags or list(
self.label_interface._controls.keys()
)
tags = []
for tag_name in control_tag_names:
tag = self.label_interface.get_control(tag_name)
if tag.tag.lower() in {"labels", "hypertextlabels"}:
yield tag
tags.append(tag)
return tags

@cached_property
def image_tags(self) -> Iterator[ObjectTag]:
def image_tags(self) -> List[ObjectTag]:
# check if any image tags are used as input variables
object_tag_names = self.allowed_object_tags or list(
self.label_interface._objects.keys()
)
tags = []
for tag_name in object_tag_names:
tag = self.label_interface.get_object(tag_name)
if tag.tag.lower() == "image":
yield tag
tags.append(tag)
return tags


def __getstate__(self):
"""Exclude cached properties when pickling - otherwise the 'Agent' can not be serialized in celery"""
Expand Down
Loading