Skip to content

Commit

Permalink
ruff and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
tcapelle committed Aug 14, 2024
1 parent 6d3fc1e commit 1112450
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions weave/integrations/anthropic/anthropic_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async def _async_wrapper(
## This code handles both cases by patching the _IteratorWrapper
## and adding a text_stream property to it.


def anthropic_stream_accumulator(
acc: typing.Optional["Message"],
value: "MessageStream",
Expand All @@ -132,8 +133,6 @@ def anthropic_stream_accumulator(
return acc




class AnthropicIteratorWrapper(_IteratorWrapper):
def __getattr__(self, name: str) -> Any:
"""Delegate all other attributes to the wrapped iterator."""
Expand All @@ -155,12 +154,12 @@ def __stream_text__(self) -> Union[Iterator[str], AsyncIterator[str]]:
else:
return self.__sync_stream_text__()

def __sync_stream_text__(self) -> Iterator[str]:
def __sync_stream_text__(self) -> Iterator[str]: # type: ignore[attr-defined]
for chunk in self:
if chunk.type == "content_block_delta" and chunk.delta.type == "text_delta":
if chunk.type == "content_block_delta" and chunk.delta.type == "text_delta": # type: ignore[attr-defined]
yield chunk.delta.text

async def __async_stream_text__(self) -> AsyncIterator[str]:
async def __async_stream_text__(self) -> AsyncIterator[str]: # type: ignore[attr-defined]
async for chunk in self:
if chunk.type == "content_block_delta" and chunk.delta.type == "text_delta":
yield chunk.delta.text
Expand Down
4 changes: 2 additions & 2 deletions weave/trace/op_extensions/accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def add_accumulator(
*,
should_accumulate: Optional[Callable[[Dict], bool]] = None,
on_finish_post_processor: Optional[Callable[[Any], Any]] = None,
iterator_wrapper: Type[_IteratorWrapper[Any]] = _IteratorWrapper,
iterator_wrapper: Type[_IteratorWrapper] = _IteratorWrapper,
) -> Op:
"""This is to be used internally only - specifically designed for integrations with streaming libraries.
Expand Down Expand Up @@ -214,7 +214,7 @@ def _build_iterator_from_accumulator_for_op(
value: Iterator[V],
accumulator: Callable,
on_finish: FinishCallbackType,
iterator_wrapper: "_IteratorWrapper" = _IteratorWrapper,
iterator_wrapper: Type["_IteratorWrapper"] = _IteratorWrapper,
) -> "_IteratorWrapper":
acc: _Accumulator = _Accumulator(accumulator)

Expand Down

0 comments on commit 1112450

Please sign in to comment.