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

Method register_bytes

utils/attachments.py:142–178  ·  view source on GitHub ↗

Register an in-memory payload as an attachment.

(
        self,
        data: bytes | bytearray,
        *,
        kind: MessageBlockType = MessageBlockType.FILE,
        mime_type: Optional[str] = None,
        display_name: Optional[str] = None,
        attachment_id: Optional[str] = None,
        description: Optional[str] = None,
        extra: Optional[Dict[str, Any]] = None,
        persist: bool = True,
    )

Source from the content-addressed store, hash-verified

140 return record
141
142 def register_bytes(
143 self,
144 data: bytes | bytearray,
145 *,
146 kind: MessageBlockType = MessageBlockType.FILE,
147 mime_type: Optional[str] = None,
148 display_name: Optional[str] = None,
149 attachment_id: Optional[str] = None,
150 description: Optional[str] = None,
151 extra: Optional[Dict[str, Any]] = None,
152 persist: bool = True,
153 ) -> AttachmentRecord:
154 """Register an in-memory payload as an attachment."""
155
156 if not isinstance(data, (bytes, bytearray)):
157 raise TypeError("register_bytes expects bytes or bytearray data")
158
159 attachment_id = attachment_id or uuid.uuid4().hex
160 filename = display_name or _default_filename_for_mime(mime_type)
161
162 target_dir = self.root / attachment_id
163 target_dir.mkdir(parents=True, exist_ok=True)
164 target_path = target_dir / filename
165 with target_path.open("wb") as handle:
166 handle.write(bytes(data))
167
168 return self.register_file(
169 target_path,
170 kind=kind,
171 display_name=display_name or filename,
172 mime_type=mime_type,
173 attachment_id=attachment_id,
174 copy_file=False,
175 description=description,
176 extra=extra,
177 persist=persist,
178 )
179
180 def register_remote_file(
181 self,

Callers 1

Calls 2

register_fileMethod · 0.95

Tested by

no test coverage detected