Note: If you Deploy with Workers instead of using wrangler, please make sure your CLOUDFLARE_API_TOKEN contains 'Account:Workers AI:Read', 'User:Memberships:Read', 'User:User Details:Read', 'Account:D1:Read', 'Account:D1:Write' permissions
This project is a telegram bot which provides interaction with various text generation models supported by Cloudflare Workers AI
- Select the text generation model to interact with
- Toggle LLM response streaming on/off
- Handle streaming and non-streaming LLM responses for Telegram chat
- Parse and display markdown in LLM responses
- Create and switch between the conversations with AI
- Telegram Bot's API Token
- Cloudflare Account: Required for using Workers AI models and D1 and deploying the project on Cloudflare Workers
- WEBHOOK_SECRET
- DASHBOARD_SECRET: Password in order for you to control the bot via dashboard
- BOT_TOKEN: Bot API token from BotFather
- CLOUDFLARE_ACCOUNT_ID: Required for getting LLM model list
- CLOUDFLARE_API_TOKEN: (required permission: Workers AI:Read) Required for getting LLM model list
- DEFAULT_AI_MODEL: (format: @cf/meta/llama-3-8b-instruct)
- DEV_SERVER_URL: (format: "https://example.com/"); Can be used for local development
- MESSAGE_STREAMING_INITIAL_COOLDOWN: (default: 2000); How quick can streaming message be sent in ms
- MESSAGE_STREAMING_COOLDOWN: (default: 3500); How quick can streaming message be updated in ms
- MESSAGE_STREAMING_ENABLED: (default: true); Is message streaming enabled
- WHITELIST_ENABLED: (default: false); Is Telegram user whitelist enabled
- WHITELIST_ENTITIES: (format: 1,2); Telegram UserIDs that can use the bot
Assuming that you have deployed this project using Cloudflare Workers and configured variables from the previous step
- Initialize database using
npx wrangler d1 execute cloudflarechataibot --remote --file=./data/schema.sql
- Go to your Cloudflare Worker's link
- Click "Admin panel" button on the top right of the page
- Paste in WEBHOOK_SECRET's content
- Click on "Set webhook" button
- You can now use the bot in Telegram
- /new - Allows user to start new conversation
- /llm [name] - Allows user to switch llm