Closed monaxu1 closed 1 year ago
Are you using AskUserMessage
in either cl.on_chat_start
or cl.on_message
?
It's with @cl.on_chat_start
This is the code of chainlit hello
:
# This is a simple example of a chainlit app.
from chainlit import AskUserMessage, Message, on_chat_start
@on_chat_start
async def main():
res = await AskUserMessage(content="What is your name?", timeout=30).send()
if res:
await Message(
content=f"Your name is: {res['content']}.\nChainlit installation is working!\nYou can now start building your own chainlit apps!",
).send()
Both this code and chainlit hello
works on my end, can you confirm?
Actually, I'm using it in a function that is called by the main fun with cl.on_chat_start
async def async_ask_question(question: str) -> str:
print("Async: Asking question")
time_start = time.time()
res = await cl.AskUserMessage(content=question, timeout=60).send()
time_end = time.time()
print(f"Async: Time taken (secs): {time_end - time_start}")
if res:
return res["content"]
else:
return "No response"
@cl.on_chat_start
async def on_chat_start():
msg = cl.Message(content="Setting up model...")
await msg.send()
# Instantiate the agent for that user session
agent = build_qa_pipeline(
llm_model_name=constants.LLM_MODEL_NAME,
ask_question_fn=async_ask_question,
)
# Let the user know that the system is ready
msg.content = "Model set up. You can now ask questions!"
await msg.update()
# Store the agent in the user session
cl.user_session.set("llm_agent", agent)
does chainlit hello
work on your end?
Version: chainlit==0.6.2
Problem: Time taken to get the response from AskUserMessage is always the full timeout time (60 secs).