def get_streaming_callbacks(chain: Chain) -> list[Callable]:
    """Get streaming callbacks for a LangChain instance.

    Note: This function might not support all LangChain
    chain and agent types. Please open an issue on GitHub to
    request support for a specific type.

    Args:
        chain: A LangChain instance.
    """
    callbacks = []

    if "source_documents" in chain.output_keys:
        callbacks.append(SourceDocumentsStreamingCallbackHandler())

    if len(set(chain.output_keys) - {"source_documents"}) > 1:
        logger.warning(
            f"""multiple output keys found: {set(chain.output_keys) - {'source_documents'}}.

        Only the first output key will be used for streaming tokens. For more complex API logic, define the endpoint function manually.
        """
        )

    if isinstance(chain, AgentExecutor):
        callbacks.append(FinalTokenStreamingCallbackHandler())
    else:
        callbacks.extend(
            [
                TokenStreamingCallbackHandler(output_key=chain.output_keys[0]),
            ]
        )

    return callbacks
Get streaming callbacks for a LangChain instance.

    Note: This function might not support all LangChain
    chain and agent types. Please open an issue on GitHub to
    request support for a specific type.

    Args:
        chain: A LangChain instance.
    
lanarky/adapters/langchain/utils.py