From 893448fc7b1e312c78dd447a87282da759774665 Mon Sep 17 00:00:00 2001
From: dbrian57 <17599248+dbrian57@users.noreply.github.com>
Date: Fri, 16 Jan 2026 21:35:08 +0000
Subject: [PATCH 1/2] chore: Update reference documentation (Weave 0.52.24)
---
docs.json | 15 +-
weave/reference/python-sdk.mdx | 3303 +-
weave/reference/python-sdk/trace/feedback.mdx | 88 +-
weave/reference/python-sdk/trace/op.mdx | 209 +-
weave/reference/python-sdk/trace/util.mdx | 199 +-
.../python-sdk/trace/weave_client.mdx | 268 +-
.../trace_server/trace_server_interface.mdx | 3604 +-
.../remote_http_trace_server.mdx | 596 +-
weave/reference/python-sdk/weave/index.mdx | 6825 ---
weave/reference/python-sdk/weave/trace/op.mdx | 553 -
.../python-sdk/weave/trace/weave_client.mdx | 11749 -----
.../trace_server/trace_server_interface.mdx | 36060 ----------------
weave/reference/service-api.mdx | 68 +
weave/reference/typescript-sdk.mdx | 1 +
.../typescript-sdk/classes/dataset.mdx | 20 +-
.../typescript-sdk/classes/evaluation.mdx | 14 +-
.../classes/evaluationlogger.mdx | 8 +-
.../typescript-sdk/classes/messagesprompt.mdx | 36 +-
.../typescript-sdk/classes/objectref.mdx | 49 +-
.../typescript-sdk/classes/scorelogger.mdx | 8 +-
.../typescript-sdk/classes/stringprompt.mdx | 36 +-
.../typescript-sdk/classes/weaveclient.mdx | 81 +-
.../typescript-sdk/classes/weaveobject.mdx | 10 +-
.../typescript-sdk/functions/init.mdx | 4 +-
.../typescript-sdk/functions/login.mdx | 2 +-
.../reference/typescript-sdk/functions/op.mdx | 10 +-
.../requirecurrentcallstackentry.mdx | 2 +-
.../functions/requirecurrentchildsummary.mdx | 2 +-
.../typescript-sdk/functions/weaveaudio.mdx | 2 +-
.../typescript-sdk/functions/weaveimage.mdx | 2 +-
.../functions/withattributes.mdx | 43 +
.../typescript-sdk/functions/wrapopenai.mdx | 2 +-
.../typescript-sdk/interfaces/callschema.mdx | 32 +-
.../typescript-sdk/interfaces/callsfilter.mdx | 18 +-
.../typescript-sdk/interfaces/weaveaudio.mdx | 6 +-
.../typescript-sdk/interfaces/weaveimage.mdx | 6 +-
.../typescript-sdk/type-aliases/op.mdx | 2 +-
.../type-aliases/opdecorator.mdx | 3 +-
38 files changed, 6455 insertions(+), 57481 deletions(-)
delete mode 100644 weave/reference/python-sdk/weave/index.mdx
delete mode 100644 weave/reference/python-sdk/weave/trace/op.mdx
delete mode 100644 weave/reference/python-sdk/weave/trace/weave_client.mdx
delete mode 100644 weave/reference/python-sdk/weave/trace_server/trace_server_interface.mdx
create mode 100644 weave/reference/typescript-sdk/functions/withattributes.mdx
diff --git a/docs.json b/docs.json
index 1f311f94e6..cb59c361c1 100644
--- a/docs.json
+++ b/docs.json
@@ -991,14 +991,6 @@
"pages": [
"weave/reference/python-sdk/trace_server_bindings/remote_http_trace_server"
]
- },
- {
- "group": "Other",
- "pages": [
- "weave/reference/python-sdk/weave/trace/op",
- "weave/reference/python-sdk/weave/trace/weave_client",
- "weave/reference/python-sdk/weave/trace_server/trace_server_interface"
- ]
}
]
},
@@ -1030,6 +1022,7 @@
"weave/reference/typescript-sdk/functions/requirecurrentchildsummary",
"weave/reference/typescript-sdk/functions/weaveaudio",
"weave/reference/typescript-sdk/functions/weaveimage",
+ "weave/reference/typescript-sdk/functions/withattributes",
"weave/reference/typescript-sdk/functions/wrapopenai"
]
},
@@ -1098,7 +1091,9 @@
"inference/usage-limits",
{
"group": "Tutorials",
- "pages": ["inference/tutorials/creating-lora"]
+ "pages": [
+ "inference/tutorials/creating-lora"
+ ]
},
{
"group": "API Reference",
@@ -2625,4 +2620,4 @@
}
],
"baseUrl": "https://docs.wandb.ai"
-}
+}
\ No newline at end of file
diff --git a/weave/reference/python-sdk.mdx b/weave/reference/python-sdk.mdx
index 2949788cdf..d5804006ac 100644
--- a/weave/reference/python-sdk.mdx
+++ b/weave/reference/python-sdk.mdx
@@ -3,280 +3,1578 @@ title: "weave"
description: "Python SDK reference for weave"
---
+import { SourceLink } from '/snippets/en/_includes/source-link.mdx';
+
# API Overview
---
-
+
+
+## class `Agent`
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `model_name`: ``
+- `temperature`: ``
+- `system_message`: ``
+- `tools`: `list[typing.Any]`
+
+
+
+### method `step`
+
+```python
+step(state: AgentState) → AgentState
+```
+
+Run a step of the agent.
+
+**Args:**
+
+
+ - `state`: The current state of the environment.
+ - `action`: The action to take.
+**Returns:**
+ The new state of the environment.
+
+---
+
+
+
+## class `AgentState`
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `history`: `list[typing.Any]`
+
+---
+
+
+
+## class `AnnotationSpec`
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `field_schema`: `dict[str, typing.Any]`
+- `unique_among_creators`: ``
+- `op_scope`: `list[str] | None`
+
+
+
+### classmethod `preprocess_field_schema`
+
+```python
+preprocess_field_schema(data: dict[str, Any]) → dict[str, Any]
+```
+
+---
+
+
+
+### classmethod `validate_field_schema`
+
+```python
+validate_field_schema(schema: dict[str, Any]) → dict[str, Any]
+```
+
+---
+
+
+
+### method `value_is_valid`
+
+```python
+value_is_valid(payload: Any) → bool
+```
+
+Validates a payload against this annotation spec's schema.
+
+**Args:**
+
+
+ - `payload`: The data to validate against the schema
+**Returns:**
+
+ - `bool`: True if validation succeeds, False otherwise
+
+---
+
+
+
+## class `Audio`
+A class representing audio data in a supported format (wav or mp3).
+
+This class handles audio data storage and provides methods for loading from different sources and exporting to files.
+
+**Attributes:**
+
+ - `format`: The audio format (currently supports 'wav' or 'mp3')
+ - `data`: The raw audio data as bytes
+
+**Args:**
+
+
+ - `data`: The audio data (bytes or base64 encoded string)
+ - `format`: The audio format ('wav' or 'mp3')
+ - `validate_base64`: Whether to attempt base64 decoding of the input data
+**Raises:**
+
+ - `ValueError`: If audio data is empty or format is not supported
+
+
+
+### method `__init__`
+
+```python
+__init__(
+ data: 'bytes',
+ format: 'SUPPORTED_FORMATS_TYPE',
+ validate_base64: 'bool' = True
+) → None
+```
+
+---
+
+
+
+### method `export`
+
+```python
+export(path: 'str | bytes | Path | PathLike') → None
+```
+
+Export audio data to a file.
+
+**Args:**
+
+
+---
+
+
+
+### classmethod `from_data`
+
+```python
+from_data(data: 'str | bytes', format: 'str') → Self
+```
+
+Create an Audio object from raw data and specified format.
+
+ - `path`: Path where the audio file should be written
+**Args:**
+
+
+ - `data`: Audio data as bytes or base64 encoded string
+ - `format`: Audio format ('wav' or 'mp3')
+**Returns:**
+
+ - `Audio`: A new Audio instance
+
+**Raises:**
+
+ - `ValueError`: If format is not supported
+
+---
+
+
+
+### classmethod `from_path`
+
+```python
+from_path(path: 'str | bytes | Path | PathLike') → Self
+```
+
+Create an Audio object from a file path.
+
+**Args:**
+
+
+ - `path`: Path to an audio file (must have .wav or .mp3 extension)
+**Returns:**
+
+ - `Audio`: A new Audio instance loaded from the file
+
+**Raises:**
+
+ - `ValueError`: If file doesn't exist or has unsupported extension
+
+---
+
+
+
+## class `Content`
+A class to represent content from various sources, resolving them to a unified byte-oriented representation with associated metadata.
+
+This class must be instantiated using one of its classmethods:
+- from_path()
+- from_bytes()
+- from_text()
+- from_url()
+- from_base64()
+- from_data_url()
+
+
+
+### method `__init__`
+
+```python
+__init__(*args: 'Any', **kwargs: 'Any') → None
+```
+
+Direct initialization is disabled. Please use a classmethod like `Content.from_path()` to create an instance.
+
+**Pydantic Fields:**
+
+- `data`: ``
+- `size`: ``
+- `mimetype`: ``
+- `digest`: ``
+- `filename`: ``
+- `content_type`: `typing.Literal['bytes', 'text', 'base64', 'file', 'url', 'data_url', 'data_url:base64', 'data_url:encoding', 'data_url:encoding:base64']`
+- `input_type`: ``
+- `encoding`: ``
+- `metadata`: `dict[str, typing.Any] | None`
+- `extension`: `str | None`
+
+---
+
+#### property art
+
+#### property ref
+
+---
+
+
+
+### method `as_string`
+
+```python
+as_string() → str
+```
+
+Display the data as a string. Bytes are decoded using the `encoding` attribute If base64, the data will be re-encoded to base64 bytes then decoded to an ASCII string
+
+**Returns:**
+ str.
+
+---
+
+
+
+### classmethod `from_base64`
+
+```python
+from_base64(
+ b64_data: 'str | bytes',
+ extension: 'str | None' = None,
+ mimetype: 'str | None' = None,
+ metadata: 'dict[str, Any] | None' = None
+) → Self
+```
+
+Initializes Content from a base64 encoded string or bytes.
+
+---
+
+
+
+### classmethod `from_bytes`
+
+```python
+from_bytes(
+ data: 'bytes',
+ extension: 'str | None' = None,
+ mimetype: 'str | None' = None,
+ metadata: 'dict[str, Any] | None' = None,
+ encoding: 'str' = 'utf-8'
+) → Self
+```
+
+Initializes Content from raw bytes.
+
+---
+
+
+
+### classmethod `from_data_url`
+
+```python
+from_data_url(url: 'str', metadata: 'dict[str, Any] | None' = None) → Self
+```
+
+Initializes Content from a data URL.
+
+---
+
+
+
+### classmethod `from_path`
+
+```python
+from_path(
+ path: 'str | Path',
+ encoding: 'str' = 'utf-8',
+ mimetype: 'str | None' = None,
+ metadata: 'dict[str, Any] | None' = None
+) → Self
+```
+
+Initializes Content from a local file path.
+
+---
+
+
+
+### classmethod `from_text`
+
+```python
+from_text(
+ text: 'str',
+ extension: 'str | None' = None,
+ mimetype: 'str | None' = None,
+ metadata: 'dict[str, Any] | None' = None,
+ encoding: 'str' = 'utf-8'
+) → Self
+```
+
+Initializes Content from a string of text.
+
+---
+
+
+
+### classmethod `from_url`
+
+```python
+from_url(
+ url: 'str',
+ headers: 'dict[str, Any] | None' = None,
+ timeout: 'int | None' = 30,
+ metadata: 'dict[str, Any] | None' = None
+) → Self
+```
+
+Initializes Content by fetching bytes from an HTTP(S) URL.
+
+Downloads the content, infers mimetype/extension from headers, URL path, and data, and constructs a Content object from the resulting bytes.
+
+---
+
+
+
+### classmethod `model_validate`
+
+```python
+model_validate(
+ obj: 'Any',
+ strict: 'bool | None' = None,
+ from_attributes: 'bool | None' = None,
+ context: 'dict[str, Any] | None' = None
+) → Self
+```
+
+Override model_validate to handle Content reconstruction from dict.
+
+---
+
+
+
+### classmethod `model_validate_json`
+
+```python
+model_validate_json(
+ json_data: 'str | bytes | bytearray',
+ strict: 'bool | None' = None,
+ context: 'dict[str, Any] | None' = None
+) → Self
+```
+
+Override model_validate_json to handle Content reconstruction from JSON.
+
+---
+
+
+
+### method `open`
+
+```python
+open() → bool
+```
+
+Open the file using the operating system's default application.
+
+This method uses the platform-specific mechanism to open the file with the default application associated with the file's type.
+
+**Returns:**
+
+ - `bool`: True if the file was successfully opened, False otherwise.
+
+---
+
+
+
+### method `save`
+
+```python
+save(dest: 'str | Path') → None
+```
+
+Copy the file to the specified destination path. Updates the filename and the path of the content to reflect the last saved copy.
+
+**Args:**
+
+
+---
+
+
+
+### method `serialize_data`
+
+```python
+serialize_data(data: 'bytes') → str
+```
+
+When dumping model in json mode
+
+---
+
+
+
+### method `to_data_url`
+
+```python
+to_data_url(use_base64: 'bool' = True) → str
+```
+
+Constructs a data URL from the content.
+
+ - `dest`: Destination path where the file will be copied to (string or pathlib.Path) The destination path can be a file or a directory. If dest has no file extension (e.g. .txt), destination will be considered a directory.
+**Args:**
+
+
+ - `use_base64`: If True, the data will be base64 encoded. Otherwise, it will be percent-encoded. Defaults to True.
+**Returns:**
+ A data URL string.
+
+---
+
+
+
+## class `Dataset`
+Dataset object with easy saving and automatic versioning.
+
+**Examples:**
+```python
+# Create a dataset
+dataset = Dataset(name='grammar', rows=[
+ {'id': '0', 'sentence': "He no likes ice cream.", 'correction': "He doesn't like ice cream."},
+ {'id': '1', 'sentence': "She goed to the store.", 'correction': "She went to the store."},
+ {'id': '2', 'sentence': "They plays video games all day.", 'correction': "They play video games all day."}
+])
+
+# Publish the dataset
+weave.publish(dataset)
+
+# Retrieve the dataset
+dataset_ref = weave.ref('grammar').get()
+
+# Access a specific example
+example_label = dataset_ref.rows[2]['sentence']
+```
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `rows`: `trace.table.Table | trace.vals.WeaveTable`
+
+
+
+### method `add_rows`
+
+```python
+add_rows(rows: Iterable[dict]) → Dataset
+```
+
+Create a new dataset version by appending rows to the existing dataset.
+
+This is useful for adding examples to large datasets without having to load the entire dataset into memory.
+
+**Args:**
+
+
+ - `rows`: The rows to add to the dataset.
+**Returns:**
+ The updated dataset.
+
+---
+
+
+
+### classmethod `convert_to_table`
+
+```python
+convert_to_table(rows: Any) → Table | WeaveTable
+```
+
+---
+
+
+
+### classmethod `from_calls`
+
+```python
+from_calls(calls: Iterable[Call]) → Self
+```
+
+---
+
+
+
+### classmethod `from_hf`
+
+```python
+from_hf(
+ hf_dataset: Union[ForwardRef('HFDataset'), ForwardRef('HFDatasetDict')]
+) → Self
+```
+
+---
+
+
+
+### classmethod `from_obj`
+
+```python
+from_obj(obj: WeaveObject) → Self
+```
+
+---
+
+
+
+### classmethod `from_pandas`
+
+```python
+from_pandas(df: 'DataFrame') → Self
+```
+
+---
+
+
+
+### method `select`
+
+```python
+select(indices: Iterable[int]) → Self
+```
+
+Select rows from the dataset based on the provided indices.
+
+**Args:**
+
+
+ - `indices`: An iterable of integer indices specifying which rows to select.
+**Returns:**
+ A new Dataset object containing only the selected rows.
+
+---
+
+
+
+### method `to_hf`
+
+```python
+to_hf() → HFDataset
+```
+
+---
+
+
+
+### method `to_pandas`
+
+```python
+to_pandas() → DataFrame
+```
+
+---
+
+
+
+## class `EasyPrompt`
+
+
+
+### method `__init__`
+
+```python
+__init__(
+ content: str | dict | list | None = None,
+ role: str | None = None,
+ dedent: bool = False,
+ **kwargs: Any
+) → None
+```
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `data`: ``
+- `config`: ``
+- `requirements`: ``
+
+---
+
+#### property as_str
+
+Join all messages into a single string.
+
+---
+
+#### property is_bound
+
+---
+
+#### property messages
+
+#### property placeholders
+
+---
+
+#### property system_message
+
+Join all messages into a system prompt message.
+
+---
+
+#### property system_prompt
+
+Join all messages into a system prompt object.
+
+---
+
+#### property unbound_placeholders
+
+---
+
+
+
+### method `append`
+
+```python
+append(item: Any, role: str | None = None, dedent: bool = False) → None
+```
+
+---
+
+
+
+### method `as_dict`
+
+```python
+as_dict() → dict[str, Any]
+```
+
+---
+
+
+
+### method `as_pydantic_dict`
+
+```python
+as_pydantic_dict() → dict[str, Any]
+```
+
+---
+
+
+
+### method `bind`
+
+```python
+bind(*args: Any, **kwargs: Any) → Prompt
+```
+
+---
+
+
+
+### method `bind_rows`
+
+```python
+bind_rows(dataset: list[dict] | Any) → list['Prompt']
+```
+
+---
+
+
+
+### method `config_table`
+
+```python
+config_table(title: str | None = None) → Table
+```
+
+---
+
+
+
+### method `configure`
+
+```python
+configure(config: dict | None = None, **kwargs: Any) → Prompt
+```
+
+---
+
+
+
+### method `dump`
+
+```python
+dump(fp: ) → None
+```
+
+---
+
+
+
+### method `dump_file`
+
+```python
+dump_file(filepath: str | Path) → None
+```
+
+---
+
+
+
+### method `format`
+
+```python
+format(**kwargs: Any) → Any
+```
+
+---
+
+
+
+### classmethod `from_obj`
+
+```python
+from_obj(obj: WeaveObject) → Self
+```
+
+---
+
+
+
+### classmethod `load`
+
+```python
+load(fp: ) → Self
+```
+
+---
+
+
+
+### classmethod `load_file`
+
+```python
+load_file(filepath: str | Path) → Self
+```
+
+---
+
+
+
+### method `messages_table`
+
+```python
+messages_table(title: str | None = None) → Table
+```
+
+---
+
+
+
+### method `print`
+
+```python
+print() → str
+```
+
+---
+
+
+
+### method `publish`
+
+```python
+publish(name: str | None = None) → ObjectRef
+```
+
+---
+
+
+
+### method `require`
+
+```python
+require(param_name: str, **kwargs: Any) → Prompt
+```
+
+---
+
+
+
+### method `run`
+
+```python
+run() → Any
+```
+
+---
+
+
+
+### method `validate_requirement`
+
+```python
+validate_requirement(key: str, value: Any) → list
+```
+
+---
+
+
+
+### method `validate_requirements`
+
+```python
+validate_requirements(values: dict[str, Any]) → list
+```
+
+---
+
+
+
+### method `values_table`
+
+```python
+values_table(title: str | None = None) → Table
+```
+
+---
+
+
+
+## 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.
+
+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
+examples = [
+ {"question": "What is the capital of France?", "expected": "Paris"},
+ {"question": "Who wrote 'To Kill a Mockingbird'?", "expected": "Harper Lee"},
+ {"question": "What is the square root of 64?", "expected": "8"},
+]
+
+# Define any custom scoring function
+@weave.op
+def match_score1(expected: str, model_output: dict) -> dict:
+ # Here is where you'd define the logic to score the model output
+ return {'match': expected == model_output['generated_text']}
+
+@weave.op
+def function_to_evaluate(question: str):
+ # here's where you would add your LLM call and return the output
+ return {'generated_text': 'Paris'}
+
+# Score your examples using scoring functions
+evaluation = Evaluation(
+ dataset=examples, scorers=[match_score1]
+)
+
+# Start tracking the evaluation
+weave.init('intro-example')
+# Run the evaluation
+asyncio.run(evaluation.evaluate(function_to_evaluate))
+```
+
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `dataset`: ``
+- `scorers`: `list[typing.Annotated[trace.op_protocol.Op | flow.scorer.Scorer, BeforeValidator(func=, json_schema_input_type=PydanticUndefined)]] | None`
+- `preprocess_model_input`: `collections.abc.Callable[[dict], dict] | None`
+- `trials`: ``
+- `metadata`: `dict[str, typing.Any] | None`
+- `evaluation_name`: `str | collections.abc.Callable[trace.call.Call, str] | None`
+
+
+
+### method `evaluate`
+
+```python
+evaluate(model: Op | Model) → dict
+```
+
+---
+
+
+
+### classmethod `from_obj`
+
+```python
+from_obj(obj: WeaveObject) → Self
+```
+
+---
+
+
+
+### method `get_eval_results`
+
+```python
+get_eval_results(model: Op | Model) → EvaluationResults
+```
+
+---
+
+
+
+### method `get_evaluate_calls`
+
+```python
+get_evaluate_calls() → PaginatedIterator[CallSchema, WeaveObject]
+```
+
+Retrieve all evaluation calls that used this Evaluation object.
+
+Note that this returns a CallsIter instead of a single call because it's possible to have multiple evaluation calls for a single evaluation (e.g. if you run the same evaluation multiple times).
+
+**Returns:**
+
+ - `CallsIter`: An iterator over Call objects representing evaluation runs.
+
+**Raises:**
+
+ - `ValueError`: If the evaluation has no ref (hasn't been saved/run yet).
+
+**Examples:**
+```python
+evaluation = Evaluation(dataset=examples, scorers=[scorer])
+await evaluation.evaluate(model) # Run evaluation first
+calls = evaluation.get_evaluate_calls()
+for call in calls:
+ print(f"Evaluation run: {call.id} at {call.started_at}")
+```
+
+---
+
+
+
+### method `get_score_calls`
+
+```python
+get_score_calls() → dict[str, list[Call]]
+```
+
+Retrieve scorer calls for each evaluation run, grouped by trace ID.
+
+**Returns:**
+
+ - `dict[str, list[Call]]`: A dictionary mapping trace IDs to lists of scorer Call objects. Each trace ID represents one evaluation run, and the list contains all scorer calls executed during that run.
+
+**Examples:**
+```python
+evaluation = Evaluation(dataset=examples, scorers=[accuracy_scorer, f1_scorer])
+await evaluation.evaluate(model)
+score_calls = evaluation.get_score_calls()
+for trace_id, calls in score_calls.items():
+ print(f"Trace {trace_id}: {len(calls)} scorer calls")
+ for call in calls:
+ scorer_name = call.summary.get("weave", {}).get("trace_name")
+ print(f" Scorer: {scorer_name}, Output: {call.output}")
+```
+
+---
+
+
+
+### method `get_scores`
+
+```python
+get_scores() → dict[str, dict[str, list[Any]]]
+```
+
+Extract and organize scorer outputs from evaluation runs.
+
+**Returns:**
+
+ - `dict[str, dict[str, list[Any]]]`: A nested dictionary structure where:
+ - First level keys are trace IDs (evaluation runs)
+ - Second level keys are scorer names
+ - Values are lists of scorer outputs for that run and scorer
+
+**Examples:**
+```python
+evaluation = Evaluation(dataset=examples, scorers=[accuracy_scorer, f1_scorer])
+await evaluation.evaluate(model)
+scores = evaluation.get_scores()
+# Access scores by trace and scorer
+for trace_id, trace_scores in scores.items():
+ print(f"Evaluation run {trace_id}:")
+ for scorer_name, outputs in trace_scores.items():
+ print(f" {scorer_name}: {outputs}")
+```
+
+Expected output:
+
+```
+{
+ "trace_123": {
+ "accuracy_scorer": [{"accuracy": 0.85}],
+ "f1_scorer": [{"f1": 0.78}]
+ }
+}
+```
+
+---
+
+
+
+### method `model_post_init`
+
+```python
+model_post_init(_Evaluation__context: Any) → None
+```
+
+---
+
+
+
+### method `predict_and_score`
+
+```python
+predict_and_score(model: Op | Model, example: dict) → dict
+```
+
+---
+
+
+
+### method `summarize`
+
+```python
+summarize(eval_table: EvaluationResults) → dict
+```
+
+---
+
+
+
+## class `EvaluationLogger`
+This class provides an imperative interface for logging evaluations.
+
+An evaluation is started automatically when the first prediction is logged using the `log_prediction` method, and finished when the `log_summary` method is called.
+
+Each time you log a prediction, you will get back a `ScoreLogger` object. You can use this object to log scores and metadata for that specific prediction. For more information, see the `ScoreLogger` class.
+
+Basic usage - log predictions with inputs and outputs directly:
+
+```python
+ev = EvaluationLogger()
+
+# Log predictions with known inputs/outputs
+pred = ev.log_prediction(inputs={'q': 'Hello'}, outputs={'a': 'Hi there!'})
+pred.log_score("correctness", 0.9)
+
+# Finish the evaluation
+ev.log_summary({"avg_score": 0.9})
+```
+
+Advanced usage - use context manager for dynamic outputs and nested operations:
+
+```python
+ev = EvaluationLogger()
+
+# Use context manager when you need to capture nested operations
+with ev.log_prediction(inputs={'q': 'Hello'}) as pred:
+ # Any operations here (like LLM calls) automatically become
+ # children of the predict call
+ response = your_llm_call(...)
+ pred.output = response.content
+ pred.log_score("correctness", 0.9)
+
+# Finish the evaluation
+ev.log_summary({"avg_score": 0.9})
+```
+
+
+
+### method `__init__`
+
+```python
+__init__(
+ name: 'str | None' = None,
+ model: 'Model | dict | str | None' = None,
+ dataset: 'Dataset | list[dict] | str | None' = None,
+ eval_attributes: 'dict[str, Any] | None' = None,
+ scorers: 'list[str] | None' = None
+) → None
+```
+
+---
+
+#### property attributes
+
+---
+
+#### property ui_url
-### function `init`
+---
+
+
+
+### method `fail`
```python
-init(
- project_name: 'str',
- settings: 'UserSettings | dict[str, Any] | None' = None,
- autopatch_settings: 'AutopatchSettings | None' = None,
- global_postprocess_inputs: 'PostprocessInputsFunc | None' = None,
- global_postprocess_output: 'PostprocessOutputFunc | None' = None,
- global_attributes: 'dict[str, Any] | None' = None
-) → WeaveClient
+fail(exception: 'BaseException') → None
```
-Initialize weave tracking, logging to a wandb project.
+Convenience method to fail the evaluation with an exception.
-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:**
-
+### method `finish`
-NOTE: Global postprocessing settings are applied to all ops after each op's own postprocessing. The order is always: 1. Op-specific postprocessing 2. Global postprocessing
+```python
+finish(exception: 'BaseException | None' = None) → None
+```
- - `project_name`: The name of the Weights & Biases team and project to log to. If you don't specify a team, your default entity is used. To find or update your default entity, refer to [User Settings](https://docs.wandb.ai/guides/models/app/settings-page/user-settings/#default-team) in the W&B Models documentation.
- - `settings`: Configuration for the Weave client generally.
- - `autopatch_settings`: (Deprecated) Configuration for autopatch integrations. Use explicit patching instead.
- - `global_postprocess_inputs`: A function that will be applied to all inputs of all ops.
- - `global_postprocess_output`: A function that will be applied to all outputs of all ops.
- - `global_attributes`: A dictionary of attributes that will be applied to all traces.
-**Returns:**
- A Weave client.
+Clean up the evaluation resources explicitly without logging a summary.
+
+Ensures all prediction calls and the main evaluation call are finalized. This is automatically called if the logger is used as a context manager.
---
-
+
-### function `publish`
+### method `log_example`
```python
-publish(obj: 'Any', name: 'str | None' = None) → ObjectRef
+log_example(
+ inputs: 'dict[str, Any]',
+ output: 'Any',
+ scores: 'dict[str, ScoreType]'
+) → None
```
-Save and version a Python object.
+Log a complete example with inputs, output, and scores.
-Weave creates a new version of the object if the object's name already exists and its content hash does not match the latest version of that object.
+This is a convenience method that combines log_prediction and log_score for when you have all the data upfront.
**Args:**
- - `obj`: The object to save and version.
- - `name`: The name to save the object under.
-**Returns:**
- A Weave Ref to the saved object.
+ - `inputs`: The input data for the prediction
+ - `output`: The output value
+ - `scores`: Dictionary mapping scorer names to score values
+**Example:**
+```python
+ev = EvaluationLogger()
+ev.log_example(
+ inputs={'q': 'What is 2+2?'},
+ output='4',
+ scores={'correctness': 1.0, 'fluency': 0.9}
+)
+```
---
-
+
-### function `ref`
+### method `log_prediction`
```python
-ref(location: 'str') → ObjectRef
+log_prediction(inputs: 'dict[str, Any]', output: 'Any' = None) → ScoreLogger
```
-Creates a Ref to an existing Weave object. This does not directly retrieve the object but allows you to pass it to other Weave API functions.
+Log a prediction to the Evaluation.
+
+Returns a ScoreLogger that can be used directly or as a context manager.
**Args:**
- - `location`: A Weave Ref URI, or if `weave.init()` has been called, `name:version` or `name`. If no version is provided, `latest` is used.
+ - `inputs`: The input data for the prediction
+ - `output`: The output value. Defaults to None. Can be set later using pred.output.
**Returns:**
- A Weave Ref to the object.
+ ScoreLogger for logging scores and optionally finishing the prediction.
+
+Example (direct):
+ - `pred = ev.log_prediction({'q'`: '...'}, output="answer") pred.log_score("correctness", 0.9) pred.finish()
+
+Example (context manager):
+ - `with ev.log_prediction({'q'`: '...'}) as pred: response = model(...) pred.output = response pred.log_score("correctness", 0.9) # Automatically calls finish() on exit
---
-
+
-### function `get`
+### method `log_summary`
```python
-get(uri: 'str | ObjectRef') → Any
+log_summary(summary: 'dict | None' = None, auto_summarize: 'bool' = True) → None
```
-A convenience function for getting an object from a URI.
+Log a summary dict to the Evaluation.
-Many objects logged by Weave are automatically registered with the Weave server. This function allows you to retrieve those objects by their URI.
+This will calculate the summary, call the summarize op, and then finalize the evaluation, meaning no more predictions or scores can be logged.
+
+---
+
+
+
+### method `set_view`
+
+```python
+set_view(
+ name: 'str',
+ content: 'Content | str',
+ extension: 'str | None' = None,
+ mimetype: 'str | None' = None,
+ metadata: 'dict[str, Any] | None' = None,
+ encoding: 'str' = 'utf-8'
+) → None
+```
+
+Attach a view to the evaluation's main call summary under `weave.views`.
+
+Saves the provided content as an object in the project and writes its reference URI under `summary.weave.views.` for the evaluation's `evaluate` call. String inputs are wrapped as text content using `Content.from_text` with the provided extension or mimetype.
**Args:**
- - `uri`: A fully-qualified weave ref URI.
+ - `name`: The view name to display, used as the key under `summary.weave.views`.
+ - `content`: A `weave.Content` instance or string to serialize.
+ - `extension`: Optional file extension for string content inputs.
+ - `mimetype`: Optional MIME type for string content inputs.
+ - `metadata`: Optional metadata attached to newly created `Content`.
+ - `encoding`: Text encoding for string content inputs.
**Returns:**
- The object.
+ None
+
+**Examples:**
+ ``` import weave```
+ >>> ev = weave.EvaluationLogger()
+ >>> ev.set_view("report", "# Report", extension="md")
+
+---
+
+
+
+## class `File`
+A class representing a file with path, mimetype, and size information.
+
+
+
+### method `__init__`
-**Example:**
```python
-weave.init("weave_get_example")
-dataset = weave.Dataset(rows=[{"a": 1, "b": 2}])
-ref = weave.publish(dataset)
+__init__(path: 'str | Path', mimetype: 'str | None' = None)
+```
-dataset2 = weave.get(ref) # same as dataset!
+Initialize a File object.
+
+**Args:**
+
+
+---
+
+#### property filename
+
+Get the filename of the file.
+
+ - `path`: Path to the file (string or pathlib.Path)
+ - `mimetype`: Optional MIME type of the file - will be inferred from extension if not provided
+**Returns:**
+
+ - `str`: The name of the file without the directory path.
+
+---
+
+
+
+### method `open`
+
+```python
+open() → bool
```
+Open the file using the operating system's default application.
+
+This method uses the platform-specific mechanism to open the file with the default application associated with the file's type.
+
+**Returns:**
+
+ - `bool`: True if the file was successfully opened, False otherwise.
+
---
-
+
-### function `require_current_call`
+### method `save`
```python
-require_current_call() → Call
+save(dest: 'str | Path') → None
```
-Get the Call object for the currently executing Op, within that Op.
+Copy the file to the specified destination path.
-This allows you to access attributes of the Call such as its id or feedback while it is running.
+**Args:**
+
+
+---
+
+
+
+## class `Markdown`
+A Markdown renderable.
+
+ - `dest`: Destination path where the file will be copied to (string or pathlib.Path) The destination path can be a file or a directory.
+**Args:**
+
+ - `markup` (str): A string containing markdown.
+ - `code_theme` (str, optional): Pygments theme for code blocks. Defaults to "monokai". See https://pygments.org/styles/ for code themes.
+ - `justify` (JustifyMethod, optional): Justify value for paragraphs. Defaults to None.
+ - `style` (Union[str, Style], optional): Optional style to apply to markdown.
+ - `hyperlinks` (bool, optional): Enable hyperlinks. Defaults to ``True``.
+
+
+
+### method `__init__`
```python
-@weave.op
-def hello(name: str) -> None:
- print(f"Hello {name}!")
- current_call = weave.require_current_call()
- print(current_call.id)
+__init__(
+ markup: 'str',
+ code_theme: 'str' = 'monokai',
+ justify: 'JustifyMethod | None' = None,
+ style: 'str | Style' = 'none',
+ hyperlinks: 'bool' = True,
+ inline_code_lexer: 'str | None' = None,
+ inline_code_theme: 'str | None' = None
+) → None
```
-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 `get_call` method on the `WeaveClient` returned from `weave.init` to retrieve the Call object.
+
+
+## class `MessagesPrompt`
+
+
+
+### method `__init__`
```python
-client = weave.init("")
-mycall = client.get_call("")
+__init__(messages: list[dict])
```
-Alternately, after defining your Op you can use its `call` method. For example:
+ - `inline_code_lexer`: (str, optional): Lexer to use if inline code highlighting is enabled. Defaults to None.
+ - `inline_code_theme`: (Optional[str], optional): Pygments theme for inline code highlighting, or None for no highlighting. Defaults to None.
+**Pydantic Fields:**
+
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `messages`: `list[dict]`
+
+
+
+### method `format`
```python
-@weave.op
-def add(a: int, b: int) -> int:
- return a + b
+format(**kwargs: Any) → list
+```
-result, call = add.call(1, 2)
-print(call.id)
+---
+
+
+
+### method `format_message`
+
+```python
+format_message(message: dict, **kwargs: Any) → dict
```
-**Returns:**
- The Call object for the currently executing Op
+Format a single message by replacing template variables.
-**Raises:**
-
- - `NoCurrentCallError`: If tracking has not been initialized or this method is invoked outside an Op.
+This method delegates to the standalone format_message_with_template_vars function for the actual formatting logic.
---
-
+
-### function `get_current_call`
+### classmethod `from_obj`
```python
-get_current_call() → Call | None
+from_obj(obj: WeaveObject) → Self
```
-Get the Call object for the currently executing Op, within that Op.
+---
-**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.
+
+
+## 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
+
+**Examples:**
+```python
+class YourModel(Model):
+ attribute1: str
+ attribute2: int
-**Note:**
+ @weave.op
+ def predict(self, input_data: str) -> dict:
+ # Model logic goes here
+ prediction = self.attribute1 + ' ' + input_data
+ return {'pred': prediction}
+```
-> The returned Call's ``attributes`` dictionary becomes immutable once the call starts. Use :func:`weave.attributes` to set call metadata before invoking an Op. The ``summary`` field may be updated while the Op executes and will be merged with computed summary information when the call finishes.
+**Pydantic Fields:**
----
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
-
+
-### function `finish`
+### method `get_infer_method`
```python
-finish() → None
+get_infer_method() → Callable
```
-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.
-
---
-
+
-### function `op`
+## class `Monitor`
+Sets up a monitor to score incoming calls automatically.
+**Examples:**
```python
-op(
- func: 'Callable[P, R] | None' = None,
- name: 'str | None' = None,
- call_display_name: 'str | CallDisplayNameFunc | None' = None,
- postprocess_inputs: 'PostprocessInputsFunc | None' = None,
- postprocess_output: 'PostprocessOutputFunc | None' = None,
- tracing_sample_rate: 'float' = 1.0,
- enable_code_capture: 'bool' = True,
- accumulator: 'Callable[[Any | None, Any], Any] | None' = None
-) → Callable[[Callable[P, R]], Op[P, R]] | Op[P, R]
+import weave
+from weave.scorers import ValidJSONScorer
+
+json_scorer = ValidJSONScorer()
+
+my_monitor = weave.Monitor(
+ name="my-monitor",
+ description="This is a test monitor",
+ sampling_rate=0.5,
+ op_names=["my_op"],
+ query={
+ "$expr": {
+ "$gt": [
+ {
+ "$getField": "started_at"
+ },
+ {
+ "$literal": 1742540400
+ }
+ ]
+ }
+ }
+ },
+ scorers=[json_scorer],
+)
+
+my_monitor.activate()
```
-A decorator to weave op-ify a function or method. Works for both sync and async. Automatically detects iterator functions and applies appropriate behavior.
+**Pydantic Fields:**
----
+- `name`: `str | None`
+- `description`: `str | None`
+- `ref`: `trace.refs.ObjectRef | None`
+- `sampling_rate`: ``
+- `scorers`: `list[flow.scorer.Scorer]`
+- `op_names`: `list[str]`
+- `query`: `trace_server.interface.query.Query | None`
+- `active`: ``
-
+
-### function `attributes`
+### method `activate`
```python
-attributes(attributes: 'dict[str, Any]') → Iterator
+activate() → ObjectRef
```
-Context manager for setting attributes on a call.
+Activates the monitor.
-**Example:**
-```python
-with weave.attributes({'env': 'production'}):
- print(my_function.call("World"))
-```
+**Returns:**
+ The ref to the monitor.
---
-
+
-### function `thread`
+### method `deactivate`
```python
-thread(
- thread_id: 'str | None | object' =