def _make_chunk()

in google/generativeai/types/retriever_types.py [0:0]


    def _make_chunk(self, chunk: ChunkOptions) -> protos.Chunk:
        # del self
        if isinstance(chunk, protos.Chunk):
            return protos.Chunk(chunk)
        elif isinstance(chunk, str):
            return protos.Chunk(data={"string_value": chunk})
        elif isinstance(chunk, tuple):
            if len(chunk) == 2:
                name, data = chunk  # pytype: disable=bad-unpacking
                custom_metadata = None
            elif len(chunk) == 3:
                name, data, custom_metadata = chunk  # pytype: disable=bad-unpacking
            else:
                raise ValueError(
                    f"Tuples should have length 2 or 3, got length: {len(chunk)}\n"
                    f"value: {chunk}"
                )

            return protos.Chunk(
                name=name,
                data={"string_value": data},
                custom_metadata=custom_metadata,
            )
        elif isinstance(chunk, Mapping):
            if isinstance(chunk["data"], str):
                chunk = dict(chunk)
                chunk["data"] = {"string_value": chunk["data"]}
            return protos.Chunk(chunk)
        else:
            raise TypeError(
                f"Invalid input: Could not convert instance of type '{type(chunk).__name__}' to a chunk. Received value: '{chunk}'."
            )