n3d1117 / chatgpt-telegram-bot

🤖 A Telegram bot that integrates with OpenAI's official ChatGPT APIs to provide answers, written in Python
GNU General Public License v2.0
2.88k stars 1.32k forks source link

Tiktoken Docker on Raspbeey PI #128

Open AlejandroIglesiasCalvo opened 1 year ago

AlejandroIglesiasCalvo commented 1 year ago

Discussed in https://github.com/n3d1117/chatgpt-telegram-bot/discussions/127

Originally posted by **AlejandroIglesiasCalvo** March 28, 2023 Hello, I'm working on this Bot on a Raspberry Pi. I use Github Actions to compile different versions, but the compilation for arm v7 is of greater interest to me. The problem is that the tiktoken library doesn't have wheels for armv7. I would like to know if someone has managed to patch this or avoid the problem. Specifically, I managed to avoid it at the cost of losing all usage calculations. That is, without using tiktoken. The error that generates is: #10 415.8 Building wheels for collected packages: tiktoken, regex, aiohttp, frozenlist, multidict, yarl #10 415.8 Building wheel for tiktoken (pyproject.toml): started #10 424.5 Building wheel for tiktoken (pyproject.toml): finished with status 'error' #10 424.6 error: subprocess-exited-with-error #10 424.6 #10 424.6 × Building wheel for tiktoken (pyproject.toml) did not run successfully. #10 424.6 │ exit code: 1 #10 424.6 ╰─> [39 lines of output] #10 424.6 running bdist_wheel #10 424.6 running build #10 424.6 running build_py #10 424.6 creating build #10 424.6 creating build/lib.linux-armv7l-cpython-39 #10 424.6 creating build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 copying tiktoken/load.py -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 copying tiktoken/__init__.py -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 copying tiktoken/core.py -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 copying tiktoken/registry.py -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 copying tiktoken/model.py -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 creating build/lib.linux-armv7l-cpython-39/tiktoken_ext #10 424.6 copying tiktoken_ext/openai_public.py -> build/lib.linux-armv7l-cpython-39/tiktoken_ext #10 424.6 running egg_info #10 424.6 writing tiktoken.egg-info/PKG-INFO #10 424.6 writing dependency_links to tiktoken.egg-info/dependency_links.txt #10 424.6 writing requirements to tiktoken.egg-info/requires.txt #10 424.6 writing top-level names to tiktoken.egg-info/top_level.txt #10 424.6 reading manifest file 'tiktoken.egg-info/SOURCES.txt' #10 424.6 reading manifest template 'MANIFEST.in' #10 424.6 warning: no files found matching 'Makefile' #10 424.6 adding license file 'LICENSE' #10 424.6 writing manifest file 'tiktoken.egg-info/SOURCES.txt' #10 424.6 copying tiktoken/py.typed -> build/lib.linux-armv7l-cpython-39/tiktoken #10 424.6 warning: build_py: byte-compiling is disabled, skipping. #10 424.6 #10 424.6 running build_ext #10 424.6 running build_rust #10 424.6 error: can't find Rust compiler #10 424.6 #10 424.6 If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler. #10 424.6 #10 424.6 To update pip, run: #10 424.6 #10 424.6 pip install --upgrade pip #10 424.6 #10 424.6 and then retry package installation. #10 424.6 #10 424.6 If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at [https://rustup.rs)](https://rustup.rs%29/) is the recommended way to download and update the Rust compiler toolchain. #10 424.6 [end of output] #10 424.6 #10 424.6 note: This error originates from a subprocess, and is likely not a problem with pip. #10 424.7 ERROR: Failed building wheel for tiktoken Mi DockerFile: FROM python:3.9-alpine ENV PYTHONFAULTHANDLER=1 \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_DISABLE_PIP_VERSION_CHECK=on RUN apk --no-cache add ffmpeg WORKDIR /app COPY . . RUN pip install -r requirements.txt --no-cache-dir CMD ["python", "bot/main.py"]
Axibed commented 1 year ago

Hello, I encountered the same problem, but when trying to run on android (termux, pydroid). I tried everything and did not install this tiktoken. Either Rust asks, although when installing it at the very end, some error comes out.

AlejandroIglesiasCalvo commented 1 year ago

I have continued investigating, and even trying to install tiktoken separately (the only "solution" I found) gives me an error. The dockerfile with the "solution" is: FROM python:3.11-slim-bullseye as builder

Tiktoken requires Rust toolchain, so build it in a separate stage

RUN apt-get update && apt-get install -y gcc curl RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && apt-get install --reinstall libc6-dev -y ENV PATH="/root/.cargo/bin:${PATH}" RUN pip install --upgrade pip && pip install tiktoken

FROM python:3.11-slim-bullseye

Copy pre-built packages and cargo from builder stage

COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/ COPY --from=builder /root/.cargo /root/.cargo

ENV PYTHONFAULTHANDLER=1 \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_DISABLE_PIP_VERSION_CHECK=on\ CARGO_NET_GIT_FETCH_WITH_CLI="true"

WORKDIR /app COPY . .

RUN pip install --upgrade pip && pip install -r requirements.txt

CMD ["python", "bot/main.py"]

But it doesn't work, I keep investigating. 😔😔

n3d1117 commented 1 year ago

Maybe you could try opening an issue in the tiktoken repository?

slippersheepig commented 1 year ago

Try to useFROM rust:slim-bookwormandapt update && apt install pip,at lastpython3 main.py?It may work.

jwellner commented 1 year ago

For me Tiktoken compiled when I installed the rust and cargo packages: (don't know if all packages are needed)

RUN apk --no-cache add ffmpeg python3-dev gcc curl libc-dev clang lld cargo rust

I'm on odroidxu4 with armv7

ArsenKakasyan commented 11 months ago

For me Tiktoken compiled when I installed the rust and cargo packages: (don't know if all packages are needed)

RUN apk --no-cache add ffmpeg python3-dev gcc curl libc-dev clang lld cargo rust

I'm on odroidxu4 with armv7

Can you share Dockerfile? I tried what you wrote but it didn't work. I have armv7 too...

fidel-perez commented 7 months ago

I just opened a PR with a dockerfile that works for me on the raspberry pi 3: #472