Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang committed Jan 4, 2024
1 parent b9e0654 commit 31d3d1a
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class _ChatCompletionAccumulator:

def __init__(self) -> None:
self._is_null = True
self._cached_result: Optional[Mapping[str, Any]] = None
self._cached_result: Optional[Dict[str, Any]] = None
self._values = _ValuesAccumulator(
choices=_IndexedAccumulator(
lambda: _ValuesAccumulator(
Expand Down Expand Up @@ -81,11 +81,11 @@ def process_chunk(self, chunk: ChatCompletionChunk) -> None:
choice["message"] = delta
self._values += values

def _result(self) -> Optional[Mapping[str, Any]]:
def _result(self) -> Optional[Dict[str, Any]]:
if self._is_null:
return None
if not self._cached_result:
self._cached_result = MappingProxyType(dict(self._values))
self._cached_result = dict(self._values)
return self._cached_result

def get_attributes(self) -> Iterator[Tuple[str, AttributeValue]]:
Expand Down Expand Up @@ -115,7 +115,7 @@ class _CompletionAccumulator:

def __init__(self) -> None:
self._is_null = True
self._cached_result: Optional[Mapping[str, Any]] = None
self._cached_result: Optional[Dict[str, Any]] = None
self._values = _ValuesAccumulator(
choices=_IndexedAccumulator(lambda: _ValuesAccumulator(text=_StringAccumulator())),
)
Expand All @@ -131,11 +131,11 @@ def process_chunk(self, chunk: Completion) -> None:
values = chunk.model_dump(exclude_unset=True)
self._values += values

def _result(self) -> Optional[Mapping[str, Any]]:
def _result(self) -> Optional[Dict[str, Any]]:
if self._is_null:
return None
if not self._cached_result:
self._cached_result = MappingProxyType(dict(self._values))
self._cached_result = dict(self._values)
return self._cached_result

def get_attributes(self) -> Iterator[Tuple[str, AttributeValue]]:
Expand Down

0 comments on commit 31d3d1a

Please sign in to comment.