MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / docs

Method docs

docling/datamodel/document.py:235–271  ·  view source on GitHub ↗
(
        self, format_options: Dict[InputFormat, "FormatOption"]
    )

Source from the content-addressed store, hash-verified

233 limits: Optional[DocumentLimits] = DocumentLimits()
234
235 def docs(
236 self, format_options: Dict[InputFormat, "FormatOption"]
237 ) -> Iterable[InputDocument]:
238 for item in self.path_or_stream_iterator:
239 obj = (
240 resolve_source_to_stream(item, self.headers)
241 if isinstance(item, str)
242 else item
243 )
244 format = self._guess_format(obj)
245 backend: Type[AbstractDocumentBackend]
246 if format not in format_options.keys():
247 _log.error(
248 f"Input document {obj.name} does not match any allowed format."
249 )
250 backend = _DummyBackend
251 else:
252 backend = format_options[format].backend
253
254 if isinstance(obj, Path):
255 yield InputDocument(
256 path_or_stream=obj,
257 format=format, # type: ignore[arg-type]
258 filename=obj.name,
259 limits=self.limits,
260 backend=backend,
261 )
262 elif isinstance(obj, DocumentStream):
263 yield InputDocument(
264 path_or_stream=obj.stream,
265 format=format, # type: ignore[arg-type]
266 filename=obj.name,
267 limits=self.limits,
268 backend=backend,
269 )
270 else:
271 raise RuntimeError(f"Unexpected obj type in iterator: {type(obj)}")
272
273 def _guess_format(self, obj: Union[Path, DocumentStream]) -> Optional[InputFormat]:
274 content = b"" # empty binary blob

Callers 1

_convertMethod · 0.45

Calls 2

_guess_formatMethod · 0.95
InputDocumentClass · 0.70

Tested by

no test coverage detected