Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing a docker/image for "linux/arm/v7" (raspberry pi) ... could be marvelous ! #2349

Open
manatlan opened this issue Nov 13, 2024 · 21 comments

Comments

@manatlan
Copy link
Contributor

Is your feature request related to a problem? Please describe.
no

Describe the solution you'd like
Providing a docker/image for "linux/arm/v7" (raspberry pi) ... could be marvelous !

Describe alternatives you've considered
I tried a docker-compose of the github repo, with no luck (compilation trouble)
But I'm really not an expert ... perhaps an expert could help ?

Additional context
it could be marvelous to have a docker running on a simple raspberry pi !

@hqnicolas
Copy link

hello dear, docker for arm v7 isn't possible
try an armv8 device as me
i'm using RK3566
https://forum.armbian.com/topic/28895-efforts-to-develop-firmware-for-h96-max-v56-rk3566-8g64g/

@manatlan
Copy link
Contributor Author

manatlan commented Nov 14, 2024

Do you known what components are problematic for armv7 ?
Perhaps I could help to fix them.

If they are related to gui or vnc ... I don't need them for api only

@foxfire52
Copy link
Contributor

foxfire52 commented Nov 14, 2024

@manatlan The project uses seleniarm/node-chromium as base image. I think the selenium maintainers don't provide an armv7 image. You could ask here https://github.com/SeleniumHQ/docker-selenium
Also SeleniumHQ/docker-selenium#1076

I think the easiest way to support armv7 would be a different base image without selenium, though with a reduced number of working providers. You could try starting from that.

@foxfire52
Copy link
Contributor

@manatlan Try replacing the first line in Dockerfile

FROM seleniarm/node-chromium
ARG G4F_VERSION
ARG G4F_USER=g4f
ARG G4F_USER_ID=1000

with
FROM seleniarm/node-chromium:4.18.1-20240326
Then run docker compose up --build on your arm device.

It's an older selenium docker image with armv7 support.

@manatlan
Copy link
Contributor Author

I tried ... but got this problem

80.45             building '_cffi_backend' extension
80.45             creating build/temp.linux-armv7l-cpython-311/src/c
80.45             arm-linux-gnueabihf-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -DFFI_BUILDING=1 -DUSE__THREAD -DHAVE_SYNC_SYNCHRONIZE -I/usr/include/ffi -I/usr/include/libffi -I/usr/include/python3.11 -c src/c/_cffi_backend.c -o build/temp.linux-armv7l-cpython-311/src/c/_cffi_backend.o
80.45             src/c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
80.45                15 | #include <ffi.h>
80.45                   |          ^~~~~~~
80.45             compilation terminated.
80.45             error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
80.45             [end of output]
80.45       
80.45         note: This error originates from a subprocess, and is likely not a problem with pip.
80.45         ERROR: Failed building wheel for cffi
80.45       Failed to build cffi
80.45       ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (cffi)
80.45       [end of output]
80.45   
80.45   note: This error originates from a subprocess, and is likely not a problem with pip.
81.81 error: subprocess-exited-with-error
81.81 
81.81 × pip subprocess to install build dependencies did not run successfully.
81.81 │ exit code: 1
81.81 ╰─> See above for output.
81.81 
81.81 note: This error originates from a subprocess, and is likely not a problem with pip.

it can't build cffi ;-(
any ideas ?

@foxfire52
Copy link
Contributor

foxfire52 commented Nov 17, 2024

@manatlan Try adding this


RUN apt-get -qqy update \
&& apt-get -qqy install libffi-dev

At line 40 of Dockerfile

&& apt-get -qyy remove openjdk-11-jre-headless \
&& apt-get -qyy autoremove \
&& apt-get -qyy clean \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
# Update entrypoint
COPY docker/supervisor.conf /etc/supervisor/conf.d/selenium.conf
COPY docker/supervisor-gui.conf /etc/supervisor/conf.d/gui.conf

This should fix the missing ffi.h file dependency

@foxfire52
Copy link
Contributor

There's a new update, hlohaus added a slim Dockerfile without selenium dependency.

You should try that docker image too, I think it should work.
Download repository latest version and run

docker-compose -f docker-compose-slim.yml up -d --build

@manatlan
Copy link
Contributor Author

@foxfire52 ... I'm trying .... with "docker compose" (and not "docker-compose") ...
it's always building (for more than 3 hours) ... but it will do it ;-)
...
I will not update often (it's very very long)

@manatlan
Copy link
Contributor Author

perhaps it's possible to build it via a github action
seems possible
https://earthly.dev/blog/arm-containers-github-actions/

@manatlan
Copy link
Contributor Author

It takes more than 5h... And crash my RPI 3b+, without results ;-(

@foxfire52
Copy link
Contributor

foxfire52 commented Nov 24, 2024

@manatlan It is possible but current github action arm build failed

@hlohaus
Github doesn't provide native arm runners yet (GitHub-hosted arm64 runners), so it cross-compiles.
I think the problem happens when the docker image is cross-compiled on x64 linux platform with buildx qemu x64. Cargo dependency (duckduckgo-search->primp) can trigger build failure (qemu kernel bug link1 link2). Sometimes it affects cryptography module.
This bug doesn't affect x86 build environments or native arm platforms.

As fix we can remove duckduckgo-search requirement and RUN rustup self uninstall -y line from docker-slim image.
It should work.

@foxfire52
Copy link
Contributor

foxfire52 commented Nov 25, 2024

@manatlan Thanks to hlohaus the armv7 image is now available on docker hub.

You can test it with:

docker run \
  -p 1337:1337 \
  -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  -v ${PWD}/generated_images:/app/generated_images \
  hlohaus789/g4f:latest-slim \
  rm -r -f /app/g4f/ \
  && pip install -U g4f[slim] \
  && python -m g4f.cli api --gui --debug

@hlohaus
Copy link
Collaborator

hlohaus commented Nov 25, 2024

Good. I modified the Dockerfile to bypass any missing pip requirements.
Additionally, please be aware that not all Python packages may be installed.

@manatlan
Copy link
Contributor Author

still trouble

Collecting primp>=0.8.0
  Downloading primp-0.8.0.tar.gz (80 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 80.5/80.5 KB 1.5 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      Checking for Rust toolchain....
      Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-6njso_zl --interpreter /usr/bin/python3`
      Traceback (most recent call last):
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/lib/python3/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 164, in prepare_metadata_for_build_wheel
          return hook(metadata_directory, config_settings)
        File "/tmp/pip-build-env-j0dfi4pm/overlay/local/lib/python3.10/dist-packages/maturin/__init__.py", line 203, in prepare_metadata_for_build_wheel
          _output = subprocess.check_output(command)
        File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        File "/usr/lib/python3.10/subprocess.py", line 503, in run
          with Popen(*popenargs, **kwargs) as process:
        File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
          raise child_exception_type(errno_num, err_msg, err_filename)
      FileNotFoundError: [Errno 2] No such file or directory: 'maturin'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

@manatlan
Copy link
Contributor Author

manatlan commented Nov 26, 2024

but got better results with :

docker run \
  -p 1337:1337 \
  -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  -v ${PWD}/generated_images:/app/generated_images \
  hlohaus789/g4f:latest-slim \
  rm -r -f /app/g4f/ \
  && pip install -U pip \
  && pip install -U g4f[slim] \
  && python -m g4f.cli api --debug

but no ;-(

building wheels for collected packages: aiohttp, MarkupSafe, primp
  Building wheel for aiohttp (pyproject.toml) ... done
  Created wheel for aiohttp: filename=aiohttp-3.11.7-cp310-cp310-linux_armv7l.whl size=1414896 sha256=d9e55595e0841c527752acfc4c3e5eb1b4eebda3a4a272019e0db4e0df230c46
  Stored in directory: /home/pi/.cache/pip/wheels/30/b5/dc/4688f9dcdb7b52f57a5197868e86041f196889ca1a263874ed
  Building wheel for MarkupSafe (pyproject.toml) ... done
  Created wheel for MarkupSafe: filename=MarkupSafe-3.0.2-cp310-cp310-linux_armv7l.whl size=20934 sha256=ef190a5cfdd212dbfde0d3530c0b7bfff479754488800876ee0be1b8397c5b82
  Stored in directory: /home/pi/.cache/pip/wheels/6b/a7/76/330d3979389a2d294838832f620ac3fd32b4ce50d1524c1e29
  Building wheel for primp (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for primp (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [13 lines of output]
      Running `maturin pep517 build-wheel -i /usr/bin/python3 --compatibility off`
      📦 Including license file "/tmp/pip-install-u1fwnlou/primp_2f08d6335e164579b4611174f5e39741/LICENSE"
      🔗 Found pyo3 bindings with abi3 support for Python ≥ 3.8
      🐍 Not using a specific python interpreter
      📡 Using build options features from pyproject.toml
      error: package `rquest v0.27.7` cannot be built because it requires rustc 1.80 or newer, while the currently active rustc version is 1.75.0
      Either upgrade to rustc 1.80 or newer, or use
      cargo update [email protected] --precise ver
      where `ver` is the latest version of `rquest` supporting rustc 1.75.0
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_ENVIRONMENT_SIGNATURE="cpython-3.10-64bit" PYO3_PYTHON="/usr/bin/python3" PYTHON_SYS_EXECUTABLE="/usr/bin/python3" "cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "/tmp/pip-install-u1fwnlou/primp_2f08d6335e164579b4611174f5e39741/Cargo.toml" "--release" "--lib"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/usr/bin/python3', '--compatibility', 'off'] returned non-zero exit status 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for primp
Successfully built aiohttp MarkupSafe

I cross posted here : deedy5/primp#50

@hqnicolas
Copy link

great Job @manatlan @hlohaus @foxfire52
Armv7 docker is something on the edge
congratulations

@manatlan
Copy link
Contributor Author

I confirm !!!!

it's working now ! primp 0.8.1 fixed the bug .... and I can run it thru :

docker run \
  -p 1337:1337 \
  -v ${PWD}/har_and_cookies:/app/har_and_cookies \
  -v ${PWD}/generated_images:/app/generated_images \
  hlohaus789/g4f:latest-slim \
  rm -r -f /app/g4f/ \
  && pip install -U pip \
  && pip install -U g4f[slim] \
  && python3 -m g4f.cli api --debug

@manatlan
Copy link
Contributor Author

but at runtime, there is an error :-)

INFO:     192.168.1.1:55578 - "POST /v1/chat/completions HTTP/1.1" 500 Internal Server Error
INFO:     192.168.1.1:55578 - "OPTIONS /v1/chat/completions HTTP/1.1" 200 OK
ERROR:g4f.api:'ChatCompletionsConfig' object has no attribute 'model_dump'
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.10/site-packages/g4f/api/__init__.py", line 305, in chat_completions
    **config.model_dump(exclude_none=True),
AttributeError: 'ChatCompletionsConfig' object has no attribute 'model_dump'

@manatlan
Copy link
Contributor Author

manatlan commented Nov 26, 2024

tested with older version (0.3.6.3 & 0.3.7.1) ... but got a lot of :

g4f.errors.RateLimitError: CaptchaChallenge: Use other cookies or/and ip address
g4f.errors.RateLimitError: Response 402: Rate limit reached
...
for a lot of models ("gpt-4o", "gpt-4o-mini", "gemini-pro", "llama*" etc ...)

seems too lite ;-)

@foxfire52
Copy link
Contributor

foxfire52 commented Nov 26, 2024

cffi and pillow python modules are still missing, I've opened a Pull request to address that.

Also the Docker image name has changed. It should be hlohaus789/g4f:latest-armv7 now.

@hlohaus
Copy link
Collaborator

hlohaus commented Nov 26, 2024

@manatlan Hey man, your messages are actually from Bing. Bing Chat is no more. It's now Copilot. And guess what, you don't even need an account to use Copilot! But here's the catch, you can't upload or generate images without one.

tested with older version (0.3.6.3 & 0.3.7.1) ... but got a lot of :

g4f.errors.RateLimitError: CaptchaChallenge: Use other cookies or/and ip address
g4f.errors.RateLimitError: Response 402: Rate limit reached
...
for a lot of models ("gpt-4o", "gpt-4o-mini", "gemini-pro", "llama*" etc ...)

seems too lite ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants