1991.1.15 • Published 10 days ago

halbot v1991.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
10 days ago

🤖️ halbot

MIT licensed Node.js Package

Just another ChatGPT / Gemini / Mistral (by ollama) Telegram bob, which is simple design, easy to use, extendable and fun.

Live demo, click to watch on YouTube:

Features

  • Telegram Bot (Telegram Bot token required)
  • ChatGPT (OpenAI API key required)
  • Gemini (Google Vertex AI credentials required)
  • Mistral (Install Ollama and enable Mistral)
  • Speech-to-Text (OpenAI or Google Cloud API key required, or your own engine)
  • Text-to-Speech (OpenAI or Google Cloud API key required, or your own engine)
  • Text-to-Image by DALL·E (OpenAI API key required, or your own engine)
  • OCR/OBJECT_DETECT (Google Cloud API key required, or your own engine)
  • Feeding webpage and YouTube to enhance your prompt
  • Custom prompt and 🧠 Awesome ChatGPT Prompts at your fingertips
  • Support private and public mode, with multiple authenticate methods.
  • Middleware style workflow, easy to extend.
  • Built-in support parsing webpages, YouTube videos, PDFs, images, Office documents, code files, text files...
  • Realtime stream-style response, no more waiting.
  • Markdown rendering for GhatGPT
  • Reference rendering for Bing Chat
  • Code block rendering, developers friendly.
  • ESM from the ground up

Basic usage

Configuration

Make the halbot json config file and put it in this path ~/.halbot.json.

Basic config demo:

{
    "telegramToken": "[[Telegram Bot API Token]]",
    "openaiApiKey": "[[OpenAI API Key]]"
}

All supported configuration fields:

{

    // REQUIRED, string.
    "telegramToken": "[[Telegram Bot API Token]]",

    // Set some of these fields if you need ChatGPT, Whisper, Embedding features.
    // OPTIONAL, string.
    "openaiApiKey": "[[OpenAI API Key]]",
    // OPTIONAL, string.
    "openaiEndpoint": "[[Custom OpenAI API endpoint]]",
    // OPTIONAL, string, default: "gpt-3.5-turbo".
    "chatGptModel": "[[Custom ChatGPT Model ID]]",
    // OPTIONAL, integer, default: 0.
    "chatGptPriority": "[[Custom ChatGPT Priority]]",

    // Set some of these fields if you need to use custom ChatGPT API.
    // OPTIONAL, string.
    "chatGptApiKey": "[[Custom ChatGPT API Key]]",
    // OPTIONAL, string.
    "chatGptEndpoint": "[[Custom ChatGPT API endpoint]]",

    // Set this field if you need Gemini features.
    // OPTIONAL, string.
    "googleCredentials": "[[Google Cloud Credentials]]",
    // OPTIONAL, string.
    "googleProject": "[[Google Cloud Project ID]]",
    // OPTIONAL, string, default: "gemini-pro-vision".
    "geminiModel": "[[Custom Gemini Model ID]]",
    // OPTIONAL, integer, default: 1.
    "geminiPriority": "[[Custom Gemini Priority]]",

    // Set this field if you need Mistral features.
    // OPTIONAL, boolean.
    "mistralEnabled": "[[Enable Mistral hosted by Ollama]]",
    // OPTIONAL, string.
    "mistralEndpoint": "[[Custom Mistral API endpoint]]",
    // OPTIONAL, string, default: "Mistral" (Mistral 7B).
    "mistralModel": "[[Custom Mistral Model ID]]",
    // OPTIONAL, integer, default: 2.
    "mistralPriority": "[[Custom Mistral Priority]]",

    // OPTIONAL, string.
    // Set this field if you need Google's TTS/STT/OCR/OBJECT_DETECT/Embedding.
    "googleApiKey": "[[Google Cloud API Key]]",

    // OPTIONAL, undefined || array of string.
    // To open the bot to PUBLIC, DO NOT set this field;
    // To restrict the bot to PRIVATE, set chat/group/channel ids in this array.
    "private": ["[[CHAT_ID]]", "[[GROUP_ID]]", "[[CHANNEL_ID]]", ...],

    // OPTIONAL, string.
    // Set this field if you want to use a `magic word` to authenticate the bot.
    "magicWord": "[[Your Magic Word here]]",

    // OPTIONAL, string.
    // Use a HOME GROUP to authentication users.
    // Anyone in this group can access the bot.
    "homeGroup": "[[GROUP_ID]]",

    // OPTIONAL, array of enum string.
    // Enum: 'private', 'mention', 'group', 'channel'.
    // Defaule: ['private', 'mention'].
    // By default, it will only reply to `private` chats and group `mention`s.
    // Adding 'group' or 'channel' may cause too much disturbance.
    "chatType": ["mention", "private"],

    // OPTIONAL, string.
    "hello": "[[initial prompt]]",

    // OPTIONAL, string.
    "info": "[[bot description]]",

    // OPTIONAL, string.
    "help": "[[help information]]",

    // OPTIONAL, object.
    // Sessions/conversations storage.
    // support PostgreSQL, MariaDB/MySQL and Redis for now.
    // If omitted, the bot will use memory storage and sync to this file.
    // Example: (Compatibility: https://node-postgres.com/apis/pool)
    "storage": {
        "provider": "POSTGRESQL",
        "host": "[[DATABASE HOST]]",
        "database": "[[DATABASE NAME]]",
        "user": "[[DATABASE USER]]",
        "password": "[[DATABASE PASSWORD]]",
        "vector": true, // REQUIRED
        ...[[OTHER DATABASE OPTIONS]],
    },
    // OR: (Compatibility: https://github.com/sidorares/node-mysql2)
    "storage": {
        "provider": "[["MARIADB" || "MYSQL"]]",
        "host": "[[DATABASE HOST]]",
        "database": "[[DATABASE NAME]]",
        "user": "[[DATABASE USER]]",
        "password": "[[DATABASE PASSWORD]]",
        "charset": "utf8mb4", // REQUIRED
        ...[[OTHER DATABASE OPTIONS]],
    },
    // OR: (Compatibility: https://github.com/luin/ioredis)
    "storage": {
        "provider": "REDIS",
        "host": "[[REDIS HOST]]",
        "password": "[[REDIS PASSWORD]]",
        ...[[OTHER REDIS OPTIONS]],
    },

}

Run it

In peace-of-mind:

$ npx halbot

If you have multible AI engines configed, use '/chatgpt' or '/bing' to switch between them, or you can use '/*' to ask them all at the same time.

Integrate to your project

Install:

$ npm i halbot

Code:

import halbot from 'halbot';

const config = {

    // ...[[ALL THE CONFIG FIELDS SUPPORTED ABOVE]]],

    // OPTIONAL, function.
    // Your own authentication logic.
    // return true if the user is authenticated.
    // return false if the user is not authenticated.
    auth: async (ctx) => {
        // ctx is the `telegraf` context object: https://telegraf.js.org/#context-class
        // It has been extended: https://github.com/Leask/utilitas/blob/master/lib/bot.mjs
        return true;
    },

    // OPTIONAL, object (key renderd as name) or array (name ignored).
    ai: {
        [[aiNameA]]: [[aiConfigA]],
        [[aiNameB]]: [[aiConfigB]],
        // ...
    },

    // OPTIONAL, object.
    // Your own speech-to-text and text-to-speech engine.
    speech: {
        stt: [[sttApi]],
        tts: [[ttsApi]],
    },

    // OPTIONAL, object.
    // Your own computer-vision engine.
    vision: {
        see: [[ocrAndObjectDetectApi]],
        read: [[documentAnnotateApi]],
    },

    // OPTIONAL, object.
    // Your own image-generator engine.
    image: {
        generate: [[textToImageApi]],
    },

    // OPTIONAL, string.
    // Path to your own middlewares.
    // ./skills
    //  |- skill_a.mjs
    //    | const action = async (bot) => {
    //    |     bot.use(async (ctx, next) => {
    //    |         ctx.reply('42');
    //    |         await next();
    //    |     });
    //    | };
    //    |
    //    | export const { run, priority, func } = {
    //    |     run: true,
    //    |     priority: 100,
    //    |     func: action,
    //    | };
    skillPath: [[pathToYourMiddlewares]],

    // OPTIONAL, object.
    // Using customized storage engine.
    // `storage` should Should be compatible with the `Map` interface:
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
    storage: {
        provider: [[POSTGRESQL || MARIADB || MYSQL || REDIS]],
        get: async (key) => { /* Return session object by chatId. */ },
        set: async (key, session) => { /* Save session object by chatId. */ },
        client: { /* Customized database client / pool. */ },
            query: async (topic) => { /* Search history and session by topic. */ },
            upsert: async (event) => { /* Save event for history and session. */ },
        },
    },

    // OPTIONAL, function.
    // Using customized embedding engine for history and session search.
    embedding: async (text) => { /* Return vector embedding of the text. */ },

    // OPTIONAL, array of string.
    // Supported mime types of your vision-enabled AI models.
    // If omitted, bot will use standard OCR and Object Detect to handle images.
    supportedMimeTypes: [...[[mimeTypes]]],

    // OPTIONAL, object.
    // Adding extra commands.
    cmds: {
        [[commandA]]: [[descriptionA]],
        [[commandB]]: [[descriptionB]],
        ...[[OTHER COMMANDS]],
    },

    // OPTIONAL, object.
    // Adding extra configurations
    args: {
        [[argA]]: {
            type: 'string',
            short: [[shortCut]],
            default: [[defaultValue]],
            desc: [[description]],
        },
        [[argB]]: {
            type: 'binary',
            short: [[shortCut]],
            default: [[defaultValue]],
            desc: [[description]],
        },
        ...[[OTHER ARGS]],
    },

};

await halbot(config);

❤️ Become a sponsor to halbot

For $10/month, you can access the official halbot service for a month.

You don't need to pay $20/month for ChatGPT tokens separately.

halbot is stable. It's running on top of the latest GPT-4 model. It has a better user experience than the official web app. You can access halbot from your favourite Telegram apps on your phone, tablet and computer.

Additionally, halbot has a lot of built-in input parsers to maximize the ChatGPT engine's power.

halbot can now parse webpages, YouTube videos, PDFs, images, Office documents, code files, and text files. And other parsers are coming soon.

halbot integrates Text-to-Image service by DALL·E 3. You can ask it to draw what you want.

halbot also supports Text-to-Speech and Speech-to-Text. You can talk to the AI engines to get help with your job.

And remember, you can always use the codes in this repo to build your own halbot instant. This project will keep open source forever.

Foundations

  • halbot uses my other project 🧰 utilitas as the basic framework to handle all the dirty work.
  • halbot uses 🤖 utilitas.alan to communicate with the AI engines.

Contact me

1991.1.15

10 days ago

1991.1.14

11 days ago

1991.1.13

12 days ago

1991.1.12

12 days ago

1991.1.11

3 months ago

1991.1.10

3 months ago

1991.1.9

3 months ago

1991.1.7

4 months ago

1991.1.8

4 months ago

1991.1.5

4 months ago

1991.1.6

4 months ago

1991.1.4

4 months ago

1991.1.2

4 months ago

1990.1.129

4 months ago

1990.1.128

4 months ago

1990.1.127

4 months ago

1991.1.3

4 months ago

1990.1.126

4 months ago

1990.1.125

4 months ago

1990.1.124

4 months ago

1990.1.123

4 months ago

1990.1.122

4 months ago

1990.1.121

4 months ago

1990.1.109

4 months ago

1990.1.108

4 months ago

1990.1.119

4 months ago

1990.1.118

4 months ago

1990.1.117

4 months ago

1990.1.116

4 months ago

1990.1.115

4 months ago

1990.1.114

4 months ago

1990.1.113

4 months ago

1990.1.112

4 months ago

1990.1.111

4 months ago

1990.1.110

4 months ago

1990.1.120

4 months ago

1990.1.107

5 months ago

1990.1.106

5 months ago

1990.1.105

5 months ago

1990.1.104

6 months ago

1990.1.103

6 months ago

1990.1.102

6 months ago

1990.1.101

6 months ago

1990.1.100

6 months ago

1990.1.95

6 months ago

1990.1.96

6 months ago

1990.1.97

6 months ago

1990.1.98

6 months ago

1990.1.99

6 months ago

1990.1.92

6 months ago

1990.1.93

6 months ago

1990.1.94

6 months ago

1990.1.90

9 months ago

1990.1.91

9 months ago

1990.1.85

10 months ago

1990.1.86

10 months ago

1990.1.87

10 months ago

1990.1.88

10 months ago

1990.1.89

9 months ago

1990.1.62

1 year ago

1990.1.63

1 year ago

1990.1.64

1 year ago

1990.1.65

1 year ago

1990.1.66

1 year ago

1990.1.67

1 year ago

1990.1.68

1 year ago

1990.1.69

1 year ago

1990.1.60

1 year ago

1990.1.61

1 year ago

1990.1.59

1 year ago

1990.1.51

1 year ago

1990.1.52

1 year ago

1990.1.53

1 year ago

1990.1.54

1 year ago

1990.1.55

1 year ago

1990.1.56

1 year ago

1990.1.57

1 year ago

1990.1.58

1 year ago

1990.1.50

1 year ago

1990.1.48

1 year ago

1990.1.49

1 year ago

1990.1.40

1 year ago

1990.1.41

1 year ago

1990.1.42

1 year ago

1990.1.43

1 year ago

1990.1.44

1 year ago

1990.1.45

1 year ago

1990.1.46

1 year ago

1990.1.47

1 year ago

1990.1.37

1 year ago

1990.1.38

1 year ago

1990.1.39

1 year ago

1990.1.30

1 year ago

1990.1.31

1 year ago

1990.1.32

1 year ago

1990.1.33

1 year ago

1990.1.34

1 year ago

1990.1.35

1 year ago

1990.1.36

1 year ago

1990.1.27

1 year ago

1990.1.28

1 year ago

1990.1.29

1 year ago

1990.1.84

12 months ago

1990.1.80

1 year ago

1990.1.81

1 year ago

1990.1.82

1 year ago

1990.1.83

12 months ago

1990.1.73

1 year ago

1990.1.74

1 year ago

1990.1.75

1 year ago

1990.1.76

1 year ago

1990.1.77

1 year ago

1990.1.78

1 year ago

1990.1.79

1 year ago

1990.1.70

1 year ago

1990.1.71

1 year ago

1990.1.72

1 year ago

1990.1.26

1 year ago

1990.1.25

1 year ago

1990.1.24

1 year ago

1990.1.23

1 year ago

1990.1.22

1 year ago

1990.1.21

1 year ago

1990.1.20

1 year ago

1990.1.19

1 year ago

1990.1.18

1 year ago

1990.1.17

1 year ago

1990.1.16

1 year ago

1990.1.15

1 year ago

1990.1.14

1 year ago

1990.1.13

1 year ago

1990.1.12

1 year ago

1990.1.11

1 year ago

1990.1.10

1 year ago

1990.1.9

1 year ago

1990.1.8

1 year ago

1990.1.7

1 year ago

1990.1.6

1 year ago

1990.1.5

1 year ago

1990.1.4

1 year ago

1990.1.3

1 year ago

1990.1.2

1 year ago

1989.6.38

1 year ago

1989.6.37

1 year ago

1989.6.36

1 year ago

1989.6.35

1 year ago

1989.6.34

1 year ago

1989.6.33

1 year ago

1989.6.32

1 year ago

1989.6.31

1 year ago

1989.6.30

1 year ago

1989.6.29

1 year ago

1989.6.28

1 year ago

1989.6.27

1 year ago

1989.6.26

1 year ago

1989.6.25

1 year ago

1989.6.24

1 year ago

1989.6.23

1 year ago

1989.6.22

1 year ago

1989.6.21

1 year ago

1989.6.20

1 year ago

1989.6.19

1 year ago

1989.6.18

1 year ago

1989.6.17

1 year ago

1989.6.16

1 year ago

1989.6.15

1 year ago

1989.6.14

1 year ago

1989.6.13

1 year ago

1989.6.12

1 year ago

1989.6.11

1 year ago

1989.6.10

1 year ago

1989.6.9

1 year ago

1989.6.8

1 year ago

1989.6.7

1 year ago

1989.6.6

1 year ago

1989.6.5

1 year ago

1989.6.4

1 year ago