> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-run-filter-ui-updates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# weave

> Weave の Python SDK リファレンス

export const SourceLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="source-link">
    ソース
  </a>;

<div id="api-overview">
  # API 概要
</div>

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/agent/agent.py#L17" />

## <kbd>クラス</kbd> `Agent`

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `model_name`: `<class 'str'>`
* `temperature`: `<class 'float'>`
* `system_message`: `<class 'str'>`
* `tools`: `list[typing.Any]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L23" />

### <kbd>method</kbd> `step`

```python theme={null}
step(state: AgentState) → AgentState
```

エージェントのstepを実行します。

**引数:**

* <b>`state`</b>: 環境の現在の状態。
* <b>`action`</b>: 実行するアクション。
  **戻り値:**
  環境の新しい状態。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/agent/agent.py#L12" />

## <kbd>クラス</kbd> `AgentState`

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `history`: `list[typing.Any]`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L12" />

## <kbd>クラス</kbd> `AnnotationSpec`

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `field_schema`: `dict[str, typing.Any]`
* `unique_among_creators`: `<class 'bool'>`
* `op_scope`: `list[str] | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L47" />

### <kbd>classmethod</kbd> `preprocess_field_schema`

```python theme={null}
preprocess_field_schema(data: dict[str, Any]) → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L92" />

### <kbd>classmethod</kbd> `validate_field_schema`

```python theme={null}
validate_field_schema(schema: dict[str, Any]) → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace_server/interface/builtin_object_classes/annotation_spec.py#L103" />

### <kbd>method</kbd> `value_is_valid`

```python theme={null}
value_is_valid(payload: Any) → bool
```

payload がこの annotation spec のスキーマに適合するかを検証します。

**引数:**

* <b>`payload`</b>: スキーマに対して検証するデータ
  **戻り値:**

* <b>`bool`</b>: 検証に成功した場合は True、それ以外の場合は False

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/Audio/audio.py#L81" />

## <kbd>クラス</kbd> `Audio`

サポート対象の形式 (wav または mp3) のオーディオデータを表すクラスです。

このクラスはオーディオデータを保持し、さまざまなソースからの読み込みやファイルへの書き出しを行うためのメソッドを提供します。

**Attributes:**

* <b>`format`</b>:  オーディオ形式 (現在サポートされているのは 'wav' または 'mp3')
* <b>`data`</b>:  bytes としての生のオーディオデータ

**引数:**

* <b>`data`</b>: オーディオデータ (bytes または base64 エンコードされた文字列)

* <b>`format`</b>: オーディオ形式 ('wav' または 'mp3')

* <b>`validate_base64`</b>: 入力データの base64 デコードを試行するかどうか
  **Raises:**

* <b>`ValueError`</b>:  オーディオデータが空の場合、または形式がサポートされていない場合

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/Audio/audio.py#L106" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(
    data: 'bytes',
    format: 'SUPPORTED_FORMATS_TYPE',
    validate_base64: 'bool' = True
) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/Audio/audio.py#L174" />

### <kbd>method</kbd> `export`

```python theme={null}
export(path: 'str | bytes | Path | PathLike') → None
```

オーディオデータをファイルにエクスポートします。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/Audio/audio.py#L121" />

### <kbd>classmethod</kbd> `from_data`

```python theme={null}
from_data(data: 'str | bytes', format: 'str') → Self
```

生データと指定した形式から Audio オブジェクトを作成します。

* <b>`path`</b>: オーディオファイルの書き込み先パス
  **引数:**

* <b>`data`</b>: bytes または base64 エンコードされた文字列形式のオーディオデータ

* <b>`format`</b>: オーディオ形式 (`'wav'` または `'mp3'`)
  **戻り値:**

* <b>`Audio`</b>: 新しい Audio インスタンス

**送出される例外:**

* <b>`ValueError`</b>: `format` で指定した形式がサポートされていない場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/Audio/audio.py#L146" />

### <kbd>classmethod</kbd> `from_path`

```python theme={null}
from_path(path: 'str | bytes | Path | PathLike') → Self
```

ファイルパスから Audio オブジェクトを作成します。

**引数:**

* <b>`path`</b>: オーディオファイルへのパス (拡張子は `.wav` または `.mp3` である必要があります)
  **戻り値:**

* <b>`Audio`</b>: ファイルから読み込まれた新しい Audio インスタンス

**発生する例外:**

* <b>`ValueError`</b>: ファイルが存在しない場合、またはサポートされていない拡張子の場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L42" />

## <kbd>クラス</kbd> `Content`

さまざまなソースのコンテンツを表すクラスです。関連するメタデータとともに、バイト列ベースの統一表現に変換します。

このクラスは、以下のいずれかの classmethod を使用してインスタンス化する必要があります。

* from\_path()
* from\_bytes()
* from\_text()
* from\_url()
* from\_base64()
* from\_data\_url()

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L87" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

直接初期化することはできません。インスタンスを作成するには、`Content.from_path()` のようなクラスメソッドを使用してください。

**Pydantic のフィールド:**

* `data`: `<class 'bytes'>`
* `size`: `<class 'int'>`
* `mimetype`: `<class 'str'>`
* `digest`: `<class 'str'>`
* `filename`: `<class 'str'>`
* `content_type`: `typing.Literal['bytes', 'text', 'base64', 'file', 'url', 'data_url', 'data_url:base64', 'data_url:encoding', 'data_url:encoding:base64']`
* `input_type`: `<class 'str'>`
* `encoding`: `<class 'str'>`
* `metadata`: `dict[str, typing.Any] | None`
* `extension`: `str | None`

***

#### <kbd>プロパティ</kbd> art

#### <kbd>プロパティ</kbd> ref

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L543" />

### <kbd>method</kbd> `as_string`

```python theme={null}
as_string() → str
```

データを文字列として表示します。バイト列は `encoding` 属性を使用してデコードされます。base64 の場合、データはいったん base64 のバイト列として再エンコードされ、その後 ASCII 文字列にデコードされます。

**戻り値:**
str.

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L258" />

### <kbd>classmethod</kbd> `from_base64`

```python theme={null}
from_base64(
    b64_data: 'str | bytes',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

base64 でエンコードされた文字列またはバイト列から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L168" />

### <kbd>classmethod</kbd> `from_bytes`

```python theme={null}
from_bytes(
    data: 'bytes',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → Self
```

生のバイト列からContentを初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L357" />

### <kbd>classmethod</kbd> `from_data_url`

```python theme={null}
from_data_url(url: 'str', metadata: 'dict[str, Any] | None' = None) → Self
```

データ URL から Content を初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L309" />

### <kbd>classmethod</kbd> `from_path`

```python theme={null}
from_path(
    path: 'str | Path',
    encoding: 'str' = 'utf-8',
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

ローカルファイルのパスからContentを初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L209" />

### <kbd>classmethod</kbd> `from_text`

```python theme={null}
from_text(
    text: 'str',
    extension: 'str | None' = None,
    mimetype: 'str | None' = None,
    metadata: 'dict[str, Any] | None' = None,
    encoding: 'str' = 'utf-8'
) → Self
```

文字列からContentを初期化します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L399" />

### <kbd>classmethod</kbd> `from_url`

```python theme={null}
from_url(
    url: 'str',
    headers: 'dict[str, Any] | None' = None,
    timeout: 'int | None' = 30,
    metadata: 'dict[str, Any] | None' = None
) → Self
```

HTTP(S) URL からバイト列を取得して Content を初期化します。

コンテンツをダウンロードし、ヘッダー、URL パス、データに基づいて MIME タイプと拡張子を推定したうえで、取得したバイト列から Content オブジェクトを構築します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L97" />

### <kbd>classmethod</kbd> `model_validate`

```python theme={null}
model_validate(
    obj: 'Any',
    strict: 'bool | None' = None,
    from_attributes: 'bool | None' = None,
    context: 'dict[str, Any] | None' = None,
    extra: 'str | None' = None,
    by_alias: 'bool | None' = None,
    by_name: 'bool | None' = None
) → Self
```

dict からの Content の再構成を処理できるように、model\_validate をオーバーライドします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L148" />

### <kbd>classmethod</kbd> `model_validate_json`

```python theme={null}
model_validate_json(
    json_data: 'str | bytes | bytearray',
    strict: 'bool | None' = None,
    context: 'dict[str, Any] | None' = None,
    extra: 'str | None' = None,
    by_alias: 'bool | None' = None,
    by_name: 'bool | None' = None
) → Self
```

JSON から Content を再構成できるように、model\_validate\_json をオーバーライドします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L553" />

### <kbd>method</kbd> `open`

```python theme={null}
open() → bool
```

オペレーティングシステムの既定のアプリケーションを使用して、ファイルを開きます。

この method は、ファイルタイプに関連付けられた既定のアプリケーションでファイルを開くために、プラットフォーム固有の仕組みを使用します。

**戻り値:**

* <b>`bool`</b>: ファイルを正常に開けた場合は True、それ以外の場合は False。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L583" />

### <kbd>method</kbd> `save`

```python theme={null}
save(dest: 'str | Path') → None
```

ファイルを指定した保存先パスにコピーします。最後に保存したコピーを反映するように、コンテンツのファイル名とパスを更新します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L535" />

### <kbd>method</kbd> `serialize_data`

```python theme={null}
serialize_data(data: 'bytes') → str
```

モデルをJSONモードでダンプする場合

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_wrappers/Content/content.py#L510" />

### <kbd>method</kbd> `to_data_url`

```python theme={null}
to_data_url(use_base64: 'bool' = True) → str
```

コンテンツからデータ URL を生成します。

* <b>`dest`</b>: ファイルのコピー先となるパス (string または pathlib.Path) 。コピー先のパスには、ファイルまたはディレクトリを指定できます。`dest` にファイル拡張子 (例: `.txt`) がない場合、コピー先はディレクトリとして扱われます。
  **引数:**

* <b>`use_base64`</b>: True の場合、データは base64 エンコードされます。それ以外の場合はパーセントエンコードされます。デフォルトは True です。
  **戻り値:**
  データ URL 文字列。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L26" />

## <kbd>クラス</kbd> `Dataset`

簡単に保存でき、自動的にバージョン管理される`Dataset`オブジェクトです。

**例:**

```python theme={null}
# データセットを作成する
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."}
])

# データセットを公開する
weave.publish(dataset)

# データセットを取得する
dataset_ref = weave.ref('grammar').get()

# 特定のサンプルにアクセスする
example_label = dataset_ref.rows[2]['sentence']
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `rows`: `trace.table.Table | trace.vals.WeaveTable`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L129" />

### <kbd>method</kbd> `add_rows`

```python theme={null}
add_rows(rows: Iterable[dict]) → Dataset
```

既存のデータセットに行を追記して、新しいバージョンのデータセットを作成します。

これは、データセット全体をメモリに読み込まずに、大規模なデータセットへサンプルを追加する場合に便利です。

**引数:**

* <b>`rows`</b>: データセットに追加する行。
  **戻り値:**
  更新後のデータセット。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L173" />

### <kbd>classmethod</kbd> `convert_to_table`

```python theme={null}
convert_to_table(rows: Any) → Table | WeaveTable
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L61" />

### <kbd>classmethod</kbd> `from_calls`

```python theme={null}
from_calls(calls: Iterable[Call]) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L71" />

### <kbd>classmethod</kbd> `from_hf`

```python theme={null}
from_hf(
    hf_dataset: Union[ForwardRef('HFDataset'), ForwardRef('HFDatasetDict')]
) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L52" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L66" />

### <kbd>classmethod</kbd> `from_pandas`

```python theme={null}
from_pandas(df: 'DataFrame') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L220" />

### <kbd>method</kbd> `select`

```python theme={null}
select(indices: Iterable[int]) → Self
```

指定したインデックスに基づいて、データセットから行を選択します。

**引数:**

* <b>`indices`</b>: 選択する行を指定する整数インデックスのイテラブル。
  **戻り値:**
  選択した行のみを含む新しい Dataset オブジェクト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L115" />

### <kbd>method</kbd> `to_hf`

```python theme={null}
to_hf() → HFDataset
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/dataset/dataset.py#L107" />

### <kbd>method</kbd> `to_pandas`

```python theme={null}
to_pandas() → DataFrame
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L192" />

## <kbd>クラス</kbd> `EasyPrompt`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L200" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(
    content: str | dict | list | None = None,
    role: str | None = None,
    dedent: bool = False,
    **kwargs: Any
) → None
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `data`: `<class 'list'>`
* `config`: `<class 'dict'>`
* `requirements`: `<class 'dict'>`

***

#### <kbd>プロパティ</kbd> as\_str

すべてのメッセージを結合して1つの文字列にします。

***

#### <kbd>プロパティ</kbd> is\_bound

***

#### <kbd>プロパティ</kbd> messages

#### <kbd>プロパティ</kbd> プレースホルダー

***

#### <kbd>プロパティ</kbd> system\_message

すべてのメッセージを結合して、1つのsystem promptメッセージにします。

***

#### <kbd>プロパティ</kbd> system\_prompt

すべてのメッセージを結合して、system prompt オブジェクトにします。

***

#### <kbd>プロパティ</kbd> unbound\_placeholders

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L230" />

### <kbd>method</kbd> `append`

```python theme={null}
append(item: Any, role: str | None = None, dedent: bool = False) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L489" />

### <kbd>method</kbd> `as_dict`

```python theme={null}
as_dict() → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L486" />

### <kbd>method</kbd> `as_pydantic_dict`

```python theme={null}
as_pydantic_dict() → dict[str, Any]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L321" />

### <kbd>method</kbd> `bind`

```python theme={null}
bind(*args: Any, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L341" />

### <kbd>method</kbd> `bind_rows`

```python theme={null}
bind_rows(dataset: list[dict] | Any) → list['Prompt']
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L447" />

### <kbd>method</kbd> `config_table`

```python theme={null}
config_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L411" />

### <kbd>method</kbd> `configure`

```python theme={null}
configure(config: dict | None = None, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L527" />

### <kbd>method</kbd> `dump`

```python theme={null}
dump(fp: <class 'IO'>) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L530" />

### <kbd>method</kbd> `dump_file`

```python theme={null}
dump_file(filepath: str | Path) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L84" />

### <kbd>method</kbd> `format`

```python theme={null}
format(**kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L496" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L511" />

### <kbd>classmethod</kbd> `load`

```python theme={null}
load(fp: <class 'IO'>) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L521" />

### <kbd>classmethod</kbd> `load_file`

```python theme={null}
load_file(filepath: str | Path) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L427" />

### <kbd>method</kbd> `messages_table`

```python theme={null}
messages_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L455" />

### <kbd>method</kbd> `print`

```python theme={null}
print() → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L417" />

### <kbd>method</kbd> `publish`

```python theme={null}
publish(
    name: str | None = None,
    tags: list[str] | None = None,
    aliases: list[str] | None = None
) → ObjectRef
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L407" />

### <kbd>method</kbd> `require`

```python theme={null}
require(param_name: str, **kwargs: Any) → Prompt
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L540" />

### <kbd>method</kbd> `run`

```python theme={null}
run() → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L298" />

### <kbd>method</kbd> `validate_requirement`

```python theme={null}
validate_requirement(key: str, value: Any) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L315" />

### <kbd>method</kbd> `validate_requirements`

```python theme={null}
validate_requirements(values: dict[str, Any]) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L439" />

### <kbd>method</kbd> `values_table`

```python theme={null}
values_table(title: str | None = None) → Table
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L61" />

## <kbd>class</kbd> `評価`

scorer のセットとデータセットを含む評価を設定します。

`evaluation.evaluate(model)` を呼び出すと、データセットの各行がモデルに渡されます。このとき、データセットの列名は `model.predict` の引数名に対応付けられます。

その後、すべての scorer が呼び出され、結果は Weave に保存されます。

データセットの行を前処理したい場合は、`preprocess_model_input` に関数を渡せます。

**例:**

```python theme={null}
# サンプルを収集する
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"},
]

# カスタムスコアリング関数を定義する
@weave.op
def match_score1(expected: str, model_output: dict) -> dict:
     # ここにモデル出力をスコアリングするロジックを定義する
     return {'match': expected == model_output['generated_text']}

@weave.op
def function_to_evaluate(question: str):
     # ここに LLM の呼び出しを追加して出力を返す
     return  {'generated_text': 'Paris'}

# スコアリング関数を使ってサンプルをスコアリングする
evaluation = Evaluation(
     dataset=examples, scorers=[match_score1]
)

# 評価のトラッキングを開始する
weave.init('intro-example')
# 評価を実行する
asyncio.run(evaluation.evaluate(function_to_evaluate))
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `dataset`: `<class 'dataset.dataset.Dataset'>`
* `scorers`: `list[typing.Annotated[trace.op_protocol.Op | flow.scorer.Scorer, BeforeValidator(func=<function cast_to_scorer at 0x7f97165532e0>, json_schema_input_type=PydanticUndefined)]] | None`
* `preprocess_model_input`: `collections.abc.Callable[[dict], dict] | None`
* `trials`: `<class 'int'>`
* `metadata`: `dict[str, typing.Any] | None`
* `evaluation_name`: `str | collections.abc.Callable[trace.call.Call, str] | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L295" />

### <kbd>method</kbd> `evaluate`

```python theme={null}
evaluate(model: Op | Model) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L119" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L243" />

### <kbd>method</kbd> `get_eval_results`

```python theme={null}
get_eval_results(model: Op | Model) → EvaluationResults
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L306" />

### <kbd>method</kbd> `get_evaluate_calls`

```python theme={null}
get_evaluate_calls() → PaginatedIterator[CallSchema, WeaveObject]
```

この `評価` オブジェクトを使用したすべての評価 call を取得します。

これは単一の call ではなく CallsIter を返すことに注意してください。1 つの評価に対して複数の評価 call が存在する可能性があるためです (たとえば、同じ評価を複数回実行した場合) 。

**戻り値:**

* <b>`CallsIter`</b>: 評価 run を表す `Call` オブジェクトのイテレータ。

**送出:**

* <b>`ValueError`</b>: 評価に ref がない場合 (まだ保存または実行されていない場合) 。

**例:**

```python theme={null}
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}")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L342" />

### <kbd>method</kbd> `get_score_calls`

```python theme={null}
get_score_calls() → dict[str, list[Call]]
```

各評価 run の Scorer call を、trace ID ごとにグループ化して取得します。

**戻り値:**

* <b>`dict[str, list[Call]]`</b>: trace ID から Scorer の Call オブジェクトのリストへのマッピングを格納した辞書。各 trace ID は 1 つの評価 run を表し、リストにはその run 中に実行されたすべての Scorer call が含まれます。

**例:**

```python theme={null}
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}")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval.py#L381" />

### <kbd>method</kbd> `get_scores`

```python theme={null}
get_scores() → dict[str, dict[str, list[Any]]]
```

評価 run から Scorer の出力を抽出し、整理します。

**戻り値:**

* <b>`dict[str, dict[str, list[Any]]]`</b>: 次のようなネストされた辞書構造です。
  * 第1レベルのキーは trace ID (評価 run)
  * 第2レベルのキーは Scorer 名
  * 値は、その run と Scorer に対応する Scorer の出力のリスト

**例:**

```python theme={null}
evaluation = Evaluation(dataset=examples, scorers=[accuracy_scorer, f1_scorer])
await evaluation.evaluate(model)
scores = evaluation.get_scores()
# trace と 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}")
```

想定される出力:

```
{
     "trace_123": {
     "accuracy_scorer": [{"accuracy": 0.85}],
     "f1_scorer": [{"f1": 0.78}]
     }
}
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/pydantic/_internal/_model_construction.py#L163" />

### <kbd>method</kbd> `model_post_init`

```python theme={null}
model_post_init(_Evaluation__context: Any) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L180" />

### <kbd>method</kbd> `predict_and_score`

```python theme={null}
predict_and_score(model: Op | Model, example: dict) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L220" />

### <kbd>method</kbd> `summarize`

```python theme={null}
summarize(eval_table: EvaluationResults) → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L604" />

## <kbd>class</kbd> `EvaluationLogger`

このクラスは、評価をログするための命令型インターフェースを提供します。

最初の予測を `log_prediction` method でログすると、自動的に評価が開始され、`log_summary` method が呼び出されると終了します。

予測をログするたびに、`ScoreLogger` オブジェクトが返されます。このオブジェクトを使用して、その予測に対応するスコアとメタデータをログできます。詳細は、`ScoreLogger` クラスを参照してください。

基本的な使用方法 - 入力と出力を直接指定して予測をログします:

```python theme={null}
ev = EvaluationLogger()

# 既知の入力/出力で予測をログする
pred = ev.log_prediction(inputs={'q': 'Hello'}, outputs={'a': 'Hi there!'})
pred.log_score("correctness", 0.9)

# 評価を終了する
ev.log_summary({"avg_score": 0.9})
```

高度な使い方 - 動的な出力とネストされたオペレーションにはコンテキストマネージャーを使用します:

```python theme={null}
ev = EvaluationLogger()

# ネストされたオペレーションを取得する必要がある場合はコンテキストマネージャーを使用します
with ev.log_prediction(inputs={'q': 'Hello'}) as pred:
     # ここでのオペレーション（LLM calls など）は自動的に
     # predict call の子になります
     response = your_llm_call(...)
     pred.output = response.content
     pred.log_score("correctness", 0.9)

# 評価を終了します
ev.log_summary({"avg_score": 0.9})
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L646" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__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
```

***

#### <kbd>プロパティ</kbd> 属性

***

#### <kbd>プロパティ</kbd> ui\_url

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L1024" />

### <kbd>method</kbd> `fail`

```python theme={null}
fail(exception: 'BaseException') → None
```

評価を例外で失敗させるための便利な method。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L1008" />

### <kbd>method</kbd> `finish`

```python theme={null}
finish(exception: 'BaseException | None' = None) → None
```

サマリーをログせず、評価リソースを明示的にクリーンアップします。

すべての予測 call とメインの評価 call を確実に終了します。ロガーをコンテキストマネージャーとして使用している場合は、自動的に呼び出されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L868" />

### <kbd>method</kbd> `log_example`

```python theme={null}
log_example(
    inputs: 'dict[str, Any]',
    output: 'Any',
    scores: 'dict[str, ScoreType]'
) → None
```

入力、出力、スコア を含む完全な例をログします。

これは、必要なデータがすべて事前にそろっている場合に、log\_prediction と log\_score をまとめて実行できる便利な method です。

**引数:**

* <b>`inputs`</b>: 予測の入力データ
* <b>`output`</b>: 出力値
* <b>`scores`</b>: Scorer 名を score 値に対応付ける辞書
  **例:**

```python theme={null}
ev = EvaluationLogger()
ev.log_example(
    inputs={'q': 'What is 2+2?'},
    output='4',
    scores={'correctness': 1.0, 'fluency': 0.9}
)
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L796" />

### <kbd>method</kbd> `log_prediction`

```python theme={null}
log_prediction(inputs: 'dict[str, Any]', output: 'Any' = None) → ScoreLogger
```

予測を評価にログします。

直接使用することも、コンテキストマネージャーとして使用することもできる ScoreLogger を返します。

**引数:**

* <b>`inputs`</b>: 予測の入力データ
* <b>`output`</b>: 出力値。デフォルトは None です。後で `pred.output` を使用して設定できます。
  **戻り値:**
  スコアのログ記録や、必要に応じて予測の終了に使用できる ScoreLogger。

例 (直接使用する場合) :

* <b>`pred = ev.log_prediction({'q'`</b>:  '...'}, output="answer") pred.log\_score("correctness", 0.9) pred.finish()

例 (コンテキストマネージャーを使用する場合) :

* <b>`with ev.log_prediction({'q'`</b>:  '...'}) as pred:  response = model(...)  pred.output = response  pred.log\_score("correctness", 0.9) # 終了時に自動的に finish() が呼び出されます

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L907" />

### <kbd>method</kbd> `log_summary`

```python theme={null}
log_summary(summary: 'dict | None' = None, auto_summarize: 'bool' = True) → None
```

Evaluation に summary dict をログします。

これにより summary が計算され、summarize op が呼び出された後、評価が確定されます。つまり、以降は予測やスコアをログできなくなります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/evaluation/eval_imperative.py#L956" />

### <kbd>method</kbd> `set_view`

```python theme={null}
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
```

`weave.views` の下で、評価のメイン call の summary に view を追加します。

指定されたコンテンツをプロジェクト内のオブジェクトとして保存し、その参照 URI を、評価の `evaluate` call の `summary.weave.views.<name>` に書き込みます。文字列入力は、指定された拡張子または MIME タイプを使って、`Content.from_text` によりテキストコンテンツとしてラップされます。

**引数:**

* <b>`name`</b>: 表示する view の名前。`summary.weave.views` 配下のキーとして使用されます。
* <b>`content`</b>: シリアライズする `weave.Content` インスタンス、または文字列。
* <b>`extension`</b>: 文字列コンテンツ入力に使用する省略可能なファイル拡張子。
* <b>`mimetype`</b>: 文字列コンテンツ入力に使用する省略可能な MIME タイプ。
* <b>`metadata`</b>: 新しく作成される `Content` に付加する省略可能なメタデータ。
* <b>`encoding`</b>: 文字列コンテンツ入力のテキストエンコーディング。
  **戻り値:**
  None

**例:**
` import weave`

> > > ev = weave.EvaluationLogger()
> > > ev.set\_view("report", "# Report", extension="md")

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/File/file.py#L30" />

## <kbd>class</kbd> `File`

パス、MIMEタイプ、サイズ情報を持つファイルを表すクラス。

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/File/file.py#L34" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(path: 'str | Path', mimetype: 'str | None' = None)
```

Fileオブジェクトを初期化します。

**引数:**

***

#### <kbd>プロパティ</kbd> filename

ファイル名を取得します。

* <b>`path`</b>: ファイルのパス (string または pathlib.Path)

* <b>`mimetype`</b>: 省略可能なファイルの MIME タイプ。指定しない場合は拡張子から推定されます
  **戻り値:**

* <b>`str`</b>:  ディレクトリパスを含まないファイル名。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/File/file.py#L60" />

### <kbd>method</kbd> `open`

```python theme={null}
open() → bool
```

オペレーティングシステムの既定のアプリケーションを使用してファイルを開きます。

この method では、ファイルのタイプに関連付けられた既定のアプリケーションでファイルを開くために、プラットフォーム固有の仕組みを使用します。

**戻り値:**

* <b>`bool`</b>: ファイルを正常に開けた場合は True、それ以外の場合は False。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/type_handlers/File/file.py#L81" />

### <kbd>method</kbd> `save`

```python theme={null}
save(dest: 'str | Path') → None
```

ファイルを指定したコピー先のパスにコピーします。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/rich/markdown.py#L512" />

## <kbd>class</kbd> `Markdown`

Markdown を表示可能なオブジェクト。

* <b>`dest`</b>: ファイルのコピー先パス (string または pathlib.Path) 。コピー先パスにはファイルまたはディレクトリを指定できます。 **引数:**

* <b>`markup`</b> (str): Markdown を含む文字列。

* <b>`code_theme`</b> (str, optional): コードブロック用の Pygments テーマ。デフォルトは "monokai" です。コードテーマについては [https://pygments.org/styles/](https://pygments.org/styles/) を参照してください。

* <b>`justify`</b> (JustifyMethod, optional): 段落の justify 値。デフォルトは None です。

* <b>`style`</b> (Union\[str, Style], optional): Markdown に適用する任意のスタイル。

* <b>`hyperlinks`</b> (bool, optional): ハイパーリンクを有効にします。デフォルトは `True` です。

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/rich/markdown.py#L548" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__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
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L164" />

## <kbd>class</kbd> `MessagesPrompt`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L168" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(messages: list[dict])
```

* <b>`inline_code_lexer`</b>: (str, optional): インラインコードのハイライトが有効な場合に使用するレキサー。デフォルトは None です。

* <b>`inline_code_theme`</b>: (Optional\[str], optional): インラインコードのハイライトに使用する Pygments テーマ。ハイライトを無効にする場合は None。デフォルトは None です。
  **Pydantic のフィールド:**

* `name`: `str | None`

* `description`: `str | None`

* `ref`: `trace.refs.ObjectRef | None`

* `messages`: `list[dict]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L180" />

### <kbd>method</kbd> `format`

```python theme={null}
format(**kwargs: Any) → list
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L172" />

### <kbd>method</kbd> `format_message`

```python theme={null}
format_message(message: dict, **kwargs: Any) → dict
```

テンプレート変数を置き換えて、1つのメッセージを整形します。

この method は、実際の整形処理を行うスタンドアロンの format\_message\_with\_template\_vars function に委譲します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L183" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/model.py#L25" />

## <kbd>class</kbd> `Model`

入力に対して処理を行うコードとデータの組み合わせを表すことを目的としています。たとえば、プロンプトを使って LLM を呼び出し、予測を行ったりテキストを生成したりできます。

モデルを定義する属性やコードを変更すると、その変更はログされ、バージョンが更新されます。これにより、モデルの異なるバージョン間で予測を比較できます。これを使用して、プロンプトを改善したり、最新の LLM を試したり、異なる設定間で予測を比較したりできます。

**例:**

```python theme={null}
class YourModel(Model):
     attribute1: str
     attribute2: int

     @weave.op
     def predict(self, input_data: str) -> dict:
         # モデルのロジックをここに記述
         prediction = self.attribute1 + ' ' + input_data
         return {'pred': prediction}
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/model.py#L51" />

### <kbd>method</kbd> `get_infer_method`

```python theme={null}
get_infer_method() → Callable
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/monitor.py#L39" />

## <kbd>class</kbd> `Monitor`

受信したcallを自動的にスコアリングするモニターを設定します。

**例:**

```python theme={null}
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()
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `sampling_rate`: `<class 'float'>`
* `scorers`: `list[flow.scorer.Scorer]`
* `op_names`: `list[str]`
* `query`: `trace_server.interface.query.Query | None`
* `is_traced`: `<class 'bool'>`
* `active`: `<class 'bool'>`
* `scorer_debounce_config`: `flow.monitor.ScorerDebounceConfig | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/monitor.py#L88" />

### <kbd>method</kbd> `activate`

```python theme={null}
activate() → ObjectRef
```

モニターを有効にします。

**戻り値:**
モニターへの参照。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/monitor.py#L98" />

### <kbd>method</kbd> `deactivate`

```python theme={null}
deactivate() → ObjectRef
```

モニターを停止します。

**戻り値:**
モニターへの参照。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/monitor.py#L108" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/object/obj.py#L21" />

## <kbd>class</kbd> `Object`

トラッキングとバージョン管理が可能な Weave オブジェクトの基底クラスです。

このクラスは Pydantic の BaseModel を拡張し、オブジェクトのトラッキング、参照、シリアライズのための Weave 固有の機能を提供します。オブジェクトには名、説明、参照を設定でき、Weave システムで保存および取得できます。

**属性:**

* <b>`name`</b> (Optional\[str]):  オブジェクトの人間が読み取れる名前。
* <b>`description`</b> (Optional\[str]):  オブジェクトが表す内容の説明。
* <b>`ref`</b> (Optional\[ObjectRef]):  Weave システム内のオブジェクトへの参照。

**例:**

```python theme={null}
# シンプルなオブジェクトを作成する
obj = Object(name="my_object", description="A test object")

# URIからオブジェクトを作成する
obj = Object.from_uri("weave:///entity/project/object:digest")
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/object/obj.py#L60" />

### <kbd>classmethod</kbd> `from_uri`

```python theme={null}
from_uri(uri: str, objectify: bool = True) → Self
```

Weave URI からオブジェクトのインスタンスを作成します。

**引数:**

* <b>`uri`</b> (str):  オブジェクトを指す Weave URI。
* <b>`objectify`</b> (bool):  結果をオブジェクト化するかどうか。デフォルトは True です。

**戻り値:**

* <b>`Self`</b>:  URI から生成されたこのクラスのインスタンス。

**送出される例外:**

* <b>`NotImplementedError`</b>:  クラスがデシリアライズに必要なメソッドを実装していない場合。

**例:**

```python theme={null}
obj = MyObject.from_uri("weave:///entity/project/object:digest")
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/object/obj.py#L86" />

### <kbd>classmethod</kbd> `handle_relocatable_object`

```python theme={null}
handle_relocatable_object(
    v: Any,
    handler: ValidatorFunctionWrapHandler,
    info: ValidationInfo
) → Any
```

ObjectRef や WeaveObject を含む再配置可能なオブジェクトの検証を処理します。

このバリデーターは、入力が ObjectRef または WeaveObject で、標準の Object インスタンスに適切に変換する必要がある特別なケースを処理します。検証プロセス中に参照が保持され、無視対象のタイプが正しく処理されるようにします。

**引数:**

* <b>`v`</b> (Any):  検証する値。
* <b>`handler`</b> (ValidatorFunctionWrapHandler):  標準の pydantic 検証ハンドラー。
* <b>`info`</b> (ValidationInfo):  検証コンテキスト情報。

**戻り値:**

* <b>`Any`</b>:  検証済みのオブジェクトインスタンス。

**例:**
この method は、オブジェクトの作成時および検証時に自動的に呼び出されます。次のようなケースを処理します: \`\`\`python

<div id="when-an-objectref-is-passed">
  # ObjectRef を渡した場合
</div>

obj = MyObject(some\_object\_ref)

<div id="when-a-weaveobject-is-passed">
  # WeaveObject を渡した場合
</div>

obj = MyObject(some\_weave\_object)

````

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L162" />

## <kbd>class</kbd> `ObjectRef`
ObjectRef(entity: 'str', project: 'str', name: 'str', _digest: 'str | Future[str]', _extra: 'tuple[str | Future[str], ...]' = ()) 

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/../../../../weave/trace/refs/__init__" />

### <kbd>method</kbd> `__init__`

```python
__init__(
    entity: 'str',
    project: 'str',
    name: 'str',
    _digest: 'str | Future[str]',
    _extra: 'tuple[str | Future[str], ]' = ()
) → None
````

***

#### <kbd>プロパティ</kbd> ダイジェスト

***

#### <kbd>プロパティ</kbd> extra

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L170" />

### <kbd>method</kbd> `as_param_dict`

```python theme={null}
as_param_dict() → dict
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L262" />

### <kbd>method</kbd> `delete`

```python theme={null}
delete() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L218" />

### <kbd>method</kbd> `get`

```python theme={null}
get(objectify: 'bool' = True) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L246" />

### <kbd>method</kbd> `is_descended_from`

```python theme={null}
is_descended_from(potential_ancestor: 'ObjectRef') → bool
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L72" />

### <kbd>method</kbd> `maybe_parse_uri`

```python theme={null}
maybe_parse_uri(s: 'str') → AnyRef | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L269" />

### <kbd>method</kbd> `parse_uri`

```python theme={null}
parse_uri(uri: 'str') → ObjectRef
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L152" />

### <kbd>method</kbd> `with_attr`

```python theme={null}
with_attr(attr: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L144" />

### <kbd>method</kbd> `with_extra`

```python theme={null}
with_extra(extra: 'tuple[str | Future[str], ]') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L155" />

### <kbd>method</kbd> `with_index`

```python theme={null}
with_index(index: 'int') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L158" />

### <kbd>method</kbd> `with_item`

```python theme={null}
with_item(item_digest: 'str | Future[str]') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/refs.py#L149" />

### <kbd>method</kbd> `with_key`

```python theme={null}
with_key(key: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L83" />

## <kbd>class</kbd> `Prompt`

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L84" />

### <kbd>method</kbd> `format`

```python theme={null}
format(**kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L496" />

## <kbd>class</kbd> `SavedView`

SavedView オブジェクトを扱うための、fluent スタイルのクラスです。

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L502" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(view_type: 'str' = 'traces', label: 'str' = 'SavedView') → None
```

***

#### <kbd>プロパティ</kbd> entity

***

#### <kbd>プロパティ</kbd> label

***

#### <kbd>プロパティ</kbd> project

***

#### <kbd>プロパティ</kbd> view\_type

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L626" />

### <kbd>method</kbd> `add_column`

```python theme={null}
add_column(path: 'str | ObjectPath', label: 'str | None' = None) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L635" />

### <kbd>method</kbd> `add_columns`

```python theme={null}
add_columns(*columns: 'str') → SavedView
```

グリッドに複数の列を簡単に追加できる便利な method です。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L527" />

### <kbd>method</kbd> `add_filter`

```python theme={null}
add_filter(
    field: 'str',
    operator: 'str',
    value: 'Any | None' = None
) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L601" />

### <kbd>method</kbd> `add_sort`

```python theme={null}
add_sort(field: 'str', direction: 'SortDirection') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L666" />

### <kbd>method</kbd> `column_index`

```python theme={null}
column_index(path: 'int | str | ObjectPath') → int
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L581" />

### <kbd>method</kbd> `filter_op`

```python theme={null}
filter_op(op_name: 'str | None') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L851" />

### <kbd>method</kbd> `get_calls`

```python theme={null}
get_calls(
    limit: 'int | None' = None,
    offset: 'int | None' = None,
    include_costs: 'bool' = False,
    include_feedback: 'bool' = False,
    all_columns: 'bool' = False
) → CallsIter
```

この保存済みビューのフィルターと設定に一致する call を取得します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L909" />

### <kbd>method</kbd> `get_known_columns`

```python theme={null}
get_known_columns(num_calls_to_query: 'int | None' = None) → list[str]
```

存在が確認されている列の集合を取得します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L919" />

### <kbd>method</kbd> `get_table_columns`

```python theme={null}
get_table_columns() → list[TableColumn]
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L620" />

### <kbd>method</kbd> `hide_column`

```python theme={null}
hide_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L641" />

### <kbd>method</kbd> `insert_column`

```python theme={null}
insert_column(
    idx: 'int',
    path: 'str | ObjectPath',
    label: 'str | None' = None
) → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L979" />

### <kbd>classmethod</kbd> `load`

```python theme={null}
load(ref: 'str') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L744" />

### <kbd>method</kbd> `page_size`

```python theme={null}
page_size(page_size: 'int') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L714" />

### <kbd>method</kbd> `pin_column_left`

```python theme={null}
pin_column_left(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L724" />

### <kbd>method</kbd> `pin_column_right`

```python theme={null}
pin_column_right(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L686" />

### <kbd>method</kbd> `remove_column`

```python theme={null}
remove_column(path: 'int | str | ObjectPath') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L705" />

### <kbd>method</kbd> `remove_columns`

```python theme={null}
remove_columns(*columns: 'str') → SavedView
```

保存済みビューから列を削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L550" />

### <kbd>method</kbd> `remove_filter`

```python theme={null}
remove_filter(index_or_field: 'int | str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L565" />

### <kbd>method</kbd> `remove_filters`

```python theme={null}
remove_filters() → SavedView
```

保存済みビューに設定されているフィルターをすべて削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L523" />

### <kbd>method</kbd> `rename`

```python theme={null}
rename(label: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L680" />

### <kbd>method</kbd> `rename_column`

```python theme={null}
rename_column(path: 'int | str | ObjectPath', label: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L836" />

### <kbd>method</kbd> `save`

```python theme={null}
save() → SavedView
```

保存済みビューをサーバーに公開します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L660" />

### <kbd>method</kbd> `set_columns`

```python theme={null}
set_columns(*columns: 'str') → SavedView
```

グリッドに表示する列を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L614" />

### <kbd>method</kbd> `show_column`

```python theme={null}
show_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L608" />

### <kbd>method</kbd> `sort_by`

```python theme={null}
sort_by(field: 'str', direction: 'SortDirection') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L892" />

### <kbd>method</kbd> `to_grid`

```python theme={null}
to_grid(limit: 'int | None' = None) → Grid
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L773" />

### <kbd>method</kbd> `to_rich_table_str`

```python theme={null}
to_rich_table_str() → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L756" />

### <kbd>method</kbd> `ui_url`

```python theme={null}
ui_url() → str | None
```

UI でこの保存済みビューを表示するための URL。

これは view オブジェクトの URL ではなく、トレースなどが表示される "result" ページの URL である点に注意してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/saved_view.py#L734" />

### <kbd>method</kbd> `unpin_column`

```python theme={null}
unpin_column(col_name: 'str') → SavedView
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/scorer.py#L30" />

## <kbd>class</kbd> `Scorer`

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `column_map`: `dict[str, str] | None`

***

#### <kbd>プロパティ</kbd> display\_name

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/scorer.py#L52" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/flow/scorer.py#L36" />

### <kbd>method</kbd> `model_post_init`

```python theme={null}
model_post_init(_Scorer__context: Any) → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L44" />

### <kbd>method</kbd> `score`

```python theme={null}
score(output: Any, **kwargs: Any) → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L48" />

### <kbd>method</kbd> `summarize`

```python theme={null}
summarize(score_rows: list) → dict | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L88" />

## <kbd>class</kbd> `StringPrompt`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L92" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(content: str)
```

**Pydantic のフィールド:**

* `name`: `str | None`
* `description`: `str | None`
* `ref`: `trace.refs.ObjectRef | None`
* `content`: `<class 'str'>`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L96" />

### <kbd>method</kbd> `format`

```python theme={null}
format(**kwargs: Any) → str
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/prompt/prompt.py#L99" />

### <kbd>classmethod</kbd> `from_obj`

```python theme={null}
from_obj(obj: WeaveObject) → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/table.py#L9" />

## <kbd>class</kbd> `Table`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/table.py#L12" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(rows: 'list[dict]') → None
```

***

#### <kbd>プロパティ</kbd> rows

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/table.py#L50" />

### <kbd>method</kbd> `append`

```python theme={null}
append(row: 'dict') → None
```

表に行を追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/table.py#L56" />

### <kbd>method</kbd> `pop`

```python theme={null}
pop(index: 'int') → None
```

指定したインデックスにある行を表から削除します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L105" />

## <kbd>class</kbd> `ContextAwareThread`

呼び出し元のコンテキストで関数を実行する Thread。

これは、スレッド内で call が期待どおりに動作するようにする `threading.Thread` の差し替え実装です。Weave では特定の contextvars が設定されている必要があります (`call&#95;context.py` を参照) が、新しいスレッドは親からコンテキストを自動ではコピーしないため、call コンテキストが失われることがあります。これは好ましくありません。このクラスは contextvar のコピーを自動化するので、このスレッドを使うだけで、ユーザーの期待どおりに動作します。

このクラスを使わなくても、代わりに次のように書けば同じ効果を得られます。

```python theme={null}
def run_with_context(func, *args, **kwargs):
     context = copy_context()
     def wrapper():
         context.run(func, *args, **kwargs)
     return wrapper

thread = threading.Thread(target=run_with_context(your_func, *args, **kwargs))
thread.start()
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L129" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

***

#### <kbd>プロパティ</kbd> daemon

このスレッドがデーモンスレッドであるかどうかを示す真偽値です。

これは `start()` が呼び出される前に設定する必要があります。そうしないと `RuntimeError` が発生します。初期値はこのスレッドを生成したスレッドから継承されます。メインスレッドはデーモンスレッドではないため、メインスレッドで作成されたすべてのスレッドはデフォルトで `daemon = False` になります。

デーモンスレッドだけが残ると、Python プログラム全体は終了します。

***

#### <kbd>プロパティ</kbd> ident

このスレッドの識別子です。まだ開始されていない場合は None になります。

これは 0 以外の整数です。`get_ident()` 関数を参照してください。スレッドが終了して別のスレッドが作成されると、スレッド識別子が再利用されることがあります。この識別子は、スレッドの終了後も利用できます。

***

#### <kbd>プロパティ</kbd> 名

識別のためにのみ使用される文字列です。

特別な意味はありません。複数のスレッドに同じ名を付けることができます。初期名はコンストラクタで設定されます。

***

#### <kbd>プロパティ</kbd> native\_id

このスレッドのネイティブな整数のスレッド ID です。まだ開始されていない場合は None です。

これは 0 以上の整数です。`get_native_id()` 関数を参照してください。これは、カーネルによって報告されるスレッド ID を表します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L133" />

### <kbd>method</kbd> `run`

```python theme={null}
run() → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L438" />

## <kbd>class</kbd> `ThreadContext`

現在のスレッドとターンの情報にアクセスするためのコンテキストオブジェクト。

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L441" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(thread_id: 'str | None')
```

指定したthread\_idを使用してThreadContextを初期化します。

**引数:**

***

#### <kbd>プロパティ</kbd> thread\_id

このコンテキストの `thread_id` を取得します。

* <b>`thread_id`</b>: このコンテキストのスレッド識別子。無効な場合は None。
  **戻り値:**
  スレッド識別子。スレッドのトラッキングが無効な場合は None。

***

#### <kbd>プロパティ</kbd> turn\_id

アクティブなコンテキスト内の現在の turn\_id を取得します。

**戻り値:**
設定されていれば現在の turn\_id、設定されていなければ None。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L45" />

## <kbd>class</kbd> `ContextAwareThreadPoolExecutor`

呼び出し元のコンテキストで関数を実行する ThreadPoolExecutor。

これは concurrent.futures.ThreadPoolExecutor のドロップイン置換で、executor 内でも Weave の Call が想定どおりに動作するようにします。Weave では特定の contextvars を設定しておく必要があります (`call_context.py` を参照) 。しかし、新しいスレッドは親のコンテキストを自動的には引き継がないため、call コンテキストが失われることがあります。これは望ましくありません。このクラスは contextvar のコピーを自動化するので、この executor を使用すれば、ユーザーの期待どおりに「そのまま動作」します。

このクラスを使わなくても、代わりに次のように書けば同じ効果を得られます。

```python theme={null}
with concurrent.futures.ThreadPoolExecutor() as executor:
     contexts = [copy_context() for _ in range(len(vals))]

     def _wrapped_fn(*args):
         return contexts.pop().run(fn, *args)

     executor.map(_wrapped_fn, vals)
```

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L68" />

### <kbd>method</kbd> `__init__`

```python theme={null}
__init__(*args: 'Any', **kwargs: 'Any') → None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L77" />

### <kbd>method</kbd> `map`

```python theme={null}
map(
    fn: 'Callable',
    *iterables: 'Iterable[Any]',
    timeout: 'float | None' = None,
    chunksize: 'int' = 1
) → Iterator
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/util.py#L73" />

### <kbd>method</kbd> `submit`

```python theme={null}
submit(fn: 'Callable', *args: 'Any', **kwargs: 'Any') → Any
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L200" />

### <kbd>function</kbd> `add_tags`

```python theme={null}
add_tags(obj_ref: 'ObjectRef | str', tags: 'list[str]') → None
```

オブジェクトのバージョンにタグを追加します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L1421" />

### <kbd>関数</kbd> `as_op`

```python theme={null}
as_op(fn: 'Callable[P, R]') → Op[P, R]
```

@weave.op でデコレートされた関数を受け取り、その Op を返します。

@weave.op でデコレートされた関数はすでに Op のインスタンスであるため、この関数は実行時には実質的に何もしません。ただし、OpDef の属性に型安全にアクセスする必要がある場合は、型チェッカーを満たす目的で使用できます。

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef (weave.publish() によって返される) または weave /// URI 文字列のいずれかです。

* <b>`tags`</b>: 追加するタグ文字列のリスト。
  **引数:**

* <b>`fn`</b>: @weave.op でデコレートされた関数。
  **戻り値:**
  関数の Op。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/../../../../weave/trace/api/attributes#L365" />

### <kbd>関数</kbd> `attributes`

```python theme={null}
attributes(attributes: 'dict[str, Any]') → Iterator
```

call に属性を設定するコンテキストマネージャー。

**例:**

```python theme={null}
with weave.attributes({'env': 'production'}):
     print(my_function.call("World"))
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L515" />

### <kbd>関数</kbd> `finish`

```python theme={null}
finish() → None
```

Weave へのログ記録を停止します。

finish の実行後は、weave.op でデコレートされた関数の call はログされなくなります。ログ記録を再開するには、weave.init() をもう一度実行する必要があります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L339" />

### <kbd>関数</kbd> `get`

```python theme={null}
get(uri: 'str | ObjectRef') → Any
```

URI からオブジェクトを取得するための便利な関数です。

Weave でログされた多くのオブジェクトは、自動的に Weave サーバーに登録されます。この関数を使うと、それらのオブジェクトを URI から取得できます。

**引数:**

* <b>`uri`</b>: 完全修飾された Weave ref URI。
  **戻り値:**
  オブジェクト。

**例:**

```python theme={null}
weave.init("weave_get_example")
dataset = weave.Dataset(rows=[{"a": 1, "b": 2}])
ref = weave.publish(dataset)

dataset2 = weave.get(ref)  # datasetと同じ！
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L262" />

### <kbd>関数</kbd> `get_aliases`

```python theme={null}
get_aliases(obj_ref: 'ObjectRef | str') → list[str]
```

オブジェクトバージョンのエイリアスを取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトバージョンへの参照。`ObjectRef` または `weave:///` URI 文字列を指定します。
  **戻り値:**
  エイリアス文字列のリストです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L114" />

### <kbd>関数</kbd> `get_client`

```python theme={null}
get_client() → WeaveClient | None
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/context/call_context.py#L119" />

### <kbd>関数</kbd> `get_current_call`

```python theme={null}
get_current_call() → Call | None
```

現在実行中の Op の内部で、その Op の Call オブジェクトを取得します。

**戻り値:**
現在実行中の Op の Call オブジェクト。tracking が初期化されていない場合、またはこの method が Op の外で呼び出された場合は None です。

**注記:**

> 返された Call の `attributes` dict は、call が開始されると不変になります。Op を呼び出す前に call のメタデータを設定するには、:func:`weave.attributes` を使用してください。`summary` フィールドは Op の実行中に更新でき、call の終了時に計算された summary 情報とマージされます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L224" />

### <kbd>関数</kbd> `get_tags`

```python theme={null}
get_tags(obj_ref: 'ObjectRef | str') → list[str]
```

オブジェクトのバージョンのタグを取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列を指定します。
  **戻り値:**
  タグ文字列のリストです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L276" />

### <kbd>関数</kbd> `get_tags_and_aliases`

```python theme={null}
get_tags_and_aliases(obj_ref: 'ObjectRef | str') → tuple[list[str], list[str]]
```

オブジェクトのバージョンの タグ と エイリアス を、1回の呼び出しでまとめて取得します。

**引数:**

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照です。ObjectRef または weave /// URI 文字列を指定します。
  **戻り値:**
  `(タグ, エイリアス)` のタプルです。どちらも文字列のリストです。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L42" />

### <kbd>関数</kbd> `init`

```python theme={null}
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
```

Weave のトラッキングを初期化し、wandb プロジェクトにログします。

ログはグローバルに初期化されるため、`init` の戻り値への参照を保持しておく必要はありません。

`init` の実行後、`weave.op` でデコレートされた関数の Call は、指定したプロジェクトにログされます。

**引数:**

注: グローバルな後処理設定は、各 op 独自の後処理の後に、すべての op に適用されます。順序は常に次のとおりです: 1. op 固有の後処理 2. グローバルな後処理

* <b>`project_name`</b>: ログ先の Weights & Biases のチームおよびプロジェクトの名。チームを指定しない場合は、デフォルトの entity が使用されます。デフォルトの entity を確認または更新するには、W\&B Models ドキュメントの [User Settings](https://docs.wandb.ai/guides/models/app/settings-page/user-settings/#default-team) を参照してください。
* <b>`settings`</b>: Weave クライアント全般の設定。
* <b>`autopatch_settings`</b>: (非推奨) autopatch インテグレーションの設定。代わりに明示的なパッチ適用を使用してください。
* <b>`global_postprocess_inputs`</b>: すべての op のすべての入力に適用される関数。
* <b>`global_postprocess_output`</b>: すべての op のすべての出力に適用される関数。
* <b>`global_attributes`</b>: すべてのトレースに適用される属性の辞書。
  **戻り値:**
  Weave クライアント。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L300" />

### <kbd>関数</kbd> `list_aliases`

```python theme={null}
list_aliases() → list[str]
```

プロジェクト内のすべての重複のないエイリアスを一覧表示します。

**戻り値:**
プロジェクト内のすべてのエイリアス文字列をソートしたリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L290" />

### <kbd>関数</kbd> `list_tags`

```python theme={null}
list_tags() → list[str]
```

プロジェクト内のすべての重複しない タグ を一覧表示します。

**戻り値:**
プロジェクト内のすべての タグ 文字列をソートしたリスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/log_call.py#L18" />

### <kbd>関数</kbd> `log_call`

```python theme={null}
log_call(
    op: 'str',
    inputs: 'dict[str, Any]',
    output: 'Any',
    parent: 'Call | None' = None,
    attributes: 'dict[str, Any] | None' = None,
    display_name: 'str | Callable[[Call], str] | None' = None,
    use_stack: 'bool' = True,
    exception: 'BaseException | None' = None
) → Call
```

デコレーターパターンを使用せずに、call を Weave に直接ログします。

この関数は、オペレーションを Weave にログするための命令型 API を提供します。すでに実行済みの call をあとからログしたい場合や、ユースケースにデコレーターパターンが適していない場合に便利です。

**引数:**

* <b>`op`</b> (str):  ログするオペレーション名です。これは、その call の `op_name` として使用されます。匿名オペレーション (公開済みの ops を参照しない文字列) もサポートされます。
* <b>`inputs`</b> (dict\[str, Any]):  オペレーションの入力パラメーターを格納した辞書です。
* <b>`output`</b> (Any):  オペレーションの出力 / 結果です。
* <b>`parent`</b> (Call | None):  この call をネストするための省略可能な親 call です。指定しない場合、この call はルートレベルの call になります (現在の call コンテキストが存在する場合は、その下にネストされます) 。デフォルトは None です。
* <b>`attributes`</b> (dict\[str, Any] | None):  call に付加する省略可能なメタデータです。これらは call の作成後に固定されます。デフォルトは None です。
* <b>`display_name`</b> (str | Callable\[\[Call], str] | None):  UI で call に表示する省略可能な表示名です。文字列、または call を受け取って文字列を返す callable を指定できます。デフォルトは None です。
* <b>`use_stack`</b> (bool):  call をランタイムスタックに積むかどうかです。True の場合、call は call コンテキスト内で利用可能になり、`weave.require_current_call()` でアクセスできます。False の場合、call はログされますが、call スタックには追加されません。デフォルトは True です。
* <b>`exception`</b> (BaseException | None):  オペレーションが失敗した場合にログする省略可能な例外です。デフォルトは None です。

**戻り値:**

* <b>`Call`</b>:  完全な trace 情報を含む、作成および完了済みの Call オブジェクトです。

**例:**
基本的な使用方法:

````python theme={null}
import weave
    >>> weave.init('my-project')
    >>> call = weave.log_call(
    ...     op="my_function",
    ...     inputs={"x": 5, "y": 10},
    ...     output=15
    ... )

    属性と表示名を指定してログする:
    >>> call = weave.log_call(
    ...     op="process_data",
    ...     inputs={"data": [1, 2, 3]},
    ...     output={"mean": 2.0},
    ...     attributes={"version": "1.0", "env": "prod"},
    ...     display_name="Data Processing"
    ... )

    失敗した操作をログする:
    >>> try:
    ...     result = risky_operation()
    ... except Exception as e:
    ...     call = weave.log_call(
    ...         op="risky_operation",
    ...         inputs={},
    ...         output=None,
    ...         exception=e
    ...     )

    Callのネスト:
    >>> parent_call = weave.log_call("parent", {"input": 1}, 2)
    >>> child_call = weave.log_call(
    ...     "child",
    ...     {"input": 2},
    ...     4,
    ...     parent=parent_call
    ... )

    callスタックに追加せずにログする:
    >>> call = weave.log_call(
    ...     op="background_task",
    ...     inputs={"task_id": 123},
    ...     output="completed",
    ...     use_stack=False  # callスタックにプッシュしない
    ... )

---

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/op.py#L1220" />

### <kbd>function</kbd> `op`

```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,
    kind: 'OpKind | None' = None,
    color: 'OpColor | None' = None,
    eager_call_start: 'bool' = False
) → Callable[[Callable[P, R]], Op[P, R]] | Op[P, R]
````

関数またはmethodを Weave の op に変換するデコレータです。sync と async の両方に対応しています。イテレータ関数を自動的に検出し、適切な動作を適用します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L118" />

### <kbd>関数</kbd> `publish`

```python theme={null}
publish(
    obj: 'Any',
    name: 'str | None' = None,
    tags: 'list[str] | None' = None,
    aliases: 'list[str] | None' = None
) → ObjectRef
```

Python オブジェクトを保存し、バージョン管理します。

オブジェクトの名がすでに存在し、そのコンテンツハッシュがそのオブジェクトの最新バージョンと一致しない場合、Weave はそのオブジェクトの新しいバージョンを作成します。

* <b>`func`</b>: デコレートする関数。

* <b>`name`</b>: op のカスタム名。デフォルトは関数名です。

* <b>`call_display_name`</b>: Call の表示名。文字列または callable を指定できます。

* <b>`postprocess_inputs`</b>: ログする前に入力を変換する関数。

* <b>`postprocess_output`</b>: ログする前に出力を変換する関数。

* <b>`tracing_sample_rate`</b>: トレースする Call の割合 (0.0～1.0) 。

* <b>`enable_code_capture`</b>: この op のソースコードを取得するかどうか。

* <b>`accumulator`</b>: ストリーミング op の結果を蓄積する関数。

* <b>`eager_call_start`</b>: True の場合、Call の開始はバッチ処理されず、すぐに送信されます。評価のように実行時間の長い operation を UI にすぐ表示する必要がある場合に便利です。
  **引数:**

* <b>`obj`</b>: 保存してバージョン管理するオブジェクト。

* <b>`name`</b>: オブジェクトの保存時に使用する名。

* <b>`tags`</b>: 公開されたオブジェクトバージョンに追加する任意の タグ のリスト。

* <b>`aliases`</b>: 公開されたオブジェクトバージョンに設定する任意の エイリアス のリスト。
  **戻り値:**
  保存されたオブジェクトへの Weave Ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L310" />

### <kbd>関数</kbd> `ref`

```python theme={null}
ref(location: 'str') → ObjectRef
```

既存の Weave オブジェクトへの Ref を作成します。オブジェクト自体を直接取得するわけではありませんが、他の Weave API 関数に渡せるようになります。

**引数:**

* <b>`location`</b>: Weave Ref URI、または `weave.init()` が呼び出されている場合は `name:version` もしくは `name`。バージョンが指定されていない場合は `latest` が使用されます。
  **戻り値:**
  オブジェクトを指す Weave Ref。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L250" />

### <kbd>関数</kbd> `remove_aliases`

```python theme={null}
remove_aliases(obj_ref: 'ObjectRef | str', alias: 'str | list[str]') → None
```

オブジェクトから1つ以上のエイリアスを削除します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L212" />

### <kbd>関数</kbd> `remove_tags`

```python theme={null}
remove_tags(obj_ref: 'ObjectRef | str', tags: 'list[str]') → None
```

オブジェクトのバージョンから タグ を削除します。

* <b>`obj_ref`</b>: オブジェクトへの参照です。ObjectRef または weave /// URI 文字列を指定します。
* <b>`alias`</b>: 削除するエイリアス名、またはエイリアス名のリストです。
  **引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/context/call_context.py#L70" />

### <kbd>関数</kbd> `require_current_call`

```python theme={null}
require_current_call() → Call
```

現在実行中の Op の内部で、その Op に対応する Call オブジェクトを取得します。

これにより、実行中でも id や feedback などの Call の属性にアクセスできます。

```python theme={null}
@weave.op
def hello(name: str) -> None:
     print(f"Hello {name}!")
     current_call = weave.require_current_call()
     print(current_call.id)
```

Op の実行後でも、Call にアクセスできます。

Call の ID があれば (UI で確認したものなど) 、`weave.init` が返す `WeaveClient` の `get_call` method を使用して、Call オブジェクトを取得できます。

```python theme={null}
client = weave.init("<project>")
mycall = client.get_call("<call_id>")
```

あるいは、Op を定義した後にその `call` method を使用することもできます。例:

```python theme={null}
@weave.op
def add(a: int, b: int) -> int:
     return a + b

result, call = add.call(1, 2)
print(call.id)
```

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列のいずれかです。
* <b>`tags`</b>: 削除するタグ文字列のリスト。
  **戻り値:**
  現在実行中の Op の Call オブジェクト

**発生する例外:**

* <b>`NoCurrentCallError`</b>: tracking が初期化されていない場合、またはこの method が Op の外で呼び出された場合。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L238" />

### <kbd>関数</kbd> `set_aliases`

```python theme={null}
set_aliases(obj_ref: 'ObjectRef | str', alias: 'str | list[str]') → None
```

オブジェクトのバージョンに1つ以上のエイリアスを設定します。

**引数:**

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/trace/api.py#L385" />

### <kbd>関数</kbd> `set_view`

```python theme={null}
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
```

現在のcall summaryの`_weave.views.<name>`にカスタムviewを追加します。

* <b>`obj_ref`</b>: オブジェクトのバージョンへの参照。ObjectRef または weave /// URI 文字列のいずれかです。

* <b>`alias`</b>: 設定するエイリアス名、またはエイリアス名のリスト (例: "production") 。
  **引数:**

* <b>`name`</b>: viewの名前 (`summary._weave.views` 配下のキー) 。

* <b>`content`</b>: `weave.Content` インスタンス、または生の文字列。文字列は、指定された拡張子またはMIMEタイプを使用して `Content.from_text` でラップされます。

* <b>`extension`</b>: `content` が文字列の場合に使用するオプションのファイル拡張子。

* <b>`mimetype`</b>: `content` が文字列の場合に使用するオプションのMIMEタイプ。

* <b>`metadata`</b>: テキストから `Content` を作成する際に付加するオプションのメタデータ。

* <b>`encoding`</b>: テキストから `Content` を作成する際に適用するテキストエンコーディング。
  **戻り値:**
  なし

**例:**
` import weave`

> > > weave.init("proj")
> > > @weave.op
> > > ... def foo():
> > > ...     weave.set\_view("readme", "# Hello", extension="md")
> > > ...     return 1
> > > foo()

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/../../../../weave/trace/api/thread#L468" />

### <kbd>関数</kbd> `thread`

```python theme={null}
thread(
    thread_id: 'str | None | object' = <object object at 0x7f9716a290d0>
) → Iterator[ThreadContext]
```

コンテキスト内のcallに thread\_id を設定するためのコンテキストマネージャー。

**例：**

```python theme={null}
# thread_id を自動生成する
with weave.thread() as t:
     print(f"Thread ID: {t.thread_id}")
     result = my_function("input")  # この call には自動生成された thread_id が付与される
     print(f"Current turn: {t.turn_id}")

# thread_id を明示的に指定する
with weave.thread("custom_thread") as t:
     result = my_function("input")  # この call には thread_id="custom_thread" が付与される

# スレッド追跡を無効にする
with weave.thread(None) as t:
     result = my_function("input")  # この call には thread_id=None が付与される
```

**引数:**

* <b>`thread_id`</b>: このコンテキストで Call に関連付けるスレッド識別子。指定しない場合は、UUID v7 が自動生成されます。`None` の場合は、スレッドのトラッキングが無効化されます。
  **返される値:**

* <b>`ThreadContext`</b>: `thread&#95;id` と現在の `turn&#95;id` にアクセスできるオブジェクト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.35/weave/integrations/wandb/wandb.py#L9" />

### <kbd>関数</kbd> `wandb_init_hook`

```python theme={null}
wandb_init_hook() → None
```
