A simple Python-based Telegram bot that uses a locally running Large Language Model (LLM) to answer your questions. It's built with aiogram and uses llama-cpp-python to run an OpenAI-compatible server out of the box.
- Run Locally: All processing happens on your machine. The internet is only needed for the Telegram Bot API.
- Easy to Start: A
Makefilehelps you set up and run the project with just a few commands. - GGUF Support: Works with models in the popular GGUF format.
- Context-Aware: Remembers the last few messages in a conversation.
- Async Powered: Built with
asynciofor better performance. - GPU Acceleration: Optional support for NVIDIA (CUDA) and Apple Silicon (Metal) GPUs.
git clone https://github.com/adjacentai/localaichat.git
cd localaichatJust run this command:
make setupIt will create a virtual environment in the .venv folder and install all the required libraries from requirements.txt.
Copy the example file to create your own configuration:
cp env.example .envNow, open the .env file in a text editor and fill in the following:
BOT_TOKEN: Your Telegram bot token. You can get one from @BotFather.MODEL_PATH: The path to your model file.
This project needs a model in the .gguf format. You can download a suitable model from Hugging Face.
We recommend using models designed for chat or instructions, like Hermes-2-Pro-Llama-3-8B-GGUF.
After downloading the model:
- Create a
modelsfolder in the project's root directory. - Place the model file (e.g.,
Hermes-2-Pro-Llama-3-8B-Q4_K_M.gguf) inside themodelsfolder. - Make sure the
MODEL_PATHin your.envfile is correct (e.g.,models/your_model_name.gguf).
make runThis command starts both the AI server and the Telegram bot. You can now open a chat with your bot in Telegram and start talking!
If you have a supported GPU, you can make the model run faster.
-
For NVIDIA (CUDA): Uncomment the line
CMAKE_ARGS="-DGGML_CUDA=on"in theMakefileand runmake setupagain. You need to have the NVIDIA CUDA Toolkit installed. -
For Apple Silicon (Metal): Metal support is usually enabled by default. If it's not working, uncomment
CMAKE_ARGS="-DLLAMA_METAL=on"in theMakefileand runmake setupagain to reinstall dependencies.