mudler / LocalAI

:robot: The free, Open Source alternative to OpenAI, Claude and others. Self-hosted and local-first. Drop-in replacement for OpenAI, running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. Features: Generate Text, Audio, Video, Images, Voice Cloning, Distributed, P2P inference
https://localai.io
MIT License
25.63k stars 1.93k forks source link

Telegram bot example does not build when following the instructions #2604

Closed greygoo closed 4 months ago

greygoo commented 4 months ago

LocalAI version: quay.io/go-skynet/local-ai:latest-aio-gpu-nvidia-cuda-12

Environment, CPU architecture, OS, and Version: Ryzen 7500, Nvidia 1660 GPU, OpenSUSE Tumbleweed

Describe the bug When following the instructions at https://github.com/mudler/LocalAI/blob/master/examples/telegram-bot/README.md - the docker compose build step fails with the following error:

greygoo@laboratory-vmhost:/data/src/TG-GPT> git clone https://github.com/go-skynet/LocalAI
Cloning into 'LocalAI'...
remote: Enumerating objects: 12920, done.
remote: Counting objects: 100% (1675/1675), done.
remote: Compressing objects: 100% (231/231), done.
remote: Total 12920 (delta 1522), reused 1511 (delta 1439), pack-reused 11245
Receiving objects: 100% (12920/12920), 6.61 MiB | 6.44 MiB/s, done.
Resolving deltas: 100% (8366/8366), done.
greygoo@laboratory-vmhost:/data/src/TG-GPT> cd LocalAI/examples/telegram-bot
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot> git clone https://github.com/mudler/chatgpt_telegram_bot
Cloning into 'chatgpt_telegram_bot'...
remote: Enumerating objects: 451, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 451 (delta 0), reused 2 (delta 0), pack-reused 447
Receiving objects: 100% (451/451), 1.03 MiB | 5.17 MiB/s, done.
Resolving deltas: 100% (249/249), done.
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot> cp -rf docker-compose.yml chatgpt_telegram_bot
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot> vi chatgpt_telegram_bot/docker-compose.yml 
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot> cd chatgpt_telegram_bot
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot> mv config/config.example.yml config/config.yml
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot> mv config/config.example.env config/config.env
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot> vim config/config.yml
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot> vi docker-compose.yml 
greygoo@laboratory-vmhost:/data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot> docker-compose --env-file config/config.env up --build
WARN[0000] /data/src/TG-GPT/LocalAI/examples/telegram-bot/chatgpt_telegram_bot/docker-compose.yml: `version` is obsolete 
[+] Building 2.8s (12/12) FINISHED                                                                                                                                                             docker:default
 => [chatgpt_telegram_bot internal] load build definition from Dockerfile                                                                                                                                0.1s
 => => transferring dockerfile: 535B                                                                                                                                                                     0.0s
 => [chatgpt_telegram_bot internal] load metadata for docker.io/library/python:3.11-slim                                                                                                                 1.4s
 => [chatgpt_telegram_bot internal] load .dockerignore                                                                                                                                                   0.1s
 => => transferring context: 46B                                                                                                                                                                         0.0s
 => [chatgpt_telegram_bot 1/7] FROM docker.io/library/python:3.11-slim@sha256:17ec9dc2367aa748559d0212f34665ec4df801129de32db705ea34654b5bc77a                                                           0.0s
 => [chatgpt_telegram_bot internal] load build context                                                                                                                                                   0.1s
 => => transferring context: 2.22MB                                                                                                                                                                      0.0s
 => CACHED [chatgpt_telegram_bot 2/7] RUN     set -eux;     apt-get update;     DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends     python3-pip     build-essential     pyt  0.0s
 => CACHED [chatgpt_telegram_bot 3/7] RUN pip install -U pip && pip install -U wheel                                                                                                                     0.0s
 => CACHED [chatgpt_telegram_bot 4/7] COPY ./requirements.txt /tmp/requirements.txt                                                                                                                      0.0s
 => CACHED [chatgpt_telegram_bot 5/7] RUN pip install -r /tmp/requirements.txt && rm -r /tmp/requirements.txt                                                                                            0.0s
 => [chatgpt_telegram_bot 6/7] COPY . /code                                                                                                                                                              0.2s
 => [chatgpt_telegram_bot 7/7] WORKDIR /code                                                                                                                                                             0.2s
 => [chatgpt_telegram_bot] exporting to image                                                                                                                                                            0.4s
 => => exporting layers                                                                                                                                                                                  0.2s
 => => writing image sha256:fd6954649379612a086de40bb862e12e22a573b4937a3e7390c59692e535ae28                                                                                                             0.0s
 => => naming to docker.io/library/chatgpt_telegram_bot-chatgpt_telegram_bot                                                                                                                             0.0s
[+] Running 1/1
 ✔ Container chatgpt_telegram_bot  Created                                                                                                                                                               0.2s 
Attaching to chatgpt_telegram_bot
chatgpt_telegram_bot  | Traceback (most recent call last):
chatgpt_telegram_bot  |   File "/usr/local/lib/python3.11/site-packages/langchain/_api/module_import.py", line 69, in import_by_name
chatgpt_telegram_bot  |     module = importlib.import_module(new_module)
chatgpt_telegram_bot  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgpt_telegram_bot  |   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
chatgpt_telegram_bot  |     return _bootstrap._gcd_import(name[level:], package, level)
chatgpt_telegram_bot  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
chatgpt_telegram_bot  |   File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
chatgpt_telegram_bot  | ModuleNotFoundError: No module named 'langchain_community'
chatgpt_telegram_bot  | 
chatgpt_telegram_bot  | The above exception was the direct cause of the following exception:
chatgpt_telegram_bot  | 
chatgpt_telegram_bot  | Traceback (most recent call last):
chatgpt_telegram_bot  |   File "/code/bot/bot.py", line 15, in <module>
chatgpt_telegram_bot  |     from agent import agent_actions,updateHandle
chatgpt_telegram_bot  |   File "/code/bot/agent.py", line 3, in <module>
chatgpt_telegram_bot  |     from langchain.embeddings import LocalAIEmbeddings
chatgpt_telegram_bot  |   File "/usr/local/lib/python3.11/site-packages/langchain/embeddings/__init__.py", line 167, in __getattr__
chatgpt_telegram_bot  |     return _import_attribute(name)
chatgpt_telegram_bot  |            ^^^^^^^^^^^^^^^^^^^^^^^
chatgpt_telegram_bot  |   File "/usr/local/lib/python3.11/site-packages/langchain/_api/module_import.py", line 72, in import_by_name
chatgpt_telegram_bot  |     raise ModuleNotFoundError(
chatgpt_telegram_bot  | ModuleNotFoundError: Module langchain_community.embeddings not found. Please install langchain-community to access this module. You can install it using `pip install -U langchain-community`
chatgpt_telegram_bot exited with code 0

By adding RUN pip install -U langchain-community to the Dockerfile, the container builds and runs, but that's just a workaround. You can point me to where the best place is to fix this is, and I can test and create a PR.

To Reproduce Follow instructions at https://github.com/mudler/LocalAI/blob/master/examples/telegram-bot/README.md

Expected behavior No build error

Logs log of build error in description

Additional context

greygoo commented 4 months ago

The proper fix is obviously to add langchain-community to requirements.txt. Just tested, works here.

jtwolfe commented 4 months ago

fork -> branch -> pull -> profit :P

You gonna add it or shall I?

mudler commented 4 months ago

hey @greygoo ! nice to see you here! that looks right, willing to open up a PR?

greygoo commented 4 months ago

I can do :)