From 6bf0c1f7c329e76047af27c91e2d775defa2f36c Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 05:51:25 -0500 Subject: [PATCH 01/15] test --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 698645f807e..385644f9dd8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,11 @@ repos: # Note: You have to update pyproject.toml[tool.mypy] too! args: ["--config-file=pyproject.toml"] exclude: (.*pyi$)|(weave_query)|(tests)|(examples) + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.387 + hooks: + - id: pyright + # This is legacy Weave when we were building a notebook product - should be removed - repo: local hooks: diff --git a/pyproject.toml b/pyproject.toml index de7b10a0ea5..52cd63e4fdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -189,6 +189,24 @@ exclude = ["weave_query", "tests", "examples", "docs", "noxfile.py"] # In cases where we support multiple versions of an integration, some imports can be missing reportMissingImports = false +# TODO: Gradually remove as we improve our code! +reportAttributeAccessIssue = false +reportPossiblyUnboundVariable = false +reportOptionalMemberAccess = false +reportPrivateImportUsage = false +reportArgumentType = false +reportReturnType = false +reportGeneralTypeIssues = false +reportCallIssue = false +reportIncompatibleMethodOverride = false +reportRedeclaration = false +reportIndexIssue = false +reportOperatorIssue = false +reportAssignmentType = false +reportInconsistentOverload = false +reportTypedDictNotRequiredAccess = false +reportOptionalSubscript = false +reportFunctionMemberAccess = false [tool.mypy] warn_unused_configs = true From 699f27a67b85fcf866792a707e4f23a4946d3843 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 06:02:29 -0500 Subject: [PATCH 02/15] test --- pyproject.toml | 1 - weave/trace/cli.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 52cd63e4fdd..2fc278bcd24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -206,7 +206,6 @@ reportAssignmentType = false reportInconsistentOverload = false reportTypedDictNotRequiredAccess = false reportOptionalSubscript = false -reportFunctionMemberAccess = false [tool.mypy] warn_unused_configs = true diff --git a/weave/trace/cli.py b/weave/trace/cli.py index 53fcc774f2e..d8300d9fd51 100644 --- a/weave/trace/cli.py +++ b/weave/trace/cli.py @@ -18,7 +18,7 @@ def cli() -> None: pass -@cli.command(help="Serve weave models.") +@cli.command(help="Serve weave models.") # type: ignore @click.argument("model_ref") @click.option("--method", help="Method name to serve.") @click.option("--project", help="W&B project name.") @@ -54,7 +54,7 @@ def serve( ) -@cli.group(help="Deploy weave models.") +@cli.group(help="Deploy weave models.") # type: ignore def deploy() -> None: pass From e476ed58bdb34b8085f9c2c632fb6d9462b9a443 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 06:04:59 -0500 Subject: [PATCH 03/15] test --- pyproject.toml | 1 - weave/integrations/instructor/instructor_iterable_utils.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2fc278bcd24..ed3dfc3e333 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,7 +205,6 @@ reportOperatorIssue = false reportAssignmentType = false reportInconsistentOverload = false reportTypedDictNotRequiredAccess = false -reportOptionalSubscript = false [tool.mypy] warn_unused_configs = true diff --git a/weave/integrations/instructor/instructor_iterable_utils.py b/weave/integrations/instructor/instructor_iterable_utils.py index 879181709fe..8287cb2c0d1 100644 --- a/weave/integrations/instructor/instructor_iterable_utils.py +++ b/weave/integrations/instructor/instructor_iterable_utils.py @@ -8,10 +8,10 @@ def instructor_iterable_accumulator( - acc: Optional[BaseModel], value: BaseModel + acc: Optional[list[BaseModel]], value: BaseModel ) -> list[BaseModel]: if acc is None: - acc = [value] + return [value] if acc[-1] != value: acc.append(value) return acc From 1c4b92fac425268a27f1a503ec6c1318dd80caae Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 06:15:42 -0500 Subject: [PATCH 04/15] test --- .pre-commit-config.yaml | 2 ++ pyproject.toml | 1 - weave/flow/obj.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 385644f9dd8..fb837f5e020 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,8 @@ repos: rev: v1.1.387 hooks: - id: pyright + additional_dependencies: + - pydantic # This is legacy Weave when we were building a notebook product - should be removed - repo: local diff --git a/pyproject.toml b/pyproject.toml index ed3dfc3e333..8dc049fd99e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,7 +204,6 @@ reportIndexIssue = false reportOperatorIssue = false reportAssignmentType = false reportInconsistentOverload = false -reportTypedDictNotRequiredAccess = false [tool.mypy] warn_unused_configs = true diff --git a/weave/flow/obj.py b/weave/flow/obj.py index b59067608d3..64e078b36bc 100644 --- a/weave/flow/obj.py +++ b/weave/flow/obj.py @@ -73,7 +73,7 @@ def handle_relocatable_object( # pydantic validation will construct a new pydantic object def is_ignored_type(v: type) -> bool: - return isinstance(v, cls.model_config["ignored_types"]) + return isinstance(v, cls.model_config["ignored_types"]) # pyright: ignore[reportTypedDictNotRequiredAccess] allowed_fields = {k: v for k, v in fields.items() if not is_ignored_type(v)} new_obj = handler(allowed_fields) From f96668d90f3d23d8818368a2f103df93bbdd82c7 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 09:55:48 -0500 Subject: [PATCH 05/15] test --- .pre-commit-config.yaml | 3 +-- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb837f5e020..5afb89ca97d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,8 +24,7 @@ repos: rev: v1.1.387 hooks: - id: pyright - additional_dependencies: - - pydantic + additional_dependencies: [".[tests]"] # This is legacy Weave when we were building a notebook product - should be removed - repo: local diff --git a/pyproject.toml b/pyproject.toml index 8dc049fd99e..44ab71ef49c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,7 +200,6 @@ reportGeneralTypeIssues = false reportCallIssue = false reportIncompatibleMethodOverride = false reportRedeclaration = false -reportIndexIssue = false reportOperatorIssue = false reportAssignmentType = false reportInconsistentOverload = false From 4b581fcc48a60151b33f318ce94e2375f34fc046 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 09:56:41 -0500 Subject: [PATCH 06/15] test --- weave/flow/obj.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave/flow/obj.py b/weave/flow/obj.py index 64e078b36bc..b59067608d3 100644 --- a/weave/flow/obj.py +++ b/weave/flow/obj.py @@ -73,7 +73,7 @@ def handle_relocatable_object( # pydantic validation will construct a new pydantic object def is_ignored_type(v: type) -> bool: - return isinstance(v, cls.model_config["ignored_types"]) # pyright: ignore[reportTypedDictNotRequiredAccess] + return isinstance(v, cls.model_config["ignored_types"]) allowed_fields = {k: v for k, v in fields.items() if not is_ignored_type(v)} new_obj = handler(allowed_fields) From 810a0132ab5114add317a2cb8091ddbb660427e4 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:00:32 -0500 Subject: [PATCH 07/15] test --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 44ab71ef49c..104df713812 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -193,14 +193,11 @@ reportMissingImports = false reportAttributeAccessIssue = false reportPossiblyUnboundVariable = false reportOptionalMemberAccess = false -reportPrivateImportUsage = false reportArgumentType = false reportReturnType = false -reportGeneralTypeIssues = false reportCallIssue = false reportIncompatibleMethodOverride = false reportRedeclaration = false -reportOperatorIssue = false reportAssignmentType = false reportInconsistentOverload = false From 053294969838e3e205e9c0b11f7de08704407b69 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:02:28 -0500 Subject: [PATCH 08/15] test --- pyproject.toml | 1 - weave/integrations/langchain/langchain.py | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 104df713812..d1868a5c7ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,7 +198,6 @@ reportReturnType = false reportCallIssue = false reportIncompatibleMethodOverride = false reportRedeclaration = false -reportAssignmentType = false reportInconsistentOverload = false [tool.mypy] diff --git a/weave/integrations/langchain/langchain.py b/weave/integrations/langchain/langchain.py index 508bb70de8f..8dd184e79af 100644 --- a/weave/integrations/langchain/langchain.py +++ b/weave/integrations/langchain/langchain.py @@ -55,7 +55,7 @@ except ImportError: import_failed = True -from typing import Any, Dict, Generator, List, Optional +from typing import Any, Dict, Generator, List, Optional, cast RUNNABLE_SEQUENCE_NAME = "RunnableSequence" @@ -182,7 +182,9 @@ def _persist_run_single(self, run: Run) -> None: # Note: this is implemented as a network call - it would be much nice # to refactor `create_call` such that it could accept a parent_id instead # of an entire Parent object. - parent_run = self.gc.get_call(wv_current_run.parent_id) + parent_run = cast( + Call, self.gc.get_call(wv_current_run.parent_id) + ) fn_name = make_pythonic_function_name(run.name) complete_op_name = f"langchain.{run.run_type.capitalize()}.{fn_name}" From 06d28b41d2f55ec615242cb53424de3b5607604c Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:04:20 -0500 Subject: [PATCH 09/15] test --- pyproject.toml | 1 - weave/flow/prompt/prompt.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d1868a5c7ce..ae4610120bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,7 +198,6 @@ reportReturnType = false reportCallIssue = false reportIncompatibleMethodOverride = false reportRedeclaration = false -reportInconsistentOverload = false [tool.mypy] warn_unused_configs = true diff --git a/weave/flow/prompt/prompt.py b/weave/flow/prompt/prompt.py index 016e9d3f996..a26e91c6fdc 100644 --- a/weave/flow/prompt/prompt.py +++ b/weave/flow/prompt/prompt.py @@ -242,7 +242,7 @@ def bind_rows(self, dataset: Union[list[dict], Any]) -> list["Prompt"]: return bound @overload - def __getitem__(self, index: SupportsIndex) -> Any: ... + def __getitem__(self, key: SupportsIndex) -> Any: ... @overload def __getitem__(self, key: slice) -> "EasyPrompt": ... From 477f0a435704bf4898fa981bc0f0fbc382381097 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:07:26 -0500 Subject: [PATCH 10/15] test --- pyproject.toml | 1 - weave/integrations/notdiamond/custom_router.py | 1 + weave/scorers/base_scorer.py | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ae4610120bf..58dd68b975a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -196,7 +196,6 @@ reportOptionalMemberAccess = false reportArgumentType = false reportReturnType = false reportCallIssue = false -reportIncompatibleMethodOverride = false reportRedeclaration = false [tool.mypy] diff --git a/weave/integrations/notdiamond/custom_router.py b/weave/integrations/notdiamond/custom_router.py index 03d234e5dda..cc5477915c2 100644 --- a/weave/integrations/notdiamond/custom_router.py +++ b/weave/integrations/notdiamond/custom_router.py @@ -83,6 +83,7 @@ def _get_model_results(provider_name: str) -> pd.DataFrame: class _DummyEvalModel(weave.Model): model_results: pd.DataFrame + @weave.op() def predict(self, prompt: str) -> Dict[str, Any]: response, score = self.model_results[ self.model_results[prompt_column] == prompt diff --git a/weave/scorers/base_scorer.py b/weave/scorers/base_scorer.py index 080149af0aa..650c1d3d2e0 100644 --- a/weave/scorers/base_scorer.py +++ b/weave/scorers/base_scorer.py @@ -18,6 +18,7 @@ class Scorer(Object): description="A mapping from column names in the dataset to the names expected by the scorer", ) + @weave.op def score(self, *, output: Any, **kwargs: Any) -> Any: raise NotImplementedError From 3116bf757beb6c65a6347241ab4c0b6c4e4e1c48 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:24:30 -0500 Subject: [PATCH 11/15] test --- weave/scorers/base_scorer.py | 1 + 1 file changed, 1 insertion(+) diff --git a/weave/scorers/base_scorer.py b/weave/scorers/base_scorer.py index 650c1d3d2e0..1934ef59f99 100644 --- a/weave/scorers/base_scorer.py +++ b/weave/scorers/base_scorer.py @@ -88,6 +88,7 @@ def auto_summarize(data: list) -> Optional[dict[str, Any]]: def get_scorer_attributes( scorer: Union[Callable, Op, Scorer], ) -> Tuple[str, Callable, Callable]: + score_fn: Union[Op, Callable[..., Any]] if weave_isinstance(scorer, Scorer): scorer_name = scorer.name if scorer_name is None: From 5218be0e41c6fdfabf5e423f12cb145c68563aa3 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:09:12 -0500 Subject: [PATCH 12/15] test --- pyproject.toml | 1 - weave/trace/weave_client.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 58dd68b975a..d1783ad5cb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -194,7 +194,6 @@ reportAttributeAccessIssue = false reportPossiblyUnboundVariable = false reportOptionalMemberAccess = false reportArgumentType = false -reportReturnType = false reportCallIssue = false reportRedeclaration = false diff --git a/weave/trace/weave_client.py b/weave/trace/weave_client.py index 0a3d4ad514e..f1636a15829 100644 --- a/weave/trace/weave_client.py +++ b/weave/trace/weave_client.py @@ -267,7 +267,8 @@ def children(self) -> "CallsIter": def delete(self) -> bool: """Delete the call.""" client = weave_client_context.require_weave_client() - return client.delete_call(call=self) + client.delete_call(call=self) + return True def set_display_name(self, name: Optional[str]) -> None: """ From 252c51a4670341983393e2ef973dc57547339242 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:13:34 -0500 Subject: [PATCH 13/15] test --- pyproject.toml | 1 - weave/integrations/langchain/langchain.py | 2 +- weave/integrations/llamaindex/llamaindex.py | 2 +- weave/trace/op.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d1783ad5cb9..b89d442888f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -195,7 +195,6 @@ reportPossiblyUnboundVariable = false reportOptionalMemberAccess = false reportArgumentType = false reportCallIssue = false -reportRedeclaration = false [tool.mypy] warn_unused_configs = true diff --git a/weave/integrations/langchain/langchain.py b/weave/integrations/langchain/langchain.py index 8dd184e79af..ea291a5d956 100644 --- a/weave/integrations/langchain/langchain.py +++ b/weave/integrations/langchain/langchain.py @@ -89,7 +89,7 @@ def _run_to_dict(run: Run, as_input: bool = False) -> dict: run_dict = {k: v for k, v in run_dict.items() if v} return run_dict - class WeaveTracer(BaseTracer): + class WeaveTracer(BaseTracer): # pyright: ignore[reportRedeclaration] run_inline: bool = True def __init__(self, **kwargs: Any) -> None: diff --git a/weave/integrations/llamaindex/llamaindex.py b/weave/integrations/llamaindex/llamaindex.py index 4abadb6cb7a..0427dfb2dcc 100644 --- a/weave/integrations/llamaindex/llamaindex.py +++ b/weave/integrations/llamaindex/llamaindex.py @@ -25,7 +25,7 @@ if not import_failed: - class WeaveCallbackHandler(BaseCallbackHandler): + class WeaveCallbackHandler(BaseCallbackHandler): # pyright: ignore[reportRedeclaration] """Base callback handler that can be used to track event starts and ends.""" def __init__( diff --git a/weave/trace/op.py b/weave/trace/op.py index ae85d65e7b8..94d072ed326 100644 --- a/weave/trace/op.py +++ b/weave/trace/op.py @@ -611,7 +611,7 @@ def create_wrapper(func: Callable) -> Op: if is_async: @wraps(func) - async def wrapper(*args: Any, **kwargs: Any) -> Any: + async def wrapper(*args: Any, **kwargs: Any) -> Any: # pyright: ignore[reportRedeclaration] res, _ = await _do_call_async( cast(Op, wrapper), *args, __should_raise=True, **kwargs ) From 56eef19a0ea3da1fb50c6602cf7337037e64993b Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 10:31:21 -0500 Subject: [PATCH 14/15] test --- weave/integrations/cohere/cohere_sdk.py | 10 +++++----- .../instructor/instructor_iterable_utils.py | 4 ++-- weave/integrations/notdiamond/custom_router.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/weave/integrations/cohere/cohere_sdk.py b/weave/integrations/cohere/cohere_sdk.py index 7e8482335ee..b0a5944795b 100644 --- a/weave/integrations/cohere/cohere_sdk.py +++ b/weave/integrations/cohere/cohere_sdk.py @@ -88,7 +88,7 @@ def _accumulate_content( def cohere_wrapper(name: str) -> Callable: def wrapper(fn: Callable) -> Callable: - op = weave.op()(fn) + op = weave.op(fn) op.name = name # type: ignore return op @@ -122,7 +122,7 @@ def _wrapper(*args: Any, **kwargs: Any) -> Any: return _wrapper - op = weave.op()(_post_process_response(fn)) + op = weave.op(_post_process_response(fn)) op.name = name # type: ignore return op @@ -156,7 +156,7 @@ async def _wrapper(*args: Any, **kwargs: Any) -> Any: return _wrapper - op = weave.op()(_post_process_response(fn)) + op = weave.op(_post_process_response(fn)) op.name = name # type: ignore return op @@ -165,7 +165,7 @@ async def _wrapper(*args: Any, **kwargs: Any) -> Any: def cohere_stream_wrapper(name: str) -> Callable: def wrapper(fn: Callable) -> Callable: - op = weave.op()(fn) + op = weave.op(fn) op.name = name # type: ignore return add_accumulator(op, lambda inputs: cohere_accumulator) # type: ignore @@ -174,7 +174,7 @@ def wrapper(fn: Callable) -> Callable: def cohere_stream_wrapper_v2(name: str) -> Callable: def wrapper(fn: Callable) -> Callable: - op = weave.op()(fn) + op = weave.op(fn) op.name = name # type: ignore return add_accumulator( op, make_accumulator=lambda inputs: cohere_accumulator_v2 diff --git a/weave/integrations/instructor/instructor_iterable_utils.py b/weave/integrations/instructor/instructor_iterable_utils.py index 8287cb2c0d1..84d64a103b6 100644 --- a/weave/integrations/instructor/instructor_iterable_utils.py +++ b/weave/integrations/instructor/instructor_iterable_utils.py @@ -29,7 +29,7 @@ def should_accumulate_iterable(inputs: dict) -> bool: def instructor_wrapper_sync(name: str) -> Callable[[Callable], Callable]: def wrapper(fn: Callable) -> Callable: - op = weave.op()(fn) + op = weave.op(fn) op.name = name # type: ignore return add_accumulator( op, # type: ignore @@ -50,7 +50,7 @@ async def _async_wrapper(*args: Any, **kwargs: Any) -> Any: return _async_wrapper "We need to do this so we can check if `stream` is used" - op = weave.op()(_fn_wrapper(fn)) + op = weave.op(_fn_wrapper(fn)) op.name = name # type: ignore return add_accumulator( op, # type: ignore diff --git a/weave/integrations/notdiamond/custom_router.py b/weave/integrations/notdiamond/custom_router.py index cc5477915c2..081fafb96f7 100644 --- a/weave/integrations/notdiamond/custom_router.py +++ b/weave/integrations/notdiamond/custom_router.py @@ -83,7 +83,7 @@ def _get_model_results(provider_name: str) -> pd.DataFrame: class _DummyEvalModel(weave.Model): model_results: pd.DataFrame - @weave.op() + @weave.op def predict(self, prompt: str) -> Dict[str, Any]: response, score = self.model_results[ self.model_results[prompt_column] == prompt @@ -93,12 +93,12 @@ def predict(self, prompt: str) -> Dict[str, Any]: class BestRoutedModel(_DummyEvalModel): model_name: str - @weave.op() + @weave.op def predict(self, prompt: str) -> Dict[str, Any]: return super().predict(prompt) class NotDiamondRoutedModel(_DummyEvalModel): - @weave.op() + @weave.op def predict(self, prompt: str) -> Dict[str, Any]: return super().predict(prompt) From 581f3f7f2e43e0f9ea2918c8bef1738b25f15f0a Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 11:51:59 -0500 Subject: [PATCH 15/15] test --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b89d442888f..e5c6570ded5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -194,7 +194,6 @@ reportAttributeAccessIssue = false reportPossiblyUnboundVariable = false reportOptionalMemberAccess = false reportArgumentType = false -reportCallIssue = false [tool.mypy] warn_unused_configs = true