yell0w4x / valery

Telegram bot assistant and english tutor based on Meta's LLAMA.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Valery: Llama based telegram bot

Valery

@ValeryAIBot

Three modes are available.

  • English tutor
  • General assistant
  • Code assistant

General assistant allows to setup timers in natural language like 'Remind me to turn off the stove in 20 minutes'. When timer is fired bot will send you a message containing text with reminded matter.

To run own instance one needs to create telegram bot. Obtain https://www.anyscale.com/platform and https://deepgram.com API token if speech recognition is necessary. And put them into ./config/prod.env. See ./config/test.env.example.

VALERY_TELEGRAM_TOKEN=...
VALERY_MONGODB_URI=mongodb://mongo-db-url
VALERY_ANYSCALE_TOKEN=...
VALERY_DEEPGRAM_TOKEN=...

Deploy to fly.io

One can deploy to fly.io easily. First deploy mongo instance by using this repo https://github.com/yell0w4x/fly-mongo. Then use the deployed mongo instance name in mongo url variable as follows.

VALERY_MONGODB_URI=mongodb://your-fly-mongo-instance.internal:27017/valery?uuidRepresentation=standard

Then deploy your bot instance via deploy script.

$ ./deploy --help
Valery bot

Fly.io based Valery bot deploy script. Fly.io CLI is required.

Usage:
    ./deploy [OPTIONS]

Options:
    --new               Launch new application using fly.toml template
    --app APP           Application name to use for deploy. Overrides one in toml file
    --envs              .env file to expose inside app container (default: prod.env)
    --image             Docker image to use as base for the app (default: python:3.11-bookworm)
    --allocate-ips      Allocate ip addresses on launch
    --debug             Set bash 'x' option
    --help              Show help message

Examples:
    Deploy new app.
    
        ./deploy --new --app mybot

    Redeploy. 
        
        ./deploy

Note:
    This script allocates shared ipv4 and ipv6 addresses that cost nothing
    Dedicated ipv4 address costs $2/month

Run on prem in docker

Use run script. Remember to provide correct config/prod.env.

$ ./run --help
Valery bot

Run on this machine within specified environment

Usage:
    ./run [OPTIONS]

Options:
    --envs        .env file to expose inside app container (default: test.env)
    --image       Docker image to use as base for the app (default: python:3.11-bookworm)
    --detach      Detach from containers
    --stop        Stop containers
    --remove      Remove containers on stop. If no --stop given and attached to containers.
                  After containers stopped they are removed. 
    --debug       Set bash 'x' option
    --help        Show help message

Run tests

To run tests one needs a telegram bot and a pyrogram session. To obtain pyrogram session use e2e-tests/obtain_pyrogram_session.py.

$ python e2e-tests/obtain_pyrogram_session.py --help
usage: obtain_pyrogram_session.py [-h] --session-name SESSION_NAME [--api-id API_ID] [--api-hash API_HASH]

options:
  -h, --help            show this help message and exit
  --session-name SESSION_NAME
                        Arbitrary session name
  --api-id API_ID       Telegram API id
  --api-hash API_HASH   Telegram API hash

It will create a file .session. Put it inside e2e-tests/src folder and run tests as follows.

VALERY_BOT_CHAT_ID=@YourTelegramBot VALERY_BOT_SESSION_NAME=YourPyrogramSessionName ./run-tests

About

Telegram bot assistant and english tutor based on Meta's LLAMA.

License:MIT License


Languages

Language:Python 84.1%Language:Shell 11.9%Language:Dockerfile 2.8%Language:JavaScript 1.3%