MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / AttachmentRecord

Class AttachmentRecord

utils/attachments.py:19–56  ·  view source on GitHub ↗

Stores metadata about an attachment tracked inside a workflow run.

Source from the content-addressed store, hash-verified

17
18@dataclass
19class AttachmentRecord:
20 """Stores metadata about an attachment tracked inside a workflow run."""
21
22 ref: AttachmentRef
23 kind: MessageBlockType = MessageBlockType.FILE
24 description: Optional[str] = None
25 extra: Dict[str, Any] = field(default_factory=dict)
26
27 def to_dict(self) -> Dict[str, Any]:
28 return {
29 "ref": self.ref.to_dict(),
30 "kind": self.kind.value,
31 "description": self.description,
32 "extra": self.extra,
33 }
34
35 @classmethod
36 def from_dict(cls, data: Dict[str, Any]) -> "AttachmentRecord":
37 ref_data = data.get("ref") or {}
38 raw_kind = data.get("kind", MessageBlockType.FILE.value)
39 try:
40 kind = MessageBlockType(raw_kind)
41 except ValueError:
42 kind = MessageBlockType.FILE
43 return cls(
44 ref=AttachmentRef.from_dict(ref_data),
45 kind=kind,
46 description=data.get("description"),
47 extra=data.get("extra") or {},
48 )
49
50 def as_message_block(self) -> MessageBlock:
51 """Convert to a MessageBlock referencing this attachment."""
52 return MessageBlock(
53 type=self.kind,
54 attachment=self.ref.copy(),
55 data=dict(self.extra),
56 )
57
58
59class AttachmentStore:

Callers 3

register_fileMethod · 0.85
register_remote_fileMethod · 0.85
ingest_recordMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected