From 2775667ef20e28d80d7d41e52be72e436d6aeaa9 Mon Sep 17 00:00:00 2001 From: Andrew Truong Date: Wed, 22 Jan 2025 12:12:46 -0500 Subject: [PATCH] test --- docs/docs/guides/tracking/objects.md | 24 +++++++++++++++++++++++- weave/trace/api.py | 10 ++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/docs/guides/tracking/objects.md b/docs/docs/guides/tracking/objects.md index 23e806d60b1f..8398625e1b04 100644 --- a/docs/docs/guides/tracking/objects.md +++ b/docs/docs/guides/tracking/objects.md @@ -10,6 +10,8 @@ Weave's serialization layer saves and versions objects. + To save an object, call `weave.publish` with the object and a name. + ```python import weave # Initialize tracking to the project 'intro-example' @@ -18,6 +20,17 @@ Weave's serialization layer saves and versions objects. weave.publish(['felix', 'jimbo', 'billie'], 'cat-names') ``` + For builtin weave objects, you can also save in an object-oriented way: + + ```python + import weave + + weave.init('intro-example') + + ds = weave.Dataset(rows=[{'x': 1, 'y': 2}, {'x': 3, 'y': 4}]) + ds.save('my-dataset') + ``` + Publishing in TypeScript is still early, so not all objects are fully supported yet. @@ -62,7 +75,16 @@ Saving an object with a name will create the first version of that object if it - To delete a version of an object, call `.delete()` on the object ref. + + To delete a version of an object, call `.delete()` on the object : + + ```python + weave.init('intro-example') + cat_names = weave.ref('cat-names:v1').get() + cat_names.delete() + ``` + + You can also delete directly via the ref: ```python weave.init('intro-example') diff --git a/weave/trace/api.py b/weave/trace/api.py index 39ad728d44ed..cf39fdaa7d87 100644 --- a/weave/trace/api.py +++ b/weave/trace/api.py @@ -7,7 +7,7 @@ import threading import time from collections.abc import Iterator -from typing import TYPE_CHECKING, Any +from typing import Any # TODO: type_handlers is imported here to trigger registration of the image serializer. # There is probably a better place for this, but including here for now to get the fix in. @@ -28,9 +28,6 @@ from weave.trace.table import Table from weave.trace_server.interface.builtin_object_classes import leaderboard -if TYPE_CHECKING: - from weave.flow.obj import Object - _global_postprocess_inputs: PostprocessInputsFunc | None = None _global_postprocess_output: PostprocessOutputFunc | None = None @@ -180,11 +177,11 @@ def _publish(obj: Any, name: str | None = None) -> weave_client.ObjectRef: return ref -def delete(obj: Object | ObjectRef) -> None: +def delete(obj: Any) -> None: import weave if not isinstance(obj, (weave.Object, weave.ObjectRef)): - raise ValueError("Expected an Object or ObjectRef") # noqa: TRY004 + raise TypeError("Expected an Object or ObjectRef") obj.delete() @@ -337,4 +334,5 @@ def finish() -> None: "get_current_call", "weave_client_context", "require_current_call", + "delete", ]