How to Handle Conversation in Chatbot in Python

When you develop a chatbot, sometimes for user experience, you cannot ask your user send messages like commands. For example, we want to build a guess number bot. We want the bot works like this: user: guess bot: From what number? user:: 25 bot: To what number? user: 100 bot: Guess a number between 25 to 100 user: 64 bot: too small user: 91 bot: too large …… user: 83...

July 29, 2021 · 4 min · wancat

How to Redirect Stdout to Streaming Response in Django

Sometimes we need to execute some long tasks at the backend, and the tasks are complicated and error-prone. So we hope users can see the real-time console log. Thus we need to redirect the stdout in our functions to the user’s browser. Given a function like the following. How to see the stdout in real-time in the browser? import time def job(times): for i in range(times): print(f'Task #{i}') time.sleep(1) print('Done') time....

May 25, 2021 · 5 min · wancat