From 7af29098df8a4a6c5991bcb3c59c34184c6f8cef Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 17:59:21 -0500 Subject: [PATCH 1/6] chore(weave): simplify op decorator usage internally (#2880) --- 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 f8fbd430ee4..64d736141cc 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 da35a95bff743030dc3a14a57f276b0745081eb4 Mon Sep 17 00:00:00 2001 From: Nicholas Pun <182540099+nicholaspun-wandb@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:04:32 -0800 Subject: [PATCH 2/6] fix(ui): Sorted aggregated columns no longer crash tables during ungrouping (#2802) --- .../Panel2/PanelTable/tableState.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/weave-js/src/components/Panel2/PanelTable/tableState.ts b/weave-js/src/components/Panel2/PanelTable/tableState.ts index 565fbb4b7f3..4cb8d286798 100644 --- a/weave-js/src/components/Panel2/PanelTable/tableState.ts +++ b/weave-js/src/components/Panel2/PanelTable/tableState.ts @@ -1,5 +1,6 @@ import { allObjPaths, + canSortType, constFunction, ConstNode, constNodeUnsafe, @@ -687,6 +688,16 @@ export async function disableGroupByCol( ) { const colIds = _.isArray(colId) ? colId : [colId]; const groupBy = ts.groupBy; + + // (WB-16067) + // We may try to sort on aggregated columns after ungrouping + // To prevent this, disable sorting on all the columns and re-enable + // after the ungroup + const initiallySortedCols = _.clone(ts.sort); + ts.sort.forEach(sortObj => { + ts = disableSortByCol(ts, sortObj.columnId); + }); + ts = produce(ts, draft => { draft.autoColumns = false; for (const cid of colIds) { @@ -701,9 +712,15 @@ export async function disableGroupByCol( } }); ts = await refreshSelectFunctions(ts, inputArrayNode, weave, stack); - if (ts.sort.find(s => s.columnId === colId) !== undefined) { - ts = disableSortByCol(ts, colId); - } + + initiallySortedCols.forEach(sortObj => { + if ( + sortObj.columnId !== colId && + canSortType(ts.columnSelectFunctions[sortObj.columnId].type) + ) { + ts = enableSortByCol(ts, sortObj.columnId, sortObj.dir === 'asc'); + } + }); return ts; } From af54361c423ddf35de2d36cbcebfa432f653454b Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 18:20:30 -0500 Subject: [PATCH 3/6] chore(weave): ruff: enable UP007 #2887 --- pyproject.toml | 1 + weave/scorers/llm_utils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 333ea707b96..c956500f6ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -167,6 +167,7 @@ select = [ "F401", # https://docs.astral.sh/ruff/rules/unused-import/ "TID252", # https://docs.astral.sh/ruff/rules/relative-imports/#relative-imports-tid252 "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation/ + "UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation/ ] ignore = [ # we use Google style diff --git a/weave/scorers/llm_utils.py b/weave/scorers/llm_utils.py index 60d08f6cf82..7c050a3ccdb 100644 --- a/weave/scorers/llm_utils.py +++ b/weave/scorers/llm_utils.py @@ -83,7 +83,7 @@ def create( def embed( - client: _LLM_CLIENTS, model_id: str, texts: Union[str, list[str]], **kwargs: Any + client: _LLM_CLIENTS, model_id: str, texts: str | list[str], **kwargs: Any ) -> list[list[float]]: client_type = type(client).__name__.lower() if "openai" in client_type: From 30d9dc8d00dfeec8295026a76439d462cac5edc9 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 18:38:01 -0500 Subject: [PATCH 4/6] chore(weave): ruff: enable UP028 (#2888) --- pyproject.toml | 1 + weave/trace_server/clickhouse_trace_server_batched.py | 6 ++---- weave/trace_server/sqlite_trace_server.py | 3 +-- weave/trace_server_bindings/remote_http_trace_server.py | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c956500f6ae..3e285c02031 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,6 +168,7 @@ select = [ "TID252", # https://docs.astral.sh/ruff/rules/relative-imports/#relative-imports-tid252 "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation/ "UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation/ + "UP028", # https://docs.astral.sh/ruff/rules/yield-in-for-loop/ ] ignore = [ # we use Google style diff --git a/weave/trace_server/clickhouse_trace_server_batched.py b/weave/trace_server/clickhouse_trace_server_batched.py index c8bc02b3deb..b1a7f2ee91a 100644 --- a/weave/trace_server/clickhouse_trace_server_batched.py +++ b/weave/trace_server/clickhouse_trace_server_batched.py @@ -827,8 +827,7 @@ def table_query_stream( limit=req.limit, offset=req.offset, ) - for row in rows: - yield row + yield from rows def _table_query_stream( self, @@ -1721,8 +1720,7 @@ def _query_stream( "summary": summary, }, ) - for row in stream: - yield row + yield from stream def _query( self, diff --git a/weave/trace_server/sqlite_trace_server.py b/weave/trace_server/sqlite_trace_server.py index ed54d406c13..c82815392dc 100644 --- a/weave/trace_server/sqlite_trace_server.py +++ b/weave/trace_server/sqlite_trace_server.py @@ -1186,8 +1186,7 @@ def table_query_stream( self, req: tsi.TableQueryReq ) -> Iterator[tsi.TableRowSchema]: results = self.table_query(req) - for row in results.rows: - yield row + yield from results.rows def get_type(val: Any) -> str: diff --git a/weave/trace_server_bindings/remote_http_trace_server.py b/weave/trace_server_bindings/remote_http_trace_server.py index 6f591a068fa..d2e041565f4 100644 --- a/weave/trace_server_bindings/remote_http_trace_server.py +++ b/weave/trace_server_bindings/remote_http_trace_server.py @@ -446,8 +446,7 @@ def table_query_stream( ) -> Iterator[tsi.TableRowSchema]: # Need to manually iterate over this until the stram endpoint is built and shipped. res = self.table_query(req) - for row in res.rows: - yield row + yield from res.rows def table_query_stats( self, req: Union[tsi.TableQueryStatsReq, dict[str, Any]] From cb14f6b016a8887452a8bfa6f0d2432d7467eda1 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 18:47:51 -0500 Subject: [PATCH 5/6] chore(weave): ruff: enable UP031 (#2889) --- docs/scripts/generate_images.py | 5 ++--- pyproject.toml | 1 + weave/trace/serve_fastapi.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/scripts/generate_images.py b/docs/scripts/generate_images.py index ae2c8379564..b1897a43f2c 100644 --- a/docs/scripts/generate_images.py +++ b/docs/scripts/generate_images.py @@ -59,9 +59,8 @@ async def generate_screenshot_from_browser( if local_storage: await context.add_init_script( """ - Object.assign(window.localStorage, %s); - """ - % json.dumps(local_storage) + Object.assign(window.localStorage, {}); + """.format(json.dumps(local_storage)) ) try: diff --git a/pyproject.toml b/pyproject.toml index 3e285c02031..fa04be61892 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -169,6 +169,7 @@ select = [ "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation/ "UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation/ "UP028", # https://docs.astral.sh/ruff/rules/yield-in-for-loop/ + "UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting/ ] ignore = [ # we use Google style diff --git a/weave/trace/serve_fastapi.py b/weave/trace/serve_fastapi.py index fc6e25999f6..4ba60766954 100644 --- a/weave/trace/serve_fastapi.py +++ b/weave/trace/serve_fastapi.py @@ -83,8 +83,9 @@ def object_method_app( if method_name is None: if len(op_attrs) > 1: raise ValueError( - "Multiple ops found on object (%s), must specify method_name argument" - % ", ".join(op_attrs) + "Multiple ops found on object ({}), must specify method_name argument".format( + ", ".join(op_attrs) + ) ) method_name = next(iter(op_attrs)) From 26b793445a5032885f09f65832bda725b1653176 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Tue, 5 Nov 2024 18:56:10 -0500 Subject: [PATCH 6/6] chore(weave): ruff: enable UP036 (#2890) --- pyproject.toml | 1 + weave/trace/trace_sentry.py | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fa04be61892..842fd86031b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -170,6 +170,7 @@ select = [ "UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation/ "UP028", # https://docs.astral.sh/ruff/rules/yield-in-for-loop/ "UP031", # https://docs.astral.sh/ruff/rules/printf-string-formatting/ + "UP036", # https://docs.astral.sh/ruff/rules/outdated-version-block/ ] ignore = [ # we use Google style diff --git a/weave/trace/trace_sentry.py b/weave/trace/trace_sentry.py index 2f773642e9e..fbc12c1a8c2 100644 --- a/weave/trace/trace_sentry.py +++ b/weave/trace/trace_sentry.py @@ -15,12 +15,7 @@ import os import site import sys -from typing import TYPE_CHECKING, Any, Callable, Optional, Union - -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import TYPE_CHECKING, Any, Callable, Literal, Optional, Union if TYPE_CHECKING: from sentry_sdk._types import ExcInfo