diff options
author | ben | 2025-02-01 13:54:25 +0100 |
---|---|---|
committer | ben | 2025-02-01 13:54:25 +0100 |
commit | cf09067c156b581db6cde07728cce849b7a971e3 (patch) | |
tree | ee75be9ba6bffc4f923b87c327c6b401f5634037 | |
parent | 01f224002e91e9ba8c567dbfb20a364f13327842 (diff) | |
download | ai_env-cf09067c156b581db6cde07728cce849b7a971e3.tar.gz ai_env-cf09067c156b581db6cde07728cce849b7a971e3.tar.bz2 ai_env-cf09067c156b581db6cde07728cce849b7a971e3.tar.xz |
Expose OpenAI API compatibility using aichat
-rw-r--r-- | docker-compose.yml | 20 | ||||
-rwxr-xr-x | setup_desktop.sh | 2 | ||||
-rw-r--r-- | src/aichat/Dockerfile | 9 | ||||
-rw-r--r-- | src/aichat/entrypoint.sh | 4 | ||||
-rw-r--r-- | src/nginx/nginx.conf | 17 |
5 files changed, 47 insertions, 5 deletions
diff --git a/docker-compose.yml b/docker-compose.yml index 97b141c..12ffb88 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,10 +54,21 @@ services: links: - ollama - aichat-build: + aichat: build: dockerfile: src/aichat/Dockerfile - restart: no + restart: unless-stopped + environment: + - API_KEY=${LLM_API_KEY} + depends_on: + - ollama + links: + - ollama + healthcheck: + test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/8000' || exit 1 + interval: 30s + timeout: 15s + retries: 3 faster-whisper-server: image: fedirz/faster-whisper-server:latest-cuda @@ -74,7 +85,7 @@ services: capabilities: [gpu] restart: unless-stopped healthcheck: - test: timeout 10s bash -c ':> /dev/tcp/127.0.0.1/8000' || exit 1 + test: curl --fail http://localhost:8000 || exit 1 interval: 30s timeout: 15s retries: 3 @@ -90,14 +101,17 @@ services: - openedai-speech - faster-whisper-server - ollama + - aichat links: - ollama - faster-whisper-server - openedai-speech + - aichat ports: - "11434:11434" - "8000:8000" - "8001:8001" + - "8002:8002" restart: unless-stopped volumes: diff --git a/setup_desktop.sh b/setup_desktop.sh index cc951af..7ef956e 100755 --- a/setup_desktop.sh +++ b/setup_desktop.sh @@ -7,7 +7,7 @@ cd "$SCRIPTPATH" || exit if [[ ! -x $(command -v aichat) ]]; then echo "aichat is not installed." if [[ $(docker images -q aichat-build 2>/dev/null) ]]; then - container_id=$(docker create "aichat-build") + container_id=$(docker create "aichat") docker cp "${container_id}:/usr/local/cargo/bin/aichat" "./tools/" docker rm "${container_id}" else diff --git a/src/aichat/Dockerfile b/src/aichat/Dockerfile index df13f63..406dde2 100644 --- a/src/aichat/Dockerfile +++ b/src/aichat/Dockerfile @@ -1,7 +1,14 @@ FROM rust:latest RUN rustup target add x86_64-unknown-linux-musl -RUN apt update && apt install -y musl-tools musl-dev +RUN apt update && apt install -y musl-tools musl-dev curl RUN update-ca-certificates RUN cargo install --target x86_64-unknown-linux-musl aichat + +ADD src/aichat/entrypoint.sh /entrypoint.sh +ADD src/aichat/config.yaml /aichat_config_tpl.yaml + +RUN chmod 755 entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/src/aichat/entrypoint.sh b/src/aichat/entrypoint.sh new file mode 100644 index 0000000..ec4f040 --- /dev/null +++ b/src/aichat/entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh +mkdir -p ~/.config/aichat +cat /aichat_config_tpl.yaml | sed "s/__LLM_API_KEY__/${LLM_API_KEY}/" | sed "s/localhost/ollama/" >~/.config/aichat/config.yaml +aichat --serve 0.0.0.0 diff --git a/src/nginx/nginx.conf b/src/nginx/nginx.conf index 2dc6d52..5e411a9 100644 --- a/src/nginx/nginx.conf +++ b/src/nginx/nginx.conf @@ -58,4 +58,21 @@ http { proxy_set_header Connection "upgrade"; } } + server { + listen 8002; + set $deny 1; + if ($http_authorization = "Bearer $API_KEY") { + set $deny 0; + } + if ($deny) { + return 403; + } + location / { + proxy_pass http://aichat:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } } |