MCPcopy
hub / github.com/openai/openai-python / extract_files

Function extract_files

src/openai/_utils/_utils.py:41–62  ·  view source on GitHub ↗

Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', ' ', 'data']. ``array_format`` controls how `` `` segments contribute to the emitted field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"

(
    # TODO: this needs to take Dict but variance issues.....
    # create protocol type ?
    query: Mapping[str, object],
    *,
    paths: Sequence[Sequence[str]],
    array_format: ArrayFormat = "brackets",
)

Source from the content-addressed store, hash-verified

39
40
41def extract_files(
42 # TODO: this needs to take Dict but variance issues.....
43 # create protocol type ?
44 query: Mapping[str, object],
45 *,
46 paths: Sequence[Sequence[str]],
47 array_format: ArrayFormat = "brackets",
48) -> list[tuple[str, FileTypes]]:
49 """Recursively extract files from the given dictionary based on specified paths.
50
51 A path may look like this ['foo', 'files', '<array>', 'data'].
52
53 ``array_format`` controls how ``<array>`` segments contribute to the emitted
54 field name. Supported values: ``"brackets"`` (``foo[]``), ``"repeat"`` and
55 ``"comma"`` (``foo``), ``"indices"`` (``foo[0]``, ``foo[1]``).
56
57 Note: this mutates the given dictionary.
58 """
59 files: list[tuple[str, FileTypes]] = []
60 for path in paths:
61 files.extend(_extract_items(query, path, index=0, flattened_key=None, array_format=array_format))
62 return files
63
64
65def _array_suffix(array_format: ArrayFormat, array_index: int) -> str:

Calls 2

_extract_itemsFunction · 0.85
extendMethod · 0.45