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

Method build_from_file_paths

utils/task_input.py:17–45  ·  view source on GitHub ↗
(
        self,
        prompt: str,
        attachment_paths: Sequence[str],
    )

Source from the content-addressed store, hash-verified

15 self.attachment_store = attachment_store
16
17 def build_from_file_paths(
18 self,
19 prompt: str,
20 attachment_paths: Sequence[str],
21 ) -> Union[str, List[Message]]:
22 if not attachment_paths:
23 return prompt
24
25 blocks: List[MessageBlock] = []
26
27 for raw_path in attachment_paths:
28 file_path = Path(raw_path).expanduser()
29 if not file_path.exists():
30 raise FileNotFoundError(f"Attachment not found: {file_path}")
31 mime_type, _ = mimetypes.guess_type(str(file_path))
32 record = self.attachment_store.register_file(
33 file_path,
34 kind=MessageBlockType.from_mime_type(mime_type),
35 display_name=file_path.name,
36 mime_type=mime_type,
37 extra={
38 "source": "user_upload",
39 "origin": "cli_attachment",
40 "original_path": str(file_path),
41 },
42 )
43 blocks.append(record.as_message_block())
44
45 return self.build_from_blocks(prompt, blocks)
46
47 @staticmethod
48 def build_from_blocks(prompt: str, blocks: Sequence[MessageBlock]) -> List[Message]:

Callers 4

build_task_input_payloadFunction · 0.95
_build_task_inputFunction · 0.95
_build_task_inputMethod · 0.95
_build_task_inputFunction · 0.95

Calls 4

build_from_blocksMethod · 0.95
register_fileMethod · 0.80
from_mime_typeMethod · 0.80
as_message_blockMethod · 0.80

Tested by

no test coverage detected