From cf09067c156b581db6cde07728cce849b7a971e3 Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 1 Feb 2025 13:54:25 +0100 Subject: Expose OpenAI API compatibility using aichat --- src/aichat/Dockerfile | 9 ++++++++- src/aichat/entrypoint.sh | 4 ++++ src/nginx/nginx.conf | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/aichat/entrypoint.sh (limited to 'src') 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; + } + } } -- cgit v1.2.3