> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-dependabot-github-actions-actions-cache-6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# weave

> Weave Python SDK の API リファレンス

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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/weave/flow/monitor.py#L187" />

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

複数の scorer を 1 つの分類器に統合するモニターです。

分類器 モニター は、同じモデルを対象とする複数の LLMAsAJudgeScorers の プロンプト を、1 回のスコアリング call にまとめます。

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

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

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

### <kbd>メソッド</kbd> `activate`

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

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

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

***

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

### <kbd>メソッド</kbd> `deactivate`

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

モニターを停止します。

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

***

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

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

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

***

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

### <kbd>method</kbd> `get_prompt_footer`

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

マージされた 分類器 プロンプトの後に追加するテキスト。

***

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

### <kbd>method</kbd> `get_prompt_header`

```python theme={null}
get_prompt_header(op_name: str) → str
```

マージされた分類器プロンプトの前に追加するテキスト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/weave/dataset/dataset.py#L71" />

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

```python theme={null}
from_hf(hf_dataset: 'HFDataset | HFDatasetDict') → Self
```

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/weave/prompt/prompt.py#L192" />

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

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/weave/prompt/prompt.py#L455" />

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/weave/trace/op.py#L540" />

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/weave/evaluation/eval.py#L145" />

## <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 Call を追加して出力を返す
     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 0x7f1615b1b600>, 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.42/weave/trace/op.py#L379" />

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

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

***

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

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

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

***

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

### <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.42/weave/evaluation/eval.py#L390" />

### <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.42/weave/evaluation/eval.py#L426" />

### <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.42/weave/evaluation/eval.py#L465" />

### <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.42/pydantic/_internal/_model_construction.py#L247" />

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

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

***

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

### <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.42/weave/trace/op.py#L304" />

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

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

***

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

## <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.42/weave/evaluation/eval_imperative.py#L684" />

### <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.42/weave/evaluation/eval_imperative.py#L1106" />

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

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

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

***

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

### <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.42/weave/evaluation/eval_imperative.py#L950" />

### <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.42/weave/evaluation/eval_imperative.py#L877" />

### <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.42/weave/evaluation/eval_imperative.py#L989" />

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

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

評価 に summary dict をログします。

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

***

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

### <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.42/weave/type_handlers/File/file.py#L30" />

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

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

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/weave/session/session.py#L277" />

## <kbd>class</kbd> `LLM`

1 回の LLM API Call です。chat OTel span にマッピングされます。

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

* `model`: `<class 'str'>`

* `provider_name`: `<class 'str'>`

* `response_id`: `<class 'str'>`

* `response_model`: `<class 'str'>`

* `output_type`: `<class 'str'>`

* `system_instructions`: `list[str]`

* `usage`: `<class 'session.types.Usage'>`

* `reasoning`: `<class 'session.types.Reasoning'>`

* `finish_reasons`: `list[str]`

* `input_messages`: `list[session.types.Message]`

* `output_messages`: `list[session.types.Message]`

* `media_attachments`: `list[session.types.MediaAttachment]`

* `request_temperature`: `float | None`

* `request_max_tokens`: `int | None`

* `request_top_p`: `float | None`

* `request_frequency_penalty`: `float | None`

* `request_presence_penalty`: `float | None`

* `request_seed`: `int | None`

* `request_stop_sequences`: `list[str]`

* `request_choice_count`: `int | None`

* `started_at`: `datetime.datetime | None`

* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L320" />

### <kbd>method</kbd> `attach_media`

```python theme={null}
attach_media(
    content: 'bytes | str' = '',
    uri: 'str' = '',
    file_id: 'str' = '',
    mime_type: 'str' = '',
    modality: 'str' = ''
) → LLM
```

この LLM Call にメディアを添付します。

content、uri、またはfile\_idのいずれか 1 つを必ず指定してください。明示的に設定されていない場合、Modality は mime\_type から推定されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L362" />

### <kbd>メソッド</kbd> `attach_media_url`

```python theme={null}
attach_media_url(url: 'str', modality: 'str' = '') → LLM
```

この LLM Call にメディア URL を添付します。

呼び出し元が上流のメッセージから URL string を受け取り、その内容を確認したくない一般的なケース向けに、`attach_media` を簡単に利用できるようにしたものです。`data:` URL は `mime_type` + インラインコンテンツ (kind=blob) として解析され、通常の URI は `kind=uri` になります。空の URL は無視されます。チェーンできるように `self` を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L492" />

### <kbd>メソッド</kbd> `end`

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

***

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

### <kbd>メソッド</kbd> `model_post_init`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L310" />

### <kbd>メソッド</kbd> `output`

```python theme={null}
output(content: 'str') → LLM
```

output\_messages に アシスタントメッセージ を追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L380" />

### <kbd>メソッド</kbd> `record`

```python theme={null}
record(
    input_messages: 'list[Message] | None' = None,
    output_messages: 'list[Message] | None' = None,
    media_attachments: 'list[MediaAttachment] | None' = None,
    usage: 'Usage | None' = None,
    reasoning: 'Reasoning | str | None' = None,
    response_id: 'str | None' = None,
    response_model: 'str | None' = None,
    finish_reasons: 'list[str] | None' = None,
    output_type: 'str | None' = None
) → LLM
```

1 回の Call で、複数の LLM Call フィールドを設定します。

手動でインストルメントされたエージェントでは通常、LLM Call の最後に 8 個以上の個別フィールド (`input_messages`、`output_messages`、`usage`、`response_id` など) を割り当てて、chat span を組み立てます。`record(...)` はそれらを 1 回のキーワード引数による Call にまとめるため、記録箇所を簡潔に保てます。

明示的に渡された (`None` 以外の) フィールドのみが適用され、既存の値は保持されます。`reasoning` は `Reasoning` インスタンスまたは通常の `string` のいずれも受け入れます (自動的にラップされます) 。チェーンのために `self` を返します。

***

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

### <kbd>メソッド</kbd> `think`

```python theme={null}
think(content: 'str') → LLM
```

推論/思考過程の内容を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L254" />

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

一括 `log_*` Call の結果。

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

* `session_id`: `<class 'str'>`
* `trace_ids`: `list[str]`
* `root_span_ids`: `list[str]`
* `span_count`: `<class 'int'>`

***

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

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

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

**引数:**

* <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.42/rich/markdown.py#L549" />

### <kbd>メソッド</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.42/weave/session/types.py#L243" />

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

LLM Call に添付されるメディア。

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

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

* `kind`: `typing.Literal['blob', 'uri', 'file']`

* `modality`: `<class 'str'>`

* `mime_type`: `<class 'str'>`

* `content`: `bytes | str`

* `uri`: `<class 'str'>`

* `file_id`: `<class 'str'>`

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L158" />

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

会話内の 1 つのメッセージです。

2 つの構築スタイルがサポートされます。

1. フラット形式 (後方互換性があり、プレーンテキストで扱いやすい) :  `Message(role="assistant", content="Hi there")`

2. 明示的なパーツ形式 (より高機能で、tool call、推論とテキストの混在、インラインメディアをサポート) :  `Message(role="assistant", parts=[TextPart(content="Let me check"),  ToolCallPart(id="c1", name="get_weather", arguments='{...}')])`

`parts` が空でない場合、これが正規の表現になります。空の場合、シリアライザーはフラットフィールドから単一の TextPart (または `role="tool"` の場合は ToolCallResponsePart) を生成します。

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

* `role`: `typing.Literal['user', 'assistant', 'system', 'tool']`
* `content`: `<class 'str'>`
* `tool_call_id`: `<class 'str'>`
* `tool_name`: `<class 'str'>`
* `parts`: `list[typing.Annotated[session.types.TextPart | session.types.ReasoningPart | session.types.ToolCallPart | session.types.ToolCallResponsePart | session.types.BlobPart | session.types.UriPart | session.types.FilePart, FieldInfo(annotation=NoneType, required=True, discriminator='type')]]`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L192" />

### <kbd>クラスメソッド</kbd> `assistant`

```python theme={null}
assistant(
    text: 'str' = '',
    tool_calls: 'list[ToolCallPart] | None' = None
) → Message
```

省略可能なテキストと tool Calls を含むアシスタントメッセージを作成します。

簡単な返信にはプレーンテキストを使用し、アシスタントが 1 つ以上のツールを要求する場合は `tool_calls` を渡します。両方を指定した場合、テキストは先頭の `TextPart` として出力され、その後に各 `ToolCallPart` が続くため、チャットビューではそれらがインラインで表示されます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L187" />

### <kbd>クラスメソッド</kbd> `system`

```python theme={null}
system(text: 'str') → Message
```

プレーンテキストからシステムメッセージを生成します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L214" />

### <kbd>クラスメソッド</kbd> `tool_result`

```python theme={null}
tool_result(call_id: 'str', output: 'Any') → Message
```

以前にリクエストされた tool Call のツール結果メッセージを作成します。

`output` には `string`、`dict`、`list`、スカラー、または `None` を指定できます。基盤となる `ToolCallResponsePart` は、文字列以外の値を JSON エンコードします。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L182" />

### <kbd>クラスメソッド</kbd> `user`

```python theme={null}
user(text: 'str') → Message
```

プレーンテキストからユーザーメッセージを作成します。

***

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

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

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

### <kbd>メソッド</kbd> `__init__`

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

**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.42/weave/prompt/prompt.py#L180" />

### <kbd>メソッド</kbd> `format`

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

***

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

### <kbd>メソッド</kbd> `format_message`

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

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

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

***

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

### <kbd>クラスメソッド</kbd> `from_obj`

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

***

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

## <kbd>クラス</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.42/weave/flow/model.py#L51" />

### <kbd>メソッド</kbd> `get_infer_method`

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

***

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

## <kbd>クラス</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[typing.Union[typing.Literal['genai.turn_ended'], 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.42/weave/flow/monitor.py#L92" />

### <kbd>メソッド</kbd> `activate`

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

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

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

***

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

### <kbd>メソッド</kbd> `deactivate`

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

モニターを停止します。

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

***

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

### <kbd>クラスメソッド</kbd> `from_obj`

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

***

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

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

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

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

**属性:**

* <b>`name`</b> (str | None):  オブジェクトの人間が読み取れる名前。
* <b>`description`</b> (str | None):  オブジェクトが表す内容の説明。
* <b>`ref`</b> (ObjectRef | None):  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.42/weave/object/obj.py#L65" />

### <kbd>クラスメソッド</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.42/weave/object/obj.py#L108" />

### <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.42/weave/object/obj.py#L91" />

### <kbd>クラスメソッド</kbd> `strip_weave_serialization_metadata`

```python
strip_weave_serialization_metadata(data: Any) → Any
````

dict 入力から Weave のシリアライズ メタデータを削除します。

Weave のシリアライズでは、型を再構成するために dict に \_type、\_class\_name、\_bases が追加されます。これらは実際のモデル フィールドではないため、extra="forbid" を使用する Pydantic の検証前に削除する必要があります。

***

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

## <kbd>クラス</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.42/../../../../weave/trace/refs/__init__" />

### <kbd>メソッド</kbd> `__init__`

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

***

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

***

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

***

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

***

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

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

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

***

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

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

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

***

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

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

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

***

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

### <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.42/weave/trace/refs.py#L93" />

### <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.42/weave/trace/refs.py#L294" />

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

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

***

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

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

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

***

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

### <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.42/weave/trace/refs.py#L176" />

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

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

***

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

### <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.42/weave/trace/refs.py#L170" />

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/weave/flow/saved_view.py#L496" />

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

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

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/weave/flow/saved_view.py#L979" />

### <kbd>クラスメソッド</kbd> `load`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/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.42/weave/flow/scorer.py#L57" />

### <kbd>クラスメソッド</kbd> `from_obj`

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

***

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

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

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

***

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

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

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

***

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

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L763" />

## <kbd>class</kbd> `Session`

会話セッションです。conversation\_id ごとにターンをグループ化します (span はありません) 。

`continue_parent_trace` は、このセッションが作成するターンの トレース 分離を制御します。デフォルトの `False` は、各ターンがそれぞれ独自の OTel トレース を開始することを意味します (スタンドアロンの Agents タブのビューでは、これが適切です) 。アプリケーションに外側の トレース (例: fastapi でインストルメントされたリクエスト) があり、その中に エージェント の呼び出しを含める必要がある場合は、`True` に設定します。

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

* `session_id`: `<class 'str'>`
* `session_name`: `<class 'str'>`
* `agent_name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `include_content`: `<class 'bool'>`
* `continue_parent_trace`: `<class 'bool'>`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L816" />

### <kbd>method</kbd> `end`

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

***

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

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L790" />

### <kbd>method</kbd> `start_turn`

```python theme={null}
start_turn(
    user_message: 'str' = '',
    model: 'str' = '',
    agent_name: 'str' = ''
) → Turn
```

新しいターンを作成します。前のターンがまだ開いている場合は、自動的に終了します。

`_current_turn` の contextvar を設定することで、コンテキストマネージャーを使用しているかどうかにかかわらず、`get_current_turn()` を通じてターンを参照できます。また、このセッションから `continue_parent_trace` を引き継ぎます。

***

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

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

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/weave/prompt/prompt.py#L99" />

### <kbd>クラスメソッド</kbd> `from_obj`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L533" />

## <kbd>class</kbd> `SubAgent`

1 つの ターン 内で委譲されるエージェント呼び出しです。

同じトレース内のネストされた invoke\_agent OTel スパンに対応します。

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

* `name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L592" />

### <kbd>method</kbd> `end`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L549" />

### <kbd>method</kbd> `llm`

```python theme={null}
llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

このサブエージェント内で LLM 呼び出しを開始します。

コンテキストマネージャーを使用しているかどうかに関係なく、`get_current_llm()` から LLM を参照できるように、`_current_llm` contextvar を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L569" />

### <kbd>method</kbd> `tool`

```python theme={null}
tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

このサブエージェント内でツール実行を開始します。

***

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

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

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/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.42/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.42/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.42/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.42/weave/trace/util.py#L133" />

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

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

***

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

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

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

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

### <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.42/weave/trace/util.py#L45" />

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

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

これは concurrent.futures.ThreadPoolExecutor のドロップイン置換で、executor 内でも Weave の Call が想定どおりに動作するようにします。Weave では特定の contextvars を設定しておく必要があります (`call&#95;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.42/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.42/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.42/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.42/weave/session/session.py#L187" />

## <kbd>class</kbd> `Tool`

1 回分のツール実行です。`execute_tool` OTel span に対応します。

`arguments` と `result` には `JSONString` アノテーションが使用されます。呼び出し元は dict / list / scalar を代入でき、SDK は構築時または代入時にそれを JSON エンコードします。保存される値は常に string で、GenAI semconv の wire format と一致します。

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

* `name`: `<class 'str'>`
* `arguments`: `<class 'str'>`
* `result`: `<class 'str'>`
* `tool_call_id`: `<class 'str'>`
* `tool_type`: `<class 'str'>`
* `tool_description`: `<class 'str'>`
* `tool_definitions`: `<class 'str'>`
* `duration_ms`: `<class 'int'>`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L241" />

### <kbd>method</kbd> `end`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L627" />

## <kbd>class</kbd> `Turn`

ユーザーとエージェントの 1 回のやり取りです。`invoke_agent` の OTel span に対応します。

デフォルトでは、各ターンは独自の OTel トレース を開始し (`continue_parent_trace=False`) 、Agents タブにはターンごとに 1 つの トレース が表示されます。外側の トレース がすでにアクティブで、エージェント呼び出しをその内側にネストしたい場合は、Session (または Turn に直接) で `continue_parent_trace=True` を設定してください。たとえば、fastapi でインストルメントされたリクエスト内の場合です。

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

* `agent_name`: `<class 'str'>`
* `model`: `<class 'str'>`
* `agent_id`: `<class 'str'>`
* `agent_description`: `<class 'str'>`
* `agent_version`: `<class 'str'>`
* `messages`: `list[session.types.Message]`
* `spans`: `list[session.session.LLM | session.session.Tool | session.session.SubAgent]`
* `continue_parent_trace`: `<class 'bool'>`
* `started_at`: `datetime.datetime | None`
* `ended_at`: `datetime.datetime | None`

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L717" />

### <kbd>method</kbd> `end`

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L660" />

### <kbd>method</kbd> `llm`

```python theme={null}
llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

LLM Call を開始します (この ターン の子である chat span) 。

コンテキストマネージャーを使用しているかどうかにかかわらず、`get_current_llm()` を介して LLM にアクセスできるように、contextvar `_current_llm` を設定します。

***

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

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L684" />

### <kbd>method</kbd> `subagent`

```python theme={null}
subagent(name: 'str', model: 'str' = '') → SubAgent
```

サブエージェントの呼び出しを開始します (同じトレース内のネストされた invoke\_agent span) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L680" />

### <kbd>method</kbd> `tool`

```python theme={null}
tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

ツールの実行を開始します (この ターン の子である execute\_tool span) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L655" />

### <kbd>method</kbd> `user`

```python theme={null}
user(content: 'str') → Turn
```

ターンの途中でユーザーメッセージを追加します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/types.py#L227" />

## <kbd>class</kbd> `Usage`

LLM Call における token 使用量です。

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

* `input_tokens`: `<class 'int'>`
* `output_tokens`: `<class 'int'>`
* `reasoning_tokens`: `<class 'int'>`
* `cache_creation_input_tokens`: `<class 'int'>`
* `cache_read_input_tokens`: `<class 'int'>`

***

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

### <kbd>関数</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.42/weave/trace/op.py#L1460" />

### <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.42/../../../../weave/trace/api/attributes#L460" />

### <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.42/weave/session/session.py#L968" />

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

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

contextvar から取得した現在の LLM Call を終了します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L954" />

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

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

現在のセッションを終了します (contextvarから) 。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L961" />

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

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

contextvar から現在のターンを終了します。

***

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

### <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.42/weave/trace/api.py#L434" />

### <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.42/weave/trace/api.py#L330" />

### <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.42/weave/trace/api.py#L182" />

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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.42/weave/session/session.py#L985" />

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

```python theme={null}
get_current_llm() → LLM | None
```

contextvar からアクティブな LLM Call を返します。なければ None を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L975" />

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

```python theme={null}
get_current_session() → Session | None
```

contextvar からアクティブなセッションを返します。ない場合は None を返します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L980" />

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

```python theme={null}
get_current_turn() → Turn | None
```

contextvar から現在アクティブな turn を返します。存在しない場合は None を返します。

***

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

### <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.42/weave/trace/api.py#L344" />

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

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

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

**引数:**

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

***

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

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

```python theme={null}
init(
    project_name: 'str',
    settings: 'UserSettings | dict[str, Any] | None' = None,
    autopatch_settings: 'AutopatchSettings | None' = None,
    postprocess_inputs: 'PostprocessInputsFunc | None' = None,
    postprocess_output: 'PostprocessOutputFunc | None' = None,
    attributes: 'dict[str, Any] | 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 独自の後処理の後に実行されます。順序は常に次のとおりです: 1. op 固有の後処理 2. クライアントレベルの後処理

* <b>`project_name`</b>: ログ先の Weights & Biases のチーム名と project 名です。チームを指定しない場合は、デフォルトの entity が使用されます。デフォルトの entity を確認または更新するには、W\&B Models ドキュメントの [User Settings](https://docs.wandb.ai/platform/app/settings-page/user-settings#default-team) を参照してください。
* <b>`settings`</b>: Weave クライアント全般の設定です。`UserSettings` インスタンス、または次のいずれかのキーを含む dict (いずれも省略可能) を指定できます。すべての設定は、
  接頭辞 WEAVE\_ を使用する環境変数でも設定できます (例: `WEAVE&#95;DISABLED=true`) 。使用可能な設定: - `disabled` (bool): すべての関数でトレースを無効にします。デフォルト: `False` - `print_call_link`
  (bool): ops について、Weave UI へのリンクをターミナルに出力します。デフォルト: `True` - `log_level` (str): ログする情報の種類を設定します (`DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`) 。デフォルト: `INFO` -
  `display_viewer` (str): Weave がコンソールでオブジェクトをどのように表示するかを制御します (`auto`, `rich`, `print`) 。デフォルト: `auto` - `capture_code` (bool): トレース対象の ops のコードを Weave プロジェクトに取得します。
  デフォルト: `True` - `implicitly_patch_integrations` (bool): サポートされるライブラリに自動的にパッチを適用します。デフォルト: `True` - `redact_pii` (bool): メールアドレス、電話
  番号、クレジットカードなどの機密情報がないか、すべてのトレースデータをスキャンし、サーバーに送信する前にプレースホルダー値に置き換えます。presidio-analyzer パッケージと presidio-anonymizer パッケージが必要です。
* <b>`Default`</b>: `False` - `redact_pii_fields` (list\[str]): `redact_pii` が True の場合に、マスクする PII エンティティのタイプを指定します。空の場合は、Presidio のデフォルト セットを使用します。例  \['EMAIL','PHONE\_NUMBER','CREDIT\_CARD','US\_SSN']。完全なリストは  [https://microsoft.github.io/presidio/supported\_entities/](https://microsoft.github.io/presidio/supported_entities/) を参照してください
* <b>`Default`</b>: `[]` - `redact_pii_exclude_fields` (list\[str]): 除外する PII エンティティ タイプ。Default: `[]` - `capture_client_info` (bool): Python/SDK のバージョン情報を取得します。Default: `True` -
  `capture_system_info` (bool): OS 情報を取得します。Default: `True` - `client_parallelism` (int): バックグラウンド Ops 用ワーカーの数。Default: `auto` - `use_server_cache` (bool): サーバー
  応答のローカル ディスク キャッシュを有効にします。 - `server_cache_size_limit` (int): バイト単位のキャッシュ サイズの上限。Default: `1_000_000_000` - `server_cache_dir` (str): サーバー キャッシュ用のディレクトリ。Default: `temporary` -
  `scorers_dir` (str): Scorer モデル チェックポイント用のディレクトリ。Default: `~/.cache/wandb/weave-scorers` - `max_calls_queue_size` (int): キューの最大サイズ (0 = 無制限) 。Default: `100_000` -
  `retry_max_interval` (float): 再試行の最大間隔 (秒) 。Default: `300` - `retry_max_attempts` (int): 最大再試行回数。Default: `3` - `enable_disk_fallback` (bool): 破棄された
  項目をディスクに書き込みます。Default: `True` - `use_parallel_table_upload` (bool): 大きな表の並列チャンク upload を有効にします。False の場合、表はより小さなチャンクに分けて順次 upload されます。
* <b>`Default`</b>: `True` - `http_timeout` (float): HTTP リクエストの完了を待機する最大時間 (秒) です。これには、接続時間、データ転送時間、サーバーでの処理時間が含まれます。ネットワークが低速な場合や、大きなペイロードを扱う場合は、この値を増やしてください。
* <b>`Default`</b>: `30.0` - `use_stainless_server` (bool): より高い型安全性、自動リトライ、改善されたエラー処理を備えた、Stainless 生成の HTTP クライアントを使用します。これは実験的な機能であり、将来のバージョンではデフォルトになる可能性があります。
* <b>`Default`</b>: `False` - `use_calls_complete` (bool): 開始/終了を個別にリクエストする代わりに、完了した Call データ (開始と終了) を 1 つのリクエストにまとめて送信する、最適化された書き込みパスを使用します。これによりサーバー負荷が軽減され、特に短時間で終了する Ops でパフォーマンスが向上します。
* <b>`Default`</b>: `True`
* <b>`autopatch_settings`</b>:  (非推奨) autopatch インテグレーションの設定です。代わりに、明示的にパッチを適用してください。
* <b>`postprocess_inputs`</b>: このクライアントによってトレースされるすべての op の入力に適用される関数。
* <b>`postprocess_output`</b>: このクライアントがトレースする各 op の出力に適用される関数。
* <b>`attributes`</b>: このクライアントによって生成されるすべての trace に適用される属性の辞書。
  **戻り値:**
  Weave クライアント。

***

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

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

```python theme={null}
link_prompt_to_registry(
    prompt: 'LinkablePrompt',
    target_path: 'str',
    aliases: 'Sequence[str] | None' = None
) → LinkAssetToRegistryRes
```

公開済みのpromptバージョンをRegistryにリンクします。

**引数:**

* <b>`prompt`</b>: 公開済みのprompt、`ObjectRef`、または完全修飾された weave ///... URI string。

* <b>`target_path`</b>: `<registry_project>/<portfolio_name>` 形式のRegistryの宛先パス。例: `wandb-registry-prompts/my-prompt-collection`。

* <b>`aliases`</b>: 作成されるRegistryバージョンに付与するオプションのエイリアス。
  **戻り値:**

* <b>`LinkAssetToRegistryRes`</b>: registry-link endpoint からのパース済みレスポンス。

***

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

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

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

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

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

***

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

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

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

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

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

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/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&#95;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&#95;current&#95;call()` でアクセスできます。False の場合、call はログされますが、call スタックには追加されません。デフォルトは True です。
* <b>`exception`</b> (BaseException | None):  オペレーションが失敗した場合にログする省略可能な例外です。デフォルトは None です。

**戻り値:**

* <b>`Call`</b>:  完全な トレース 情報を含む、作成および完了済みの Call オブジェクトです。

**例:**
基本的な使用方法:

````python theme={null}
import weave
    >>> weave.init('my-project')
    >>> call = weave.log_call(
    ...     op="my_function",
    ...     inputs={"x": 5, "y": 10},
    ...     output=15
    ... )

    Logging with attributes and display name:
    >>> 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"
    ... )

    Logging a failed operation:
    >>> try:
    ...     result = risky_operation()
    ... except Exception as e:
    ...     call = weave.log_call(
    ...         op="risky_operation",
    ...         inputs={},
    ...         output=None,
    ...         exception=e
    ...     )

    Nesting calls:
    >>> parent_call = weave.log_call("parent", {"input": 1}, 2)
    >>> child_call = weave.log_call(
    ...     "child",
    ...     {"input": 2},
    ...     4,
    ...     parent=parent_call
    ... )

    Logging without adding to call stack:
    >>> 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.42/weave/session/session.py#L1166" />

### <kbd>function</kbd> `log_session`

```python
log_session(
    turns: 'list[Turn]',
    session_id: 'str' = '',
    session_name: 'str' = '',
    agent_name: 'str' = '',
    model: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False
) → LogResult
````

命令型で完全な セッション を出力します。

各 Turn の `.spans` 属性には、その子 スパン が含まれます。空の場合は `session_id` を自動生成します。デフォルトでは、各 turn はそれぞれ独自の OTel トレース を持ちます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L1085" />

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

```python theme={null}
log_turn(
    session_id: 'str',
    agent_name: 'str' = '',
    session_name: 'str' = '',
    model: 'str' = '',
    messages: 'list[Message] | None' = None,
    spans: 'list[LLM | Tool | SubAgent] | None' = None,
    started_at: 'datetime | None' = None,
    ended_at: 'datetime | None' = None,
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False
) → LogResult
```

命令的に 1 つの turn とその子 スパン を OTel に送出します。

コンテキストマネージャーを使用できない場合 (ステートレスなコンテナー、コールバック、キューワーカー) に使用します。渡す各子 スパン には `started_at` / `ended_at` を設定しておく必要があります。送出される OTel スパン の Timestamp は、これらのフィールドから取得されます。turn 自身で値が指定されていない場合は、最も早い/遅い子の Timestamp が使用され、それもない場合は `now()` にフォールバックします。

***

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

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

```python theme={null}
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.42/weave/trace/urls.py#L14" />

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

```python theme={null}
otel_traces_endpoint(base_url: str | None = None) → str
```

Weave GenAI トレース取り込み用の完全な OTLP HTTP エンドポイント URL を返します。

外部の呼び出し元 (たとえば、BatchSpanProcessor がエクスポートを暗黙的に破棄することに任せる前に、取り込みエンドポイントに到達可能かどうかを検証したい起動時プローブなど) は、URL を手作業で組み立てるのではなく、これを呼び出してください。このパスは SDK が管理しており、変更される可能性があります。

* <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 にすぐ表示する必要がある場合に便利です。
  **引数:**

***

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

### <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>`base_url`</b>: トレースサーバーのベース URL。デフォルトは `weave_trace_server_url()` です。
  **引数:**

* <b>`obj`</b>: 保存してバージョン管理するオブジェクト。

* <b>`name`</b>: オブジェクトの保存時に使用する名。

* <b>`tags`</b>: 公開されたオブジェクトバージョンに追加する任意の タグ のリスト。

* <b>`aliases`</b>: 公開されたオブジェクトバージョンに設定する任意の エイリアス のリスト。
  **戻り値:**
  保存されたオブジェクトへの Weave Ref。

***

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

### <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.42/weave/trace/api.py#L318" />

### <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.42/weave/trace/api.py#L280" />

### <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.42/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.42/weave/trace/api.py#L306" />

### <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.42/weave/trace/api.py#L480" />

### <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.42/weave/session/session.py#L903" />

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

```python theme={null}
start_llm(
    model: 'str' = '',
    provider_name: 'str' = '',
    system_instructions: 'list[str] | None' = None
) → LLM
```

LLM call を作成して有効化します。利用可能であれば現在の turn を使用します。

アクティブな turn がない場合は、切り離された状態の LLM (contextvar は設定されません) を返します。

`provider_name` は明示的に渡してください。SDK はモデル ID からこれを推論しません。接頭辞ベースの推測では、ユーザーが Fine-tune したモデル (例: `text-...` という名前のモデル) を誤って判定し、将来のモデル名に関する前提を telemetry に組み込んでしまうため、事後に修正するコストが高くなります。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L857" />

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

```python theme={null}
start_session(
    agent_name: 'str' = '',
    model: 'str' = '',
    session_id: 'str' = '',
    session_name: 'str' = '',
    include_content: 'bool' = True,
    continue_parent_trace: 'bool' = False
) → Session
```

セッションを作成して有効化します。モジュール間でアクセスするための contextvar を設定します。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L943" />

### <kbd>function</kbd> `start_subagent`

```python theme={null}
start_subagent(name: 'str', model: 'str' = '') → SubAgent
```

サブエージェント呼び出し用のスパンを作成します。

SubAgent の OTel スパンは、OTel コンテキスト内で現在アクティブなスパンの子として自動的に設定されます。通常、Turn スパンがアクティブであれば、その子になります。形は `start_tool` と同様で、親子関係の伝播は OTel コンテキストが処理するため、明示的な委譲は不要です。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L932" />

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

```python theme={null}
start_tool(name: 'str', arguments: 'str' = '', tool_call_id: 'str' = '') → Tool
```

ツール実行 スパン を作成します。

Tool の OTel スパン は、OTel コンテキスト内の現在の スパン の子として自動的に設定されます。通常、アクティブな Turn スパン がある場合は、その子になります。turn を明示的に委譲する必要はありません。親子関係の伝播は Session SDK の contextvars ではなく、OTel コンテキストを通じて行われます。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/session/session.py#L879" />

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

```python theme={null}
start_turn(
    user_message: 'str' = '',
    model: 'str' = '',
    agent_name: 'str' = ''
) → Turn
```

turn を作成してアクティブ化します。利用可能な場合は、現在のセッションを使用します。

アクティブなセッションがない場合は、contextvar に設定されない、切り離された Turn を返します。つまり、`get_current_turn()` は None を返します。contextvar ベースでモジュール間アクセスを行う必要がある場合は、代わりに `session.start_turn()` を使用してください。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/../../../../weave/trace/api/thread#L563" />

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

```python theme={null}
thread(
    thread_id: 'str | object | None' = <object object at 0x7f1615fc8990>
) → 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` の場合は、スレッドの tracking が無効化されます。
  **返される値:**

* <b>`ThreadContext`</b>: `thread&#95;id` と現在の `turn&#95;id` にアクセスできるオブジェクト。

***

<SourceLink url="https://github.com/wandb/weave/blob/v0.52.42/weave/integrations/wandb/wandb.py#L9" />

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

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