Skip to content

YaroslavSl/TelegramAiAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proof-of-Reading Telegram Agent

Telegram bot that proofreads your English text using a local LLaMA model (via an HTTP API such as Ollama) and sends back corrected text plus a short explanation of the changes.

Author: Yaroslav Slipchuk LinkedIn

1. Prerequisites

  • Node.js: v18+ recommended.
  • Telegram account to create a bot via BotFather.
  • Local LLaMA server:
    • Easiest option: install Ollama and pull a LLaMA model, for example:
      • ollama pull llama3
      • This will expose an HTTP API at http://localhost:11434 by default.

2. Create a Telegram bot

  1. Open Telegram and start a chat with @BotFather.
  2. Send /newbot and follow the prompts.
  3. Copy the bot token you receive; you will need it as TELEGRAM_BOT_TOKEN.

3. Install dependencies

From the project root:

npm install

4. Configuration

Create a .env file in the project root with at least:

TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here

# Base URL for your local LLaMA server (Ollama by default)
LLAMA_BASE_URL=http://localhost:11434

# Model name as known by your local LLaMA server
# For Ollama typical options: llama3, llama3.1, llama3.2, etc.
LLAMA_MODEL=llama3

# Lower = more deterministic, higher = more creative
LLAMA_TEMPERATURE=0.2

Adjust these values as needed (for example, if your LLaMA server runs on a different port or with another model name).

5. Running a local LLaMA (Ollama example)

  1. Install Ollama from their website (https://ollama.com).
  2. Pull a LLaMA model:
ollama pull llama3
  1. Ensure the Ollama service is running. On most systems it starts automatically and listens on http://localhost:11434.

6. Run the bot

Development mode (TypeScript directly):

npm run dev

Or build and run:

npm run build
npm start

You should see a log line:

Telegram proofreading bot is running.

Now open Telegram, find your bot (the username you set in BotFather), and start chatting.

7. Usage

  • Send any English text to the bot.
    • The bot calls the local LLaMA model with a system prompt that asks for:
      • A corrected version of your text, and
      • A short explanation of the main changes.
    • The reply includes:
      • A code block with the corrected text.
      • An explanation section underneath.
  • Alternatively, reply to a specific message with /proof to proofread only that message.

8. How it talks to LLaMA

  • The code assumes a chat-style HTTP API similar to Ollama:
    • POST /api/chat on LLAMA_BASE_URL.
    • Request body includes:
      • model: the model name (e.g. llama3).
      • messages: array with system and user messages.
      • temperature: controlled by LLAMA_TEMPERATURE.
  • The model is instructed to respond with pure JSON:
{
  "corrected": "corrected full text here",
  "explanation": "short bullet-style explanation of the main changes"
}
  • If parsing fails, the bot falls back to returning the raw text from the model as the corrected version.

9. Where to customize behavior

  • Prompting / style: update the system prompt in src/llamaClient.ts.
  • Bot UX: customize commands and messages in src/bot.ts.
  • Model / server: change default values in src/config/env.ts or via your .env file.

10. Example

Example

About

TelegramAiAgent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors