def haystack_doc_to_string()

in function_app/src/helpers/common.py [0:0]


def haystack_doc_to_string(doc: Document) -> str:
    """
    Converts a Haystack Document (which can contains different types of
    content) to a simple string.

    :param doc:
        The Haystack Document to convert.

    :return:
        A string representation of the document.
    """
    if doc.content is not None:
        return doc.content
    if doc.dataframe is not None:
        return doc.dataframe.to_markdown()
    raise ValueError("Document has no content or dataframe, cannot convert to string.")