def build_chat_request(
    stream: bool, messages: Sequence[ChatMessage], **kwargs: Any
) -> ChatRequest:
    """
    Construct a ChatRequest.

    :param messages: The chat message list.
    :param stream: Indicate whether to respond in stream or not.
    :return: The ChatResponse object.
    """
    request = ChatRequest(messages=[], stream=stream)
    for message in messages:
        if message.role == MessageRole.USER:
            msg = ChatMsg(role="user", content=message.content)
            request.messages.append(msg)
        elif message.role == MessageRole.ASSISTANT:
            msg = ChatMsg(role="assistant", content=message.content)
            request.messages.append(msg)
        elif message.role == MessageRole.SYSTEM:
            request.system = message.content
        else:
            raise NotImplementedError(
                f"The message role {message.role} is not supported."
            )
    return request

    Construct a ChatRequest.

    :param messages: The chat message list.
    :param stream: Indicate whether to respond in stream or not.
    :return: The ChatResponse object.
    
llama-index-integrations/llms/llama-index-llms-qianfan/llama_index/llms/qianfan/base.py