Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ai/types/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class MessageBundle(pydantic.BaseModel):


class _ModelInputUnset:
pass
def __reduce__(self) -> str:
return "MODEL_INPUT_UNSET"
Comment on lines +205 to +206

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I don't understand this.

We should consider using the new sentinel feature though



MODEL_INPUT_UNSET: Any = _ModelInputUnset()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha: "If a string is returned, the string should be interpreted as the name of a global variable.", from __reduce__ docs...

Expand Down
16 changes: 16 additions & 0 deletions tests/types/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from __future__ import annotations

import asyncio
import copy
import dataclasses
import pickle
import random
import subprocess
import sys
Expand Down Expand Up @@ -569,3 +571,17 @@ async def build() -> str:

assert await build() == expected
assert await build() == expected


def test_tool_message_equals_its_pickle_and_deep_copy() -> None:
message = messages.Message(
role="tool",
parts=[
messages.ToolResultPart(
tool_call_id="tc-1", tool_name="lookup", result={"a": 1}
)
],
)
assert pickle.loads(pickle.dumps(message)) == message
assert copy.deepcopy(message) == message
assert message.model_copy(deep=True) == message
Loading