Skip to content

Georglider/CloudflareChatAIBot

Repository files navigation

Template: CloudflareChatAIBot

Deploy with Workers

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

Overview

This project is a telegram bot which provides interaction with various text generation models supported by Cloudflare Workers AI

Features

  • 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

Prerequisites

Variables

Required variables

Variables for Settings

  • 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

Enabling the bot

Assuming that you have deployed this project using Cloudflare Workers and configured variables from the previous step

  1. Initialize database using npx wrangler d1 execute cloudflarechataibot --remote --file=./data/schema.sql
  2. Go to your Cloudflare Worker's link
  3. Click "Admin panel" button on the top right of the page
  4. Paste in WEBHOOK_SECRET's content
  5. Click on "Set webhook" button
  6. You can now use the bot in Telegram

Bot commands

  • /new - Allows user to start new conversation
  • /llm [name] - Allows user to switch llm

About

ChatAI Bot for Telegram built on Cloudflare Workers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published