From 2bfdd96063071c919790f3ddf5a40dd90aecb43c Mon Sep 17 00:00:00 2001 From: Tim Sweeney Date: Thu, 12 Dec 2024 17:09:10 -0800 Subject: [PATCH] change to big change to builtin --- dev_docs/BaseObjectClasses.md | 10 +++++----- .../litellm/test_actions_lifecycle_llm_judge.py | 2 +- tests/trace/test_actions_lifecycle.py | 2 +- tests/trace/test_base_object_classes.py | 2 +- weave-js/scripts/generate-schemas.sh | 2 +- weave/flow/annotation_spec.py | 2 +- weave/flow/leaderboard.py | 2 +- weave/scripts/generate_base_object_schemas.py | 2 +- weave/trace/api.py | 2 +- weave/trace/base_objects.py | 2 +- weave/trace/serialize.py | 2 +- .../actions_worker/actions/contains_words.py | 2 +- .../trace_server/actions_worker/actions/llm_judge.py | 2 +- weave/trace_server/actions_worker/dispatcher.py | 2 +- weave/trace_server/feedback.py | 2 +- .../actions.py | 2 +- .../annotation_spec.py | 2 +- .../base_object_def.py | 0 .../builtin_object_registry.py | 12 +++++++----- .../generated_base_object_class_schemas.json | 0 .../leaderboard.py | 2 +- .../test_only_example.py | 2 +- weave/trace_server/object_class_util.py | 2 +- 23 files changed, 31 insertions(+), 29 deletions(-) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/actions.py (95%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/annotation_spec.py (98%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/base_object_def.py (100%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/builtin_object_registry.py (56%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/generated/generated_base_object_class_schemas.json (100%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/leaderboard.py (80%) rename weave/trace_server/interface/{base_object_classes => builtin_object_classes}/test_only_example.py (90%) diff --git a/dev_docs/BaseObjectClasses.md b/dev_docs/BaseObjectClasses.md index fded028393c..10395f63035 100644 --- a/dev_docs/BaseObjectClasses.md +++ b/dev_docs/BaseObjectClasses.md @@ -79,11 +79,11 @@ While many Weave Objects are free-form and user-defined, there is often a need f Here's how to define and use a validated base object: -1. **Define your schema** (in `weave/trace_server/interface/base_object_classes/your_schema.py`): +1. **Define your schema** (in `weave/trace_server/interface/builtin_object_classes/your_schema.py`): ```python from pydantic import BaseModel -from weave.trace_server.interface.base_object_classes import base_object_def +from weave.trace_server.interface.builtin_object_classes import base_object_def class NestedConfig(BaseModel): setting_a: int @@ -154,10 +154,10 @@ Run `make synchronize-base-object-schemas` to ensure the frontend TypeScript typ ### Architecture Flow -1. Define your schema in a python file in the `weave/trace_server/interface/base_object_classes/test_only_example.py` directory. See `weave/trace_server/interface/base_object_classes/test_only_example.py` as an example. -2. Make sure to register your schemas in `weave/trace_server/interface/base_object_classes/builtin_object_registry.py` by calling `register_base_object`. +1. Define your schema in a python file in the `weave/trace_server/interface/builtin_object_classes/test_only_example.py` directory. See `weave/trace_server/interface/builtin_object_classes/test_only_example.py` as an example. +2. Make sure to register your schemas in `weave/trace_server/interface/builtin_object_classes/builtin_object_registry.py` by calling `register_base_object`. 3. Run `make synchronize-base-object-schemas` to generate the frontend types. - * The first step (`make generate_base_object_schemas`) will run `weave/scripts/generate_base_object_schemas.py` to generate a JSON schema in `weave/trace_server/interface/base_object_classes/generated/generated_base_object_class_schemas.json`. + * The first step (`make generate_base_object_schemas`) will run `weave/scripts/generate_base_object_schemas.py` to generate a JSON schema in `weave/trace_server/interface/builtin_object_classes/generated/generated_base_object_class_schemas.json`. * The second step (yarn `generate-schemas`) will read this file and use it to generate the frontend types located in `weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts`. 4. Now, each use case uses different parts: 1. `Python Writing`. Users can directly import these classes and use them as normal Pydantic models, which get published with `weave.publish`. The python client correct builds the requisite payload. diff --git a/tests/integrations/litellm/test_actions_lifecycle_llm_judge.py b/tests/integrations/litellm/test_actions_lifecycle_llm_judge.py index 42b7a97a18f..bcce364f3ef 100644 --- a/tests/integrations/litellm/test_actions_lifecycle_llm_judge.py +++ b/tests/integrations/litellm/test_actions_lifecycle_llm_judge.py @@ -15,7 +15,7 @@ ) from tests.trace.util import client_is_sqlite from weave.trace.weave_client import WeaveClient -from weave.trace_server.interface.base_object_classes.actions import ( +from weave.trace_server.interface.builtin_object_classes.actions import ( ActionSpec, ) from weave.trace_server.trace_server_interface import ( diff --git a/tests/trace/test_actions_lifecycle.py b/tests/trace/test_actions_lifecycle.py index 7659a503c57..b43bb97fbd5 100644 --- a/tests/trace/test_actions_lifecycle.py +++ b/tests/trace/test_actions_lifecycle.py @@ -3,7 +3,7 @@ import weave from tests.trace.util import client_is_sqlite from weave.trace.weave_client import WeaveClient -from weave.trace_server.interface.base_object_classes.actions import ( +from weave.trace_server.interface.builtin_object_classes.actions import ( ActionSpec, ) from weave.trace_server.trace_server_interface import ( diff --git a/tests/trace/test_base_object_classes.py b/tests/trace/test_base_object_classes.py index 1a7e64f9ed6..1c6215960cf 100644 --- a/tests/trace/test_base_object_classes.py +++ b/tests/trace/test_base_object_classes.py @@ -22,7 +22,7 @@ from weave.trace.refs import ObjectRef from weave.trace.weave_client import WeaveClient from weave.trace_server import trace_server_interface as tsi -from weave.trace_server.interface.base_object_classes.test_only_example import ( +from weave.trace_server.interface.builtin_object_classes.test_only_example import ( TestOnlyNestedBaseModel, ) diff --git a/weave-js/scripts/generate-schemas.sh b/weave-js/scripts/generate-schemas.sh index 545d81e17af..6e6b4b86aa3 100644 --- a/weave-js/scripts/generate-schemas.sh +++ b/weave-js/scripts/generate-schemas.sh @@ -3,7 +3,7 @@ # Exit on error set -e -SCHEMA_INPUT_PATH="../weave/trace_server/interface/base_object_classes/generated/generated_base_object_class_schemas.json" +SCHEMA_INPUT_PATH="../weave/trace_server/interface/builtin_object_classes/generated/generated_base_object_class_schemas.json" SCHEMA_OUTPUT_PATH="./src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/generatedBaseObjectClasses.zod.ts" echo "Generating schemas..." diff --git a/weave/flow/annotation_spec.py b/weave/flow/annotation_spec.py index 5d6f391b0e7..aefaa01f0f7 100644 --- a/weave/flow/annotation_spec.py +++ b/weave/flow/annotation_spec.py @@ -1,4 +1,4 @@ -from weave.trace_server.interface.base_object_classes import annotation_spec +from weave.trace_server.interface.builtin_object_classes import annotation_spec # Re-export: AnnotationSpec = annotation_spec.AnnotationSpec diff --git a/weave/flow/leaderboard.py b/weave/flow/leaderboard.py index 14fce2cf5e9..ee68d3761cb 100644 --- a/weave/flow/leaderboard.py +++ b/weave/flow/leaderboard.py @@ -4,7 +4,7 @@ from weave.trace.refs import OpRef from weave.trace.weave_client import WeaveClient, get_ref -from weave.trace_server.interface.base_object_classes import leaderboard +from weave.trace_server.interface.builtin_object_classes import leaderboard from weave.trace_server.trace_server_interface import CallsFilter diff --git a/weave/scripts/generate_base_object_schemas.py b/weave/scripts/generate_base_object_schemas.py index c31d31a8c33..236d6a4892c 100644 --- a/weave/scripts/generate_base_object_schemas.py +++ b/weave/scripts/generate_base_object_schemas.py @@ -3,7 +3,7 @@ from pydantic import create_model -from weave.trace_server.interface.base_object_classes.builtin_object_registry import ( +from weave.trace_server.interface.builtin_object_classes.builtin_object_registry import ( BUILTIN_OBJECT_REGISTRY, ) diff --git a/weave/trace/api.py b/weave/trace/api.py index 294308cbb67..3553805e66b 100644 --- a/weave/trace/api.py +++ b/weave/trace/api.py @@ -26,7 +26,7 @@ should_disable_weave, ) from weave.trace.table import Table -from weave.trace_server.interface.base_object_classes import leaderboard +from weave.trace_server.interface.builtin_object_classes import leaderboard def init( diff --git a/weave/trace/base_objects.py b/weave/trace/base_objects.py index b07994566e4..900b6af588d 100644 --- a/weave/trace/base_objects.py +++ b/weave/trace/base_objects.py @@ -1 +1 @@ -from weave.trace_server.interface.base_object_classes.builtin_object_registry import * +from weave.trace_server.interface.builtin_object_classes.builtin_object_registry import * diff --git a/weave/trace/serialize.py b/weave/trace/serialize.py index 9d54f4549c5..5e0c6006aa5 100644 --- a/weave/trace/serialize.py +++ b/weave/trace/serialize.py @@ -9,7 +9,7 @@ from weave.trace.object_record import ObjectRecord from weave.trace.refs import ObjectRef, TableRef, parse_uri from weave.trace.sanitize import REDACT_KEYS, REDACTED_VALUE -from weave.trace_server.interface.base_object_classes.builtin_object_registry import ( +from weave.trace_server.interface.builtin_object_classes.builtin_object_registry import ( BUILTIN_OBJECT_REGISTRY, ) from weave.trace_server.trace_server_interface import ( diff --git a/weave/trace_server/actions_worker/actions/contains_words.py b/weave/trace_server/actions_worker/actions/contains_words.py index b272955a7e3..1898078f32f 100644 --- a/weave/trace_server/actions_worker/actions/contains_words.py +++ b/weave/trace_server/actions_worker/actions/contains_words.py @@ -1,7 +1,7 @@ import json from typing import Any -from weave.trace_server.interface.base_object_classes.actions import ( +from weave.trace_server.interface.builtin_object_classes.actions import ( ContainsWordsActionConfig, ) from weave.trace_server.trace_server_interface import ( diff --git a/weave/trace_server/actions_worker/actions/llm_judge.py b/weave/trace_server/actions_worker/actions/llm_judge.py index 6ae8134cd22..4ad6a432332 100644 --- a/weave/trace_server/actions_worker/actions/llm_judge.py +++ b/weave/trace_server/actions_worker/actions/llm_judge.py @@ -1,7 +1,7 @@ import json from typing import Any -from weave.trace_server.interface.base_object_classes.actions import ( +from weave.trace_server.interface.builtin_object_classes.actions import ( LlmJudgeActionConfig, ) from weave.trace_server.trace_server_interface import ( diff --git a/weave/trace_server/actions_worker/dispatcher.py b/weave/trace_server/actions_worker/dispatcher.py index 07c4296fcce..a87f123a917 100644 --- a/weave/trace_server/actions_worker/dispatcher.py +++ b/weave/trace_server/actions_worker/dispatcher.py @@ -6,7 +6,7 @@ do_contains_words_action, ) from weave.trace_server.actions_worker.actions.llm_judge import do_llm_judge_action -from weave.trace_server.interface.base_object_classes.actions import ( +from weave.trace_server.interface.builtin_object_classes.actions import ( ActionConfigType, ActionSpec, ContainsWordsActionConfig, diff --git a/weave/trace_server/feedback.py b/weave/trace_server/feedback.py index 33d7c9c31cb..94aeb8497b3 100644 --- a/weave/trace_server/feedback.py +++ b/weave/trace_server/feedback.py @@ -3,7 +3,7 @@ from weave.trace_server import refs_internal as ri from weave.trace_server import trace_server_interface as tsi from weave.trace_server.errors import InvalidRequest -from weave.trace_server.interface.base_object_classes.annotation_spec import ( +from weave.trace_server.interface.builtin_object_classes.annotation_spec import ( AnnotationSpec, ) from weave.trace_server.interface.feedback_types import ( diff --git a/weave/trace_server/interface/base_object_classes/actions.py b/weave/trace_server/interface/builtin_object_classes/actions.py similarity index 95% rename from weave/trace_server/interface/base_object_classes/actions.py rename to weave/trace_server/interface/builtin_object_classes/actions.py index d0ed77da07a..45207f5e1fc 100644 --- a/weave/trace_server/interface/base_object_classes/actions.py +++ b/weave/trace_server/interface/builtin_object_classes/actions.py @@ -3,7 +3,7 @@ import jsonschema from pydantic import BaseModel, Field, field_validator -from weave.trace_server.interface.base_object_classes import base_object_def +from weave.trace_server.interface.builtin_object_classes import base_object_def class LlmJudgeActionConfig(BaseModel): diff --git a/weave/trace_server/interface/base_object_classes/annotation_spec.py b/weave/trace_server/interface/builtin_object_classes/annotation_spec.py similarity index 98% rename from weave/trace_server/interface/base_object_classes/annotation_spec.py rename to weave/trace_server/interface/builtin_object_classes/annotation_spec.py index a28e06d512c..a581a747086 100644 --- a/weave/trace_server/interface/base_object_classes/annotation_spec.py +++ b/weave/trace_server/interface/builtin_object_classes/annotation_spec.py @@ -4,7 +4,7 @@ from pydantic import BaseModel, Field, create_model, field_validator, model_validator from pydantic.fields import FieldInfo -from weave.trace_server.interface.base_object_classes import base_object_def +from weave.trace_server.interface.builtin_object_classes import base_object_def SUPPORTED_PRIMITIVES = (int, float, bool, str) diff --git a/weave/trace_server/interface/base_object_classes/base_object_def.py b/weave/trace_server/interface/builtin_object_classes/base_object_def.py similarity index 100% rename from weave/trace_server/interface/base_object_classes/base_object_def.py rename to weave/trace_server/interface/builtin_object_classes/base_object_def.py diff --git a/weave/trace_server/interface/base_object_classes/builtin_object_registry.py b/weave/trace_server/interface/builtin_object_classes/builtin_object_registry.py similarity index 56% rename from weave/trace_server/interface/base_object_classes/builtin_object_registry.py rename to weave/trace_server/interface/builtin_object_classes/builtin_object_registry.py index e5c1d842585..9cc76cefb2e 100644 --- a/weave/trace_server/interface/base_object_classes/builtin_object_registry.py +++ b/weave/trace_server/interface/builtin_object_classes/builtin_object_registry.py @@ -1,10 +1,12 @@ -from weave.trace_server.interface.base_object_classes.actions import ActionSpec -from weave.trace_server.interface.base_object_classes.annotation_spec import ( +from weave.trace_server.interface.builtin_object_classes.actions import ActionSpec +from weave.trace_server.interface.builtin_object_classes.annotation_spec import ( AnnotationSpec, ) -from weave.trace_server.interface.base_object_classes.base_object_def import BaseObject -from weave.trace_server.interface.base_object_classes.leaderboard import Leaderboard -from weave.trace_server.interface.base_object_classes.test_only_example import ( +from weave.trace_server.interface.builtin_object_classes.base_object_def import ( + BaseObject, +) +from weave.trace_server.interface.builtin_object_classes.leaderboard import Leaderboard +from weave.trace_server.interface.builtin_object_classes.test_only_example import ( TestOnlyExample, TestOnlyNestedBaseObject, ) diff --git a/weave/trace_server/interface/base_object_classes/generated/generated_base_object_class_schemas.json b/weave/trace_server/interface/builtin_object_classes/generated/generated_base_object_class_schemas.json similarity index 100% rename from weave/trace_server/interface/base_object_classes/generated/generated_base_object_class_schemas.json rename to weave/trace_server/interface/builtin_object_classes/generated/generated_base_object_class_schemas.json diff --git a/weave/trace_server/interface/base_object_classes/leaderboard.py b/weave/trace_server/interface/builtin_object_classes/leaderboard.py similarity index 80% rename from weave/trace_server/interface/base_object_classes/leaderboard.py rename to weave/trace_server/interface/builtin_object_classes/leaderboard.py index c55be78e80f..19b5aa2bbaf 100644 --- a/weave/trace_server/interface/base_object_classes/leaderboard.py +++ b/weave/trace_server/interface/builtin_object_classes/leaderboard.py @@ -2,7 +2,7 @@ from pydantic import BaseModel -from weave.trace_server.interface.base_object_classes import base_object_def +from weave.trace_server.interface.builtin_object_classes import base_object_def class LeaderboardColumn(BaseModel): diff --git a/weave/trace_server/interface/base_object_classes/test_only_example.py b/weave/trace_server/interface/builtin_object_classes/test_only_example.py similarity index 90% rename from weave/trace_server/interface/base_object_classes/test_only_example.py rename to weave/trace_server/interface/builtin_object_classes/test_only_example.py index 49afb93bf89..8d8cd093f80 100644 --- a/weave/trace_server/interface/base_object_classes/test_only_example.py +++ b/weave/trace_server/interface/builtin_object_classes/test_only_example.py @@ -1,6 +1,6 @@ from pydantic import BaseModel -from weave.trace_server.interface.base_object_classes import base_object_def +from weave.trace_server.interface.builtin_object_classes import base_object_def class TestOnlyNestedBaseModel(BaseModel): diff --git a/weave/trace_server/object_class_util.py b/weave/trace_server/object_class_util.py index b48a23a769a..668d8fd3c15 100644 --- a/weave/trace_server/object_class_util.py +++ b/weave/trace_server/object_class_util.py @@ -2,7 +2,7 @@ from pydantic import BaseModel -from weave.trace_server.interface.base_object_classes.builtin_object_registry import ( +from weave.trace_server.interface.builtin_object_classes.builtin_object_registry import ( BUILTIN_OBJECT_REGISTRY, )