def chat_response_to_completion_response(
    chat_response: ChatResponse,
) -> CompletionResponse:
    """Convert a chat response to a completion response."""
    additional_kwargs = chat_response.message.additional_kwargs
    additional_kwargs.update(chat_response.additional_kwargs)

    return CompletionResponse(
        text=chat_response.message.content or "",
        additional_kwargs=additional_kwargs,
        raw=chat_response.raw,
    )
Convert a chat response to a completion response.
llama-index-core/llama_index/core/base/llms/generic_utils.py