This documentation covers two methods for setting or renaming the author of a message to display more friendly author names in the UI: the author_rename decorator and the Message author specification at message creation.

Method 1: author_rename

Useful for renaming the author of a message dynamically during the message handling process.

Parameters

orig_author
str
required

The original author name.

Returns

author
str
required

The renamed author

Usage

from langchain import OpenAI, LLMMathChain
import chainlit as cl


@cl.author_rename
def rename(orig_author: str):
    rename_dict = {"LLMMathChain": "Albert Einstein", "Chatbot": "Assistant"}
    return rename_dict.get(orig_author, orig_author)


@cl.on_message
async def main(message: cl.Message):
    llm = OpenAI(temperature=0)
    llm_math = LLMMathChain.from_llm(llm=llm)
    res = await llm_math.acall(message.content, callbacks=[cl.AsyncLangchainCallbackHandler()])

    await cl.Message(content="Hello").send()

Method 2: Message author

Allows for naming the author of a message at the moment of the message creation.

Usage

You can specify the author directly when creating a new message object:

from langchain import OpenAI, LLMMathChain
import chainlit as cl

@cl.on_message
async def main(message: cl.Message):
    llm = OpenAI(temperature=0)
    llm_math = LLMMathChain.from_llm(llm=llm)
    res = await llm_math.acall(message.content, callbacks=[cl.AsyncLangchainCallbackHandler()])

    # Specify the author at message creation
    response_message = cl.Message(content="Hello", author="NewChatBotName")
    await response_message.send()