Skip to content

Commit

Permalink
fix(awel): Fix awel check empty data bug (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
fangyinc authored Mar 19, 2024
1 parent 4970c9f commit 86a7b6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions dbgpt/core/awel/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def __bool__(self):
def __str__(self):
return f"EmptyData({self.name})"

def is_same(self, obj: Any) -> bool:
"""Check if the object is the same as the current object.
Args:
obj (Any): The object to compare with.
Returns:
bool: True if the object is the same as the current object, False otherwise.
"""
if not isinstance(obj, _EMPTY_DATA_TYPE):
return False
return self == obj


EMPTY_DATA = _EMPTY_DATA_TYPE("EMPTY_DATA")
SKIP_DATA = _EMPTY_DATA_TYPE("SKIP_DATA")
Expand Down
4 changes: 2 additions & 2 deletions dbgpt/core/awel/task/task_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, data: Union[T, _EMPTY_DATA_TYPE] = EMPTY_DATA) -> None:
@property
def output(self) -> T:
"""Return the output data."""
if self._data == EMPTY_DATA:
if EMPTY_DATA.is_same(self._data):
raise ValueError("No output data for current task output")
return cast(T, self._data)

Expand Down Expand Up @@ -188,7 +188,7 @@ def output_stream(self) -> AsyncIterator[T]:
Raises:
ValueError: If the output data is empty.
"""
if self._data == EMPTY_DATA:
if EMPTY_DATA.is_same(self._data):
raise ValueError("No output data for current task output")
return cast(AsyncIterator[T], self._data)

Expand Down

0 comments on commit 86a7b6c

Please sign in to comment.