diff --git a/docs/docs/reference/python-sdk/weave/index.md b/docs/docs/reference/python-sdk/weave/index.md
index 465b4cc22d4a..7ea6afb28f1b 100644
--- a/docs/docs/reference/python-sdk/weave/index.md
+++ b/docs/docs/reference/python-sdk/weave/index.md
@@ -1,7 +1,6 @@
---
sidebar_label: weave
---
-
# weave
@@ -9,11 +8,8 @@ The top-level functions and classes for working with Weave.
---
-
# API Overview
-
-
## Classes
- [`obj.Object`](#class-object)
@@ -24,18 +20,16 @@ The top-level functions and classes for working with Weave.
## Functions
-- [`trace_api.init`](#function-init): Initialize weave tracking, logging to a wandb project.
-- [`trace_api.publish`](#function-publish): Save and version a python object.
-- [`trace_api.ref`](#function-ref): Construct a Ref to a Weave object.
+- [`trace.api.init`](#function-init): Initialize weave tracking, logging to a wandb project.
+- [`trace.api.publish`](#function-publish): Save and version a python object.
+- [`trace.api.ref`](#function-ref): Construct a Ref to a Weave object.
- [`call_context.get_current_call`](#function-get_current_call): Get the Call object for the currently executing Op, within that Op.
-- [`trace_api.finish`](#function-finish): Stops logging to weave.
-- [`op.op`](#function-op): A decorator to weave op-ify a function or method. Works for both sync and async.
-
+- [`trace.api.finish`](#function-finish): Stops logging to weave.
+- [`op.op`](#function-op): A decorator to weave op-ify a function or method. Works for both sync and async.
---
-
-
+
### function `init`
@@ -46,26 +40,22 @@ init(
) → WeaveClient
```
-Initialize weave tracking, logging to a wandb project.
-
-Logging is initialized globally, so you do not need to keep a reference to the return value of init.
-
-Following init, calls of weave.op() decorated functions will be logged to the specified project.
+Initialize weave tracking, logging to a wandb project.
+Logging is initialized globally, so you do not need to keep a reference to the return value of init.
+Following init, calls of weave.op() decorated functions will be logged to the specified project.
**Args:**
-
- - `project_name`: The name of the Weights & Biases project to log to.
-
+- `project_name`: The name of the Weights & Biases project to log to.
**Returns:**
- A Weave client.
+A Weave client.
---
-
+
### function `publish`
@@ -73,27 +63,23 @@ Following init, calls of weave.op() decorated functions will be logged to the sp
publish(obj: Any, name: Optional[str] = None) → ObjectRef
```
-Save and version a python object.
-
-If an object with name already exists, and the content hash of obj does not match the latest version of that object, a new version will be created.
-
-TODO: Need to document how name works with this change.
+Save and version a python object.
+If an object with name already exists, and the content hash of obj does not match the latest version of that object, a new version will be created.
+TODO: Need to document how name works with this change.
**Args:**
-
- - `obj`: The object to save and version.
- - `name`: The name to save the object under.
-
+- `obj`: The object to save and version.
+- `name`: The name to save the object under.
**Returns:**
- A weave Ref to the saved object.
+A weave Ref to the saved object.
---
-
+
### function `ref`
@@ -101,22 +87,16 @@ TODO: Need to document how name works with this change.
ref(location: str) → ObjectRef
```
-Construct a Ref to a Weave object.
-
-TODO: what happens if obj does not exist
-
+Construct a Ref to a Weave object.
+TODO: what happens if obj does not exist
**Args:**
-
- - `location`: A fully-qualified weave ref URI, or if weave.init() has been called, "name:version" or just "name" ("latest" will be used for version in this case).
-
-
-
+- `location`: A fully-qualified weave ref URI, or if weave.init() has been called, "name:version" or just "name" ("latest" will be used for version in this case).
**Returns:**
- A weave Ref to the object.
+A weave Ref to the object.
---
@@ -128,9 +108,9 @@ TODO: what happens if obj does not exist
get_current_call() → Optional[ForwardRef('Call')]
```
-Get the Call object for the currently executing Op, within that Op.
+Get the Call object for the currently executing Op, within that Op.
-This allows you to access attributes of the Call such as its id or feedback while it is running.
+This allows you to access attributes of the Call such as its id or feedback while it is running.
```python
@weave.op
@@ -138,18 +118,18 @@ def hello(name: str) -> None:
print(f"Hello {name}!")
current_call = weave.get_current_call()
print(current_call.id)
-```
+```
-It is also possible to access a Call after the Op has returned.
+It is also possible to access a Call after the Op has returned.
-If you have the Call's id, perhaps from the UI, you can use the `call` method on the `WeaveClient` returned from `weave.init` to retrieve the Call object.
+If you have the Call's id, perhaps from the UI, you can use the `call` method on the `WeaveClient` returned from `weave.init` to retrieve the Call object.
```python
client = weave.init("")
mycall = client.call("")
-```
+```
-Alternately, after defining your Op you can use its `call` method. For example:
+Alternately, after defining your Op you can use its `call` method. For example:
```python
@weave.op
@@ -158,16 +138,14 @@ def hello(name: str) -> None:
mycall = hello.call("world")
print(mycall.id)
-```
-
-
+```
**Returns:**
- The Call object for the currently executing Op, or None if tracking has not been initialized or this method is invoked outside an Op.
+The Call object for the currently executing Op, or None if tracking has not been initialized or this method is invoked outside an Op.
---
-
+
### function `finish`
@@ -175,9 +153,9 @@ print(mycall.id)
finish() → None
```
-Stops logging to weave.
+Stops logging to weave.
-Following finish, calls of weave.op() decorated functions will no longer be logged. You will need to run weave.init() again to resume logging.
+Following finish, calls of weave.op() decorated functions will no longer be logged. You will need to run weave.init() again to resume logging.
---
@@ -189,15 +167,13 @@ Following finish, calls of weave.op() decorated functions will no longer be logg
op(*args: Any, **kwargs: Any) → Union[Callable[[Any], Op], Op]
```
-A decorator to weave op-ify a function or method. Works for both sync and async.
-
-Decorated functions and methods can be called as normal, but will also automatically track calls in the Weave UI.
-
-If you don't call `weave.init` then the function will behave as if it were not decorated.
+A decorator to weave op-ify a function or method. Works for both sync and async.
+Decorated functions and methods can be called as normal, but will also automatically track calls in the Weave UI.
+If you don't call `weave.init` then the function will behave as if it were not decorated.
-Example usage:
+Example usage:
```python
import weave
@@ -213,7 +189,7 @@ async def extract():
)
await extract() # calls the function and tracks the call in the Weave UI
-```
+```
---
@@ -221,14 +197,11 @@ await extract() # calls the function and tracks the call in the Weave UI
## class `Object`
-
-
-
-
**Pydantic Fields:**
- `name`: `typing.Optional[str]`
- `description`: `typing.Optional[str]`
+
---
@@ -243,10 +216,6 @@ handle_relocatable_object(
) → Any
```
-
-
-
-
---
@@ -257,22 +226,15 @@ handle_relocatable_object(
model_post_init(_Object__context: Any) → None
```
-
-
-
-
-
---
## class `Dataset`
-Dataset object with easy saving and automatic versioning
-
+Dataset object with easy saving and automatic versioning
**Examples:**
-
```python
# Create a dataset
@@ -290,14 +252,14 @@ dataset_ref = weave.ref('grammar').get()
# Access a specific example
example_label = dataset_ref.rows[2]['sentence']
-```
-
+```
**Pydantic Fields:**
- `name`: `typing.Optional[str]`
- `description`: `typing.Optional[str]`
- `rows`: ``
+
---
@@ -308,24 +270,17 @@ example_label = dataset_ref.rows[2]['sentence']
convert_to_table(rows: Any) → Table
```
-
-
-
-
-
---
## class `Model`
-Intended to capture a combination of code and data the operates on an input. For example it might call an LLM with a prompt to make a prediction or generate text.
-
-When you change the attributes or the code that defines your model, these changes will be logged and the version will be updated. This ensures that you can compare the predictions across different versions of your model. Use this to iterate on prompts or to try the latest LLM and compare predictions across different settings
+Intended to capture a combination of code and data the operates on an input. For example it might call an LLM with a prompt to make a prediction or generate text.
+When you change the attributes or the code that defines your model, these changes will be logged and the version will be updated. This ensures that you can compare the predictions across different versions of your model. Use this to iterate on prompts or to try the latest LLM and compare predictions across different settings
**Examples:**
-
```python
class YourModel(Model):
@@ -337,13 +292,13 @@ class YourModel(Model):
# Model logic goes here
prediction = self.attribute1 + ' ' + input_data
return {'pred': prediction}
-```
-
+```
**Pydantic Fields:**
- `name`: `typing.Optional[str]`
- `description`: `typing.Optional[str]`
+
---
@@ -354,28 +309,21 @@ class YourModel(Model):
get_infer_method() → Callable
```
-
-
-
-
-
---
## class `Evaluation`
-Sets up an evaluation which includes a set of scorers and a dataset.
-
-Calling evaluation.evaluate(model) will pass in rows from a dataset into a model matching the names of the columns of the dataset to the argument names in model.predict.
-Then it will call all of the scorers and save the results in weave.
+Sets up an evaluation which includes a set of scorers and a dataset.
-If you want to preprocess the rows from the dataset you can pass in a function to preprocess_model_input.
+Calling evaluation.evaluate(model) will pass in rows from a dataset into a model matching the names of the columns of the dataset to the argument names in model.predict.
+Then it will call all of the scorers and save the results in weave.
+If you want to preprocess the rows from the dataset you can pass in a function to preprocess_model_input.
**Examples:**
-
```python
# Collect your examples
@@ -405,8 +353,7 @@ evaluation = Evaluation(
weave.init('intro-example')
# Run the evaluation
asyncio.run(evaluation.evaluate(function_to_evaluate))
-```
-
+```
**Pydantic Fields:**
@@ -416,6 +363,7 @@ asyncio.run(evaluation.evaluate(function_to_evaluate))
- `scorers`: `typing.Optional[list[typing.Union[typing.Callable, trace.op.Op, flow.scorer.Scorer]]]`
- `preprocess_model_input`: `typing.Optional[typing.Callable]`
- `trials`: ``
+
---
@@ -426,10 +374,6 @@ asyncio.run(evaluation.evaluate(function_to_evaluate))
evaluate(model: Union[Callable, Model]) → dict
```
-
-
-
-
---
@@ -440,10 +384,6 @@ evaluate(model: Union[Callable, Model]) → dict
model_post_init(_Evaluation__context: Any) → None
```
-
-
-
-
---
@@ -454,10 +394,6 @@ model_post_init(_Evaluation__context: Any) → None
predict_and_score(model: Union[Callable, Model], example: dict) → dict
```
-
-
-
-
---
@@ -468,25 +404,17 @@ predict_and_score(model: Union[Callable, Model], example: dict) → dict
summarize(eval_table: EvaluationResults) → dict
```
-
-
-
-
-
---
## class `Scorer`
-
-
-
-
**Pydantic Fields:**
- `name`: `typing.Optional[str]`
- `description`: `typing.Optional[str]`
+
---
@@ -497,10 +425,6 @@ summarize(eval_table: EvaluationResults) → dict
score(target: Any, model_output: Any) → Any
```
-
-
-
-
---
@@ -510,8 +434,3 @@ score(target: Any, model_output: Any) → Any
```python
summarize(score_rows: list) → Optional[dict]
```
-
-
-
-
-
diff --git a/weave/__init__.py b/weave/__init__.py
index 97863a1d35f6..207728c31fc8 100644
--- a/weave/__init__.py
+++ b/weave/__init__.py
@@ -16,7 +16,7 @@
from . import storage
from .query_api import *
-from .trace_api import *
+from .trace.api import *
from .errors import *
@@ -64,7 +64,7 @@
# Special object informing doc generation tooling which symbols
# to document & to associate with this module.
__docspec__ = [
- # Re-exported from trace_api
+ # Re-exported from trace.api
init,
publish,
ref,
diff --git a/weave/api.py b/weave/api.py
index 17829d180925..6f00d4220401 100644
--- a/weave/api.py
+++ b/weave/api.py
@@ -1,4 +1,4 @@
"""These are the top-level functions in the `import weave` namespace."""
from .query_api import *
-from .trace_api import *
+from .trace.api import *
diff --git a/weave/deploy/modal/stub.py b/weave/deploy/modal/stub.py
index cfd0bd083278..2dee6e838e6e 100644
--- a/weave/deploy/modal/stub.py
+++ b/weave/deploy/modal/stub.py
@@ -27,7 +27,7 @@
@asgi_app(label=safe_name(uri.name))
def fastapi_app() -> FastAPI:
from weave import api
- from weave.serve_fastapi import object_method_app
+ from weave.trace.serve_fastapi import object_method_app
uri_ref = parse_uri(os.environ["MODEL_REF"])
if not isinstance(uri_ref, ObjectRef):
diff --git a/weave/legacy/arrow/list_.py b/weave/legacy/arrow/list_.py
index f8a7f09bbb3b..7cc6e84ddba6 100644
--- a/weave/legacy/arrow/list_.py
+++ b/weave/legacy/arrow/list_.py
@@ -12,7 +12,6 @@
from weave import (
errors,
- ref_util,
weave_internal,
)
from weave import weave_types as types
@@ -40,6 +39,7 @@
tag_store,
tagged_value_type,
)
+from weave.trace import ref_util
def reverse_dict(d: dict) -> dict:
diff --git a/weave/legacy/artifact_fs.py b/weave/legacy/artifact_fs.py
index f09e110e6123..d5c71f3c6438 100644
--- a/weave/legacy/artifact_fs.py
+++ b/weave/legacy/artifact_fs.py
@@ -6,10 +6,11 @@
import os
import typing
-from weave import errors, ref_util
+from weave import errors
from weave import weave_types as types
from weave.legacy import artifact_base, file_base, object_context, ref_base, uris
from weave.legacy.language_features.tagging import tag_store
+from weave.trace import ref_util
if typing.TYPE_CHECKING:
from weave.legacy import graph
diff --git a/weave/legacy/box.py b/weave/legacy/box.py
index f089e03acdc1..b957fc6ba3f3 100644
--- a/weave/legacy/box.py
+++ b/weave/legacy/box.py
@@ -4,7 +4,7 @@
import numpy as np
-from weave import ref_util
+from weave.trace import ref_util
from weave.legacy import context_state
diff --git a/weave/legacy/object_type_ref_util.py b/weave/legacy/object_type_ref_util.py
index 40e70fff6fdf..53787c4c4547 100644
--- a/weave/legacy/object_type_ref_util.py
+++ b/weave/legacy/object_type_ref_util.py
@@ -1,6 +1,6 @@
import typing
-from weave import ref_util
+from weave.trace import ref_util
from weave.legacy import context_state
diff --git a/weave/tests/legacy/test_refs.py b/weave/tests/legacy/test_refs.py
index a1cfd4ccca78..ac9923eaaad7 100644
--- a/weave/tests/legacy/test_refs.py
+++ b/weave/tests/legacy/test_refs.py
@@ -4,13 +4,14 @@
from weave.flow.obj import Object
from weave.legacy import artifact_local
from weave.legacy import ops_arrow as arrow
+from weave.trace import ref_util
from weave.trace_server.refs_internal import (
DICT_KEY_EDGE_NAME,
LIST_INDEX_EDGE_NAME,
OBJECT_ATTR_EDGE_NAME,
)
-from ... import ref_util, storage
+from ... import storage
def test_laref_artifact_version_1():
diff --git a/weave/trace_api.py b/weave/trace/api.py
similarity index 96%
rename from weave/trace_api.py
rename to weave/trace/api.py
index 48a3b0a93af3..5fd03e25d675 100644
--- a/weave/trace_api.py
+++ b/weave/trace/api.py
@@ -11,18 +11,18 @@
# TODO: type_serializers 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.
-from . import (
+from .. import (
type_serializers, # noqa: F401
urls,
util,
weave_init,
)
+from . import context, weave_client
+from .constants import TRACE_OBJECT_EMOJI
+from .op import Op, op
+from .refs import ObjectRef, parse_uri
+from .settings import UserSettings, parse_and_apply_settings
from .table import Table
-from .trace import context, weave_client
-from .trace.constants import TRACE_OBJECT_EMOJI
-from .trace.op import Op, op
-from .trace.refs import ObjectRef, parse_uri
-from .trace.settings import UserSettings, parse_and_apply_settings
def init(
diff --git a/weave/exception.py b/weave/trace/exception.py
similarity index 100%
rename from weave/exception.py
rename to weave/trace/exception.py
diff --git a/weave/ref_util.py b/weave/trace/ref_util.py
similarity index 95%
rename from weave/ref_util.py
rename to weave/trace/ref_util.py
index 968a584ca61b..93ec19decd7b 100644
--- a/weave/ref_util.py
+++ b/weave/trace/ref_util.py
@@ -3,8 +3,7 @@
from urllib import parse
from weave.legacy import box
-
-from .trace_server import refs_internal
+from weave.trace_server import refs_internal
DICT_KEY_EDGE_NAME = refs_internal.DICT_KEY_EDGE_NAME
LIST_INDEX_EDGE_NAME = refs_internal.LIST_INDEX_EDGE_NAME
@@ -23,9 +22,7 @@ def parse_local_ref_str(s: str) -> typing.Tuple[str, typing.Optional[list[str]]]
def val_with_relative_ref(
parent_object: typing.Any, child_object: typing.Any, ref_extra_parts: list[str]
) -> typing.Any:
- from weave.legacy import context_state
-
- from .legacy import ref_base
+ from weave.legacy import context_state, ref_base
# If we already have a ref, resolve it
if isinstance(child_object, ref_base.Ref):
@@ -34,7 +31,7 @@ def val_with_relative_ref(
# Only do this if ref_tracking_enabled right now. I just want to
# avoid introducing new behavior into W&B prod for the moment.
if context_state.ref_tracking_enabled():
- from . import storage
+ from .. import storage
child_ref = storage.get_ref(child_object)
parent_ref = ref_base.get_ref(parent_object)
diff --git a/weave/serve_fastapi.py b/weave/trace/serve_fastapi.py
similarity index 98%
rename from weave/serve_fastapi.py
rename to weave/trace/serve_fastapi.py
index ca63901d03b4..3e3bc7b7286d 100644
--- a/weave/serve_fastapi.py
+++ b/weave/trace/serve_fastapi.py
@@ -17,8 +17,8 @@
from weave.trace.op import Op
from weave.trace.refs import ObjectRef
-from . import errors
-from .legacy import weave_pydantic
+from .. import errors
+from ..legacy import weave_pydantic
key_cache: cache.LruTimeWindowCache[str, typing.Optional[bool]] = (
cache.LruTimeWindowCache(datetime.timedelta(minutes=5))
diff --git a/weave/table.py b/weave/trace/table.py
similarity index 100%
rename from weave/table.py
rename to weave/trace/table.py
diff --git a/weave/trace_sentry.py b/weave/trace/trace_sentry.py
similarity index 99%
rename from weave/trace_sentry.py
rename to weave/trace/trace_sentry.py
index 5e7e80d1a2f3..38bd88b1e213 100644
--- a/weave/trace_sentry.py
+++ b/weave/trace/trace_sentry.py
@@ -90,7 +90,7 @@ def setup(self) -> None:
to avoid the possibility of interfering with the user's
own Sentry SDK setup.
"""
- from . import version
+ from .. import version
client = sentry_sdk.Client(
dsn=self.dsn,
diff --git a/weave/trace/vals.py b/weave/trace/vals.py
index 8933dcc201b3..c92f9a024ec6 100644
--- a/weave/trace/vals.py
+++ b/weave/trace/vals.py
@@ -9,7 +9,6 @@
from pydantic import v1 as pydantic_v1
from weave.client_context.weave_client import get_weave_client
-from weave.table import Table
from weave.trace import box
from weave.trace.errors import InternalError
from weave.trace.object_record import ObjectRecord
@@ -24,6 +23,7 @@
TableRef,
)
from weave.trace.serialize import from_json
+from weave.trace.table import Table
from weave.trace_server.trace_server_interface import (
ObjReadReq,
TableQueryReq,
diff --git a/weave/trace/weave_client.py b/weave/trace/weave_client.py
index 44511247c4cc..c46806d1399e 100644
--- a/weave/trace/weave_client.py
+++ b/weave/trace/weave_client.py
@@ -10,11 +10,10 @@
import pydantic
from requests import HTTPError
-from weave import trace_sentry, urls, version
+from weave import urls, version
from weave.client_context import weave_client as weave_client_context
-from weave.exception import exception_to_json_str
-from weave.table import Table
-from weave.trace import call_context
+from weave.trace import call_context, trace_sentry
+from weave.trace.exception import exception_to_json_str
from weave.trace.feedback import FeedbackQuery, RefFeedbackQuery
from weave.trace.object_record import (
ObjectRecord,
@@ -26,6 +25,7 @@
from weave.trace.refs import CallRef, ObjectRef, OpRef, Ref, TableRef
from weave.trace.serialize import from_json, isinstance_namedtuple, to_json
from weave.trace.serializer import get_serializer_for_obj
+from weave.trace.table import Table
from weave.trace.vals import WeaveObject, WeaveTable, make_trace_obj
from weave.trace_server.ids import generate_id
from weave.trace_server.trace_server_interface import (
diff --git a/weave/weave_init.py b/weave/weave_init.py
index b2ef6d98acd6..21d0e31ab6ae 100644
--- a/weave/weave_init.py
+++ b/weave/weave_init.py
@@ -2,8 +2,8 @@
from weave.client_context import weave_client as weave_client_context
-from . import errors, init_message, trace_sentry
-from .trace import autopatch, weave_client
+from . import errors, init_message
+from .trace import autopatch, trace_sentry, weave_client
from .trace_server import remote_http_trace_server, sqlite_trace_server
_current_inited_client = None