Selaa lähdekoodia

Merge pull request #223 from limccn/master

feat: use entrypoint.sh override environment variables
master
zhayujie GitHub 1 vuosi sitten
vanhempi
commit
2aa146341f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 muutettua tiedostoa jossa 116 lisäystä ja 9 poistoa
  1. +7
    -3
      docker/Dockerfile.alpine
  2. +7
    -4
      docker/Dockerfile.debian
  3. +2
    -0
      docker/build.alpine.sh
  4. +2
    -0
      docker/build.debian.sh
  5. +10
    -1
      docker/docker-compose.yaml
  6. +75
    -0
      docker/entrypoint.sh
  7. +12
    -0
      docker/sample-chatgpt-on-wechat/.env
  8. +1
    -1
      docker/sample-chatgpt-on-wechat/Makefile

+ 7
- 3
docker/Dockerfile.alpine Näytä tiedosto

@@ -9,6 +9,7 @@ ENV BUILD_PREFIX=/app \
BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE'

RUN apk add --no-cache \
bash \
curl \
wget \
openssh
@@ -23,16 +24,19 @@ WORKDIR ${BUILD_PREFIX}

RUN cd ${BUILD_PREFIX} \
&& cp config-template.json ${BUILD_PREFIX}/config.json \
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json \
&& cat ${BUILD_PREFIX}/config.json
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json

RUN /usr/local/bin/python -m pip install --upgrade pip \
&& pip install itchat-uos==1.5.0.dev0 \
&& pip install --upgrade openai

ADD ./entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

RUN adduser -D -h /home/noroot -u 1000 -s /bin/bash noroot \
&& chown noroot:noroot ${BUILD_PREFIX}

USER noroot

CMD ["python","app.py"]
ENTRYPOINT ["/entrypoint.sh"]

+ 7
- 4
docker/Dockerfile.debian Näytä tiedosto

@@ -24,17 +24,20 @@ WORKDIR ${BUILD_PREFIX}

RUN cd ${BUILD_PREFIX} \
&& cp config-template.json ${BUILD_PREFIX}/config.json \
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json \
&& cat ${BUILD_PREFIX}/config.json
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json

RUN /usr/local/bin/python -m pip install --upgrade pip \
&& pip install itchat-uos==1.5.0.dev0 \
&& pip install --upgrade openai

ADD ./entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

RUN groupadd -r noroot \
&& useradd -r -g noroot noroot \
&& useradd -r -g noroot -s /bin/bash -d /home/noroot noroot \
&& chown -R noroot:noroot ${BUILD_PREFIX}

USER noroot

CMD ["python","app.py"]
ENTRYPOINT ["/entrypoint.sh"]

+ 2
- 0
docker/build.alpine.sh Näytä tiedosto

@@ -1,3 +1,5 @@
#!/bin/bash

docker build -f Dockerfile.alpine \
--build-arg CHATGPT_ON_WECHAT_VER=1.0.0\
-t zhayujie/chatgpt-on-wechat:1.0.0-alpine .

+ 2
- 0
docker/build.debian.sh Näytä tiedosto

@@ -1,3 +1,5 @@
#!/bin/bash

docker build -f Dockerfile.debian \
--build-arg CHATGPT_ON_WECHAT_VER=1.0.0\
-t zhayujie/chatgpt-on-wechat:1.0.0-debian .

+ 10
- 1
docker/docker-compose.yaml Näytä tiedosto

@@ -5,4 +5,13 @@ services:
context: ./
dockerfile: Dockerfile.alpine
image: zhayujie/chatgpt-on-wechat:1.0.0-alpine
container_name: sample-chatgpt-on-wechat
container_name: sample-chatgpt-on-wechat
environment:
OPEN_AI_API_KEY: 'YOUR API KEY'
SINGLE_CHAT_PREFIX: '["BOT", "@BOT"]'
SINGLE_CHAT_REPLY_PREFIX: '"[BOT] "'
GROUP_CHAT_PREFIX: '["@BOT"]'
GROUP_NAME_WHITE_LIST: '["CHATGPT测试群", "CHATGPT测试群2"]'
IMAGE_CREATE_PREFIX: '["画", "看", "找"]'
CONVERSATION_MAX_TOKENS: 1000
CHARACTER_DESC: '你是CHATGPT, 一个由OPENAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。'

+ 75
- 0
docker/entrypoint.sh Näytä tiedosto

@@ -0,0 +1,75 @@
#!/bin/bash
set -e

# build prefix
CHATGPT_ON_WECHAT_PREFIX=${CHATGPT_ON_WECHAT_PREFIX:-""}
# path to config.json
CHATGPT_ON_WECHAT_CONFIG_PATH=${CHATGPT_ON_WECHAT_CONFIG_PATH:-""}
# execution command line
CHATGPT_ON_WECHAT_EXEC=${CHATGPT_ON_WECHAT_EXEC:-""}

OPEN_AI_API_KEY=${OPEN_AI_API_KEY:-""}
SINGLE_CHAT_PREFIX=${SINGLE_CHAT_PREFIX:-""}
SINGLE_CHAT_REPLY_PREFIX=${SINGLE_CHAT_REPLY_PREFIX:-""}
GROUP_CHAT_PREFIX=${GROUP_CHAT_PREFIX:-""}
GROUP_NAME_WHITE_LIST=${GROUP_NAME_WHITE_LIST:-""}
IMAGE_CREATE_PREFIX=${IMAGE_CREATE_PREFIX:-""}
CONVERSATION_MAX_TOKENS=${CONVERSATION_MAX_TOKENS:-""}
CHARACTER_DESC=${CHARACTER_DESC:-""}

# CHATGPT_ON_WECHAT_PREFIX is empty, use /app
if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then
CHATGPT_ON_WECHAT_PREFIX=/app
fi

# APP_PREFIX is empty, use '/app/config.json'
if [ "$CHATGPT_ON_WECHAT_CONFIG_PATH" == "" ] ; then
CHATGPT_ON_WECHAT_CONFIG_PATH=$CHATGPT_ON_WECHAT_PREFIX/config.json
fi

# CHATGPT_ON_WECHAT_EXEC is empty, use ‘python app.py’
if [ "$CHATGPT_ON_WECHAT_EXEC" == "" ] ; then
CHATGPT_ON_WECHAT_EXEC="python app.py"
fi

# modify content in config.json
if [ "$OPEN_AI_API_KEY" != "" ] ; then
sed -i "2c \"open_ai_api_key\": \"$OPEN_AI_API_KEY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH
else
echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m"
fi

if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then
sed -i "3c \"single_chat_prefix\": $SINGLE_CHAT_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$SINGLE_CHAT_REPLY_PREFIX" != "" ] ; then
sed -i "4c \"single_chat_reply_prefix\": $SINGLE_CHAT_REPLY_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$GROUP_CHAT_PREFIX" != "" ] ; then
sed -i "5c \"group_chat_prefix\": $GROUP_CHAT_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$GROUP_NAME_WHITE_LIST" != "" ] ; then
sed -i "6c \"group_name_white_list\": $GROUP_NAME_WHITE_LIST," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$IMAGE_CREATE_PREFIX" != "" ] ; then
sed -i "7c \"image_create_prefix\": $IMAGE_CREATE_PREFIX," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$CONVERSATION_MAX_TOKENS" != "" ] ; then
sed -i "8c \"conversation_max_tokens\": $CONVERSATION_MAX_TOKENS," $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

if [ "$CHARACTER_DESC" != "" ] ; then
sed -i "9c \"character_desc\": \"$CHARACTER_DESC\"" $CHATGPT_ON_WECHAT_CONFIG_PATH
fi

# go to prefix dir
cd $CHATGPT_ON_WECHAT_PREFIX
# excute
$CHATGPT_ON_WECHAT_EXEC



+ 12
- 0
docker/sample-chatgpt-on-wechat/.env Näytä tiedosto

@@ -1 +1,13 @@
OPEN_AI_API_KEY=YOUR API KEY
SINGLE_CHAT_PREFIX=["BOT", "@BOT"]
SINGLE_CHAT_REPLY_PREFIX="[BOT] "
GROUP_CHAT_PREFIX=["@BOT"]
GROUP_NAME_WHITE_LIST=["CHATGPT测试群", "CHATGPT测试群2"]
IMAGE_CREATE_PREFIX=["画", "看", "找"]
CONVERSATION_MAX_TOKENS=1000
CHARACTER_DESC=你是CHATGPT, 一个由OPENAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。

# Optional
#CHATGPT_ON_WECHAT_PREFIX=/app
#CHATGPT_ON_WECHAT_CONFIG_PATH=/app/config.json
#CHATGPT_ON_WECHAT_EXEC=python app.py

+ 1
- 1
docker/sample-chatgpt-on-wechat/Makefile Näytä tiedosto

@@ -1,5 +1,5 @@
IMG:=`cat Name`
MOUNT:=-v `pwd`/config.json:/app/config.json
MOUNT:=
PORT_MAP:=
DOTENV:=.env
CONTAINER_NAME:=sample-chatgpt-on-wechat


Loading…
Peruuta
Tallenna