/sector-ai

Telegram interactive chatbot powered by LangChain

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Sector AI Telegram Bot

This repository contains the implementation of the Sector AI Telegram Bot, an advanced chatbot designed to interact with users on Telegram. The secret sauce is LangChain. The bot supports various functionalities, including autoreply decision-making, structured output parsing for polls, multimodal image processing, emoji responses, code generation, and more. Below is a detailed description of all components of this repository.

Installing Ollama

To download and manage the recommended models, you will need to install Ollama. Follow these steps to install Ollama and download the models:

  1. Install Ollama: https://ollama.com/download

  2. Download the recommended models:

    ollama pull llama3.1:8b
    ollama pull llava-llama3:8b

Make sure you have enough storage space and a stable internet connection to download these models.

Recommended Models

  • Llama 3.1
  • Llava Llama 3 (for vision processing)
  • Gemma 2
  • Mistral Nemo
  • Almost anything will work for the basics. However, some models aren't powerful enough for the structured output parsing involved in autoreply, decision, poll, and topic commands.

Features

This project uses the python-telegram-bot library, with various command handlers and message handlers to manage different interactions. Below is a summary of each command:

Introduction (/start)

  • Description: Sends a welcome message introducing the bot and its basic commands.
  • Usage: /start

Generate Response (/chat)

  • Description: Initiates or continues a chat interaction with the user, using AI to generate responses based on the context of the conversation.
  • Usage: /chat [text] (where [text] is the user's input)

Summarize Chat Messages (/summarize)

  • Description: Provides a summary of the current chat messages in context, potentially generated by the AI to quickly grasp the conversation’s essence.
  • Usage: /summarize

Generate Emojis Based on Prompt (/emoji)

  • Description: Creates emojis based on user input or specific prompts related to emotions or themes relevant to the chat.
  • Usage: /emoji [prompt] (where [prompt] is a description of what kind of emoji you want)

Generate a Poll Based on Question or Prompt (/poll)

  • Description: Creates a poll with multiple options based on user input, useful for gathering feedback.
  • Usage: /poll [question] (where [question] is the description of the poll)

Generate a Poll with Chat Related Topics (/topic)

  • Description: Creates a poll where users can vote on topics discussed recently in the chat context.
  • Usage: /topic

Return "True" or "False" Based on Prompt (/decide)

  • Description: Uses AI to decide between two possible outcomes based on user input.
  • Usage: /decide [prompt] (where [prompt] is the question you want decided by the bot)

Generate a Code Block Based on Specification (/code)

  • Description: Generates a code snippet according to specific requirements or inputs provided by the user.
  • Usage: /code [specification] (where [specification] describes what kind of code to generate, e.g., Python function)

Generate Fake Website Based on Specification (/html)

  • Description: Renders a mock HTML website based on given specifications or details from the user.
  • Usage: /html [specification] (where [specification] includes layout and content requirements)

Generate Horrible SVG Image Based on Description (/svg)

  • Description: Creates an SVG graphic according to detailed descriptions provided by users, often with humorous or nonsensical results.
  • Usage: /svg [description] (where [description] can be anything from a simple shape to a complex scene)

Get Current Context Length (/tokens)

  • Description: Checks the current length of the chat context in terms of tokens used, which could be relevant for understanding memory or performance constraints.
  • Usage: /tokens

Toggle Automatic Replies (/autoreply)

  • Description: Enables or disables automatic replies triggered by the LLM decision. When enabled, the bot will automatically respond to user messages and images.
  • Usage: /autoreply to toggle the feature

Reset Chat Context (/clear)

  • Description: Resets the context of the conversation, effectively starting a new chat from scratch.
  • Usage: /clear

View This Model (/model)

  • Description: Displays information about the current AI model being used by the bot.
  • Usage: /model

Set System Prompt (Admin Only) (/system)

  • Description: Allows administrators to set or modify the system prompt that guides the behavior of the AI within the chat context.
  • Usage: /system [prompt] where [prompt] is the new system message you want the bot to follow.

Generate System Prompt (Admin Only) (/characterize)

  • Description: Similar to setting a system prompt but might be used for generating more detailed or specialized instructions for the AI based on specific user requirements.
  • Usage: /characterize [details] where [details] are a thing for the LLM to roleplay as.

Set the Model (Admin Only) (/models)

  • Description: Allows administrators to switch or configure different AI models used by the bot, which can affect response quality and style.

Getting Started

To get started with the Sector AI Telegram Bot, follow these steps:

  1. Clone the repository:

    git clone https://github.com/roryeckel/sector-ai.git
    cd sector-ai
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure the bot:

    • Copy the default_config.json to a new file outside the sector-ai directory (e.g., config.json).
    • Add your Telegram bot token and other configuration settings to the config.json file.
  4. Run the bot:

    • Go back to the parent directory of sector-ai (cd ..) and run the following command to start the bot:
    python -m sector-ai --config config.json

Contributions Welcome