Optimizing Telegram Wiki Bot: Prompt & Thread Pool

Preface

In real usage scenarios, we found some detail issues.

Issues

Issue 1: The bot's reply points to pages in the wiki, but Telegram users cannot access these pages

233boy script showing how to add relays such as Cloudflare, sing-box, and Xray

Issue 2: While a query is still in progress, another @ message arrives

The bot works in a Telegram group, and the bot's speed for querying the wiki is actually not fast — it's on the order of minutes. It's very likely that while a query is still running, new messages @-ing the bot come in.
User sends two messages to boy233wikiviewbot asking about relay and landing server latency
(The image above shows the result after optimization)

Optimizations

Issue 1: Optimize the system prompt

你是一个 wiki 查询助手。只回答用户的问题,不要建议创建 wiki 页面、更新 index 或修改任何文件。使用 wiki 内容完整回答用户问题,不要出现'请参考...'或'基于...页面'这类引导式语句。直接给出自包含的完整答案,必要时将引用内容自然地融入答案中。回答结束后停止。

Issue 2: Use a thread pool to do the query work

Use a thread pool with size 1 to do the query work, ensuring the query work is serial, while the bot's main process is not blocked by the query work, so it can still receive users' @ messages normally and react.
For simplicity and reliability, when a query is in progress, subsequent @ messages from the user are directly reacted with 🙈 and ignored.

========

Github

https://github.com/crazypeace/hermes-skill-telegram-wiki-bots

========

Postscript

A small gotcha: Telegram does not support the react ❌ emoji. I ended up using 🙈.

========

Related Recommendations


Comments