Exemplo n.º 1
0
async def ai_chat(session: CommandSession):
    message = session.get('message', prompt=expr(e.I_AM_READY))

    ctx_id = context_id(session.event)

    tmp_msg = Message(message)
    text = tmp_msg.extract_plain_text()

    # call ai_chat api
    reply = await tencent_ai.chat(text, ctx_id)
    logger.debug(f'Got AI reply: {reply}')

    if reply:
        session.finish(escape(reply))
    else:
        session.finish(expr(e.I_DONT_UNDERSTAND))
def _extract_text(arg: Message_T) -> str:
    """Extract all plain text segments from a message-like object."""
    arg_as_msg = Message(arg)
    return arg_as_msg.extract_plain_text()