@@ -110,7 +110,7 @@ class ChatGPTBot(Bot): | |||||
if retry_count < 1: | if retry_count < 1: | ||||
time.sleep(5) | time.sleep(5) | ||||
logger.warn("[OPEN_AI] ImgCreate RateLimit exceed, 第{}次重试".format(retry_count+1)) | logger.warn("[OPEN_AI] ImgCreate RateLimit exceed, 第{}次重试".format(retry_count+1)) | ||||
return self.reply_text(query, retry_count+1) | |||||
return self.create_img(query, retry_count+1) | |||||
else: | else: | ||||
return "提问太快啦,请休息一下再问我吧" | return "提问太快啦,请休息一下再问我吧" | ||||
except Exception as e: | except Exception as e: | ||||
@@ -3,7 +3,7 @@ FROM python:3.7.9-alpine | |||||
LABEL maintainer="foo@bar.com" | LABEL maintainer="foo@bar.com" | ||||
ARG TZ='Asia/Shanghai' | ARG TZ='Asia/Shanghai' | ||||
ARG CHATGPT_ON_WECHAT_VER=1.0.2 | |||||
ARG CHATGPT_ON_WECHAT_VER | |||||
ENV BUILD_PREFIX=/app \ | ENV BUILD_PREFIX=/app \ | ||||
BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE' | BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE' | ||||
@@ -12,35 +12,29 @@ RUN apk add --no-cache \ | |||||
bash \ | bash \ | ||||
curl \ | curl \ | ||||
wget \ | wget \ | ||||
gcc \ | |||||
g++ \ | |||||
ca-certificates \ | |||||
openssh \ | |||||
libffi-dev | |||||
RUN wget -t 3 -T 30 -nv -O chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
https://github.com/zhayujie/chatgpt-on-wechat/archive/refs/tags/${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
&& tar -xzf chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
&& mv chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER} ${BUILD_PREFIX} \ | |||||
&& rm chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz | |||||
WORKDIR ${BUILD_PREFIX} | |||||
RUN cd ${BUILD_PREFIX} \ | |||||
&& export BUILD_GITHUB_TAG=${CHATGPT_ON_WECHAT_VER:-`curl -sL "https://api.github.com/repos/zhayujie/chatgpt-on-wechat/releases/latest" | \ | |||||
grep '"tag_name":' | \ | |||||
sed -E 's/.*"([^"]+)".*/\1/'`} \ | |||||
&& wget -t 3 -T 30 -nv -O chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
https://github.com/zhayujie/chatgpt-on-wechat/archive/refs/tags/${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& tar -xzf chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& mv chatgpt-on-wechat-${BUILD_GITHUB_TAG} ${BUILD_PREFIX} \ | |||||
&& rm chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& cd ${BUILD_PREFIX} \ | |||||
&& cp config-template.json ${BUILD_PREFIX}/config.json \ | && cp config-template.json ${BUILD_PREFIX}/config.json \ | ||||
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json | |||||
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json \ | |||||
&& /usr/local/bin/python -m pip install --no-cache --upgrade pip \ | |||||
&& pip install --no-cache \ | |||||
itchat-uos==1.5.0.dev0 \ | |||||
openai \ | |||||
&& apk del curl wget | |||||
RUN /usr/local/bin/python -m pip install --no-cache --upgrade pip \ | |||||
&& pip install --no-cache \ | |||||
itchat-uos==1.5.0.dev0 \ | |||||
openai \ | |||||
wechaty | |||||
WORKDIR ${BUILD_PREFIX} | |||||
ADD ./entrypoint.sh /entrypoint.sh | ADD ./entrypoint.sh /entrypoint.sh | ||||
RUN chmod +x /entrypoint.sh | |||||
RUN adduser -D -h /home/noroot -u 1000 -s /bin/bash noroot \ | |||||
RUN chmod +x /entrypoint.sh \ | |||||
&& adduser -D -h /home/noroot -u 1000 -s /bin/bash noroot \ | |||||
&& chown noroot:noroot ${BUILD_PREFIX} | && chown noroot:noroot ${BUILD_PREFIX} | ||||
USER noroot | USER noroot | ||||
@@ -3,42 +3,40 @@ FROM python:3.7.9 | |||||
LABEL maintainer="foo@bar.com" | LABEL maintainer="foo@bar.com" | ||||
ARG TZ='Asia/Shanghai' | ARG TZ='Asia/Shanghai' | ||||
ARG CHATGPT_ON_WECHAT_VER=1.0.2 | |||||
ARG CHATGPT_ON_WECHAT_VER | |||||
ENV BUILD_PREFIX=/app \ | ENV BUILD_PREFIX=/app \ | ||||
BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE' | BUILD_OPEN_AI_API_KEY='YOUR OPEN AI KEY HERE' | ||||
RUN apt-get update && \ | |||||
apt-get install -y --no-install-recommends \ | |||||
RUN apt-get update \ | |||||
&& apt-get install -y --no-install-recommends \ | |||||
wget \ | wget \ | ||||
curl && \ | |||||
rm -rf /var/lib/apt/lists/* | |||||
RUN wget -t 3 -T 30 -nv -O chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
https://github.com/zhayujie/chatgpt-on-wechat/archive/refs/tags/${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
&& tar -xzf chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz \ | |||||
&& mv chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER} ${BUILD_PREFIX} \ | |||||
&& rm chatgpt-on-wechat-${CHATGPT_ON_WECHAT_VER}.tar.gz | |||||
WORKDIR ${BUILD_PREFIX} | |||||
RUN cd ${BUILD_PREFIX} \ | |||||
curl \ | |||||
&& rm -rf /var/lib/apt/lists/* \ | |||||
&& export BUILD_GITHUB_TAG=${CHATGPT_ON_WECHAT_VER:-`curl -sL "https://api.github.com/repos/zhayujie/chatgpt-on-wechat/releases/latest" | \ | |||||
grep '"tag_name":' | \ | |||||
sed -E 's/.*"([^"]+)".*/\1/'`} \ | |||||
&& wget -t 3 -T 30 -nv -O chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
https://github.com/zhayujie/chatgpt-on-wechat/archive/refs/tags/${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& tar -xzf chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& mv chatgpt-on-wechat-${BUILD_GITHUB_TAG} ${BUILD_PREFIX} \ | |||||
&& rm chatgpt-on-wechat-${BUILD_GITHUB_TAG}.tar.gz \ | |||||
&& cd ${BUILD_PREFIX} \ | |||||
&& cp config-template.json ${BUILD_PREFIX}/config.json \ | && cp config-template.json ${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 --no-cache --upgrade pip \ | |||||
&& sed -i "2s/YOUR API KEY/${BUILD_OPEN_AI_API_KEY}/" ${BUILD_PREFIX}/config.json \ | |||||
&& /usr/local/bin/python -m pip install --no-cache --upgrade pip \ | |||||
&& pip install --no-cache \ | && pip install --no-cache \ | ||||
itchat-uos==1.5.0.dev0 \ | |||||
openai \ | |||||
wechaty | |||||
itchat-uos==1.5.0.dev0 \ | |||||
openai | |||||
ADD ./entrypoint.sh /entrypoint.sh | |||||
WORKDIR ${BUILD_PREFIX} | |||||
RUN chmod +x /entrypoint.sh | |||||
ADD ./entrypoint.sh /entrypoint.sh | |||||
RUN groupadd -r noroot \ | |||||
&& useradd -r -g noroot -s /bin/bash -d /home/noroot noroot \ | |||||
&& chown -R noroot:noroot ${BUILD_PREFIX} | |||||
RUN chmod +x /entrypoint.sh \ | |||||
&& groupadd -r noroot \ | |||||
&& useradd -r -g noroot -s /bin/bash -d /home/noroot noroot \ | |||||
&& chown -R noroot:noroot ${BUILD_PREFIX} | |||||
USER noroot | USER noroot | ||||
@@ -1,10 +1,15 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
CHATGPT_ON_WECHAT_TAG=1.0.2 | |||||
# fetch latest release tag | |||||
CHATGPT_ON_WECHAT_TAG=`curl -sL "https://api.github.com/repos/zhayujie/chatgpt-on-wechat/releases/latest" | \ | |||||
grep '"tag_name":' | \ | |||||
sed -E 's/.*"([^"]+)".*/\1/'` | |||||
# build image | |||||
docker build -f Dockerfile.alpine \ | docker build -f Dockerfile.alpine \ | ||||
--build-arg CHATGPT_ON_WECHAT_VER=$CHATGPT_ON_WECHAT_TAG \ | --build-arg CHATGPT_ON_WECHAT_VER=$CHATGPT_ON_WECHAT_TAG \ | ||||
-t zhayujie/chatgpt-on-wechat . | -t zhayujie/chatgpt-on-wechat . | ||||
# tag image | |||||
docker tag zhayujie/chatgpt-on-wechat zhayujie/chatgpt-on-wechat:$CHATGPT_ON_WECHAT_TAG-alpine | docker tag zhayujie/chatgpt-on-wechat zhayujie/chatgpt-on-wechat:$CHATGPT_ON_WECHAT_TAG-alpine | ||||
@@ -1,9 +1,14 @@ | |||||
#!/bin/bash | #!/bin/bash | ||||
CHATGPT_ON_WECHAT_TAG=1.0.2 | |||||
# fetch latest release tag | |||||
CHATGPT_ON_WECHAT_TAG=`curl -sL "https://api.github.com/repos/zhayujie/chatgpt-on-wechat/releases/latest" | \ | |||||
grep '"tag_name":' | \ | |||||
sed -E 's/.*"([^"]+)".*/\1/'` | |||||
# build image | |||||
docker build -f Dockerfile.debian \ | docker build -f Dockerfile.debian \ | ||||
--build-arg CHATGPT_ON_WECHAT_VER=$CHATGPT_ON_WECHAT_TAG \ | --build-arg CHATGPT_ON_WECHAT_VER=$CHATGPT_ON_WECHAT_TAG \ | ||||
-t zhayujie/chatgpt-on-wechat . | -t zhayujie/chatgpt-on-wechat . | ||||
# tag image | |||||
docker tag zhayujie/chatgpt-on-wechat zhayujie/chatgpt-on-wechat:$CHATGPT_ON_WECHAT_TAG-debian | docker tag zhayujie/chatgpt-on-wechat zhayujie/chatgpt-on-wechat:$CHATGPT_ON_WECHAT_TAG-debian |
@@ -8,11 +8,12 @@ services: | |||||
container_name: sample-chatgpt-on-wechat | container_name: sample-chatgpt-on-wechat | ||||
environment: | environment: | ||||
OPEN_AI_API_KEY: 'YOUR API KEY' | OPEN_AI_API_KEY: 'YOUR API KEY' | ||||
WECHATY_PUPPET_SERVICE_TOKEN: 'WECHATY PUPPET SERVICE TOKEN' | |||||
OPEN_AI_PROXY: '' | |||||
SINGLE_CHAT_PREFIX: '["bot", "@bot"]' | SINGLE_CHAT_PREFIX: '["bot", "@bot"]' | ||||
SINGLE_CHAT_REPLY_PREFIX: '"[bot] "' | SINGLE_CHAT_REPLY_PREFIX: '"[bot] "' | ||||
GROUP_CHAT_PREFIX: '["@bot"]' | GROUP_CHAT_PREFIX: '["@bot"]' | ||||
GROUP_NAME_WHITE_LIST: '["ChatGPT测试群", "ChatGPT测试群2"]' | GROUP_NAME_WHITE_LIST: '["ChatGPT测试群", "ChatGPT测试群2"]' | ||||
IMAGE_CREATE_PREFIX: '["画", "看", "找"]' | IMAGE_CREATE_PREFIX: '["画", "看", "找"]' | ||||
CONVERSATION_MAX_TOKENS: 1000 | CONVERSATION_MAX_TOKENS: 1000 | ||||
CHARACTER_DESC: '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。' | |||||
CHARACTER_DESC: '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。' | |||||
EXPIRES_IN_SECONDS: 3600 |
@@ -9,6 +9,7 @@ CHATGPT_ON_WECHAT_CONFIG_PATH=${CHATGPT_ON_WECHAT_CONFIG_PATH:-""} | |||||
CHATGPT_ON_WECHAT_EXEC=${CHATGPT_ON_WECHAT_EXEC:-""} | CHATGPT_ON_WECHAT_EXEC=${CHATGPT_ON_WECHAT_EXEC:-""} | ||||
OPEN_AI_API_KEY=${OPEN_AI_API_KEY:-""} | OPEN_AI_API_KEY=${OPEN_AI_API_KEY:-""} | ||||
OPEN_AI_PROXY=${OPEN_AI_PROXY:-""} | |||||
SINGLE_CHAT_PREFIX=${SINGLE_CHAT_PREFIX:-""} | SINGLE_CHAT_PREFIX=${SINGLE_CHAT_PREFIX:-""} | ||||
SINGLE_CHAT_REPLY_PREFIX=${SINGLE_CHAT_REPLY_PREFIX:-""} | SINGLE_CHAT_REPLY_PREFIX=${SINGLE_CHAT_REPLY_PREFIX:-""} | ||||
GROUP_CHAT_PREFIX=${GROUP_CHAT_PREFIX:-""} | GROUP_CHAT_PREFIX=${GROUP_CHAT_PREFIX:-""} | ||||
@@ -16,6 +17,7 @@ GROUP_NAME_WHITE_LIST=${GROUP_NAME_WHITE_LIST:-""} | |||||
IMAGE_CREATE_PREFIX=${IMAGE_CREATE_PREFIX:-""} | IMAGE_CREATE_PREFIX=${IMAGE_CREATE_PREFIX:-""} | ||||
CONVERSATION_MAX_TOKENS=${CONVERSATION_MAX_TOKENS:-""} | CONVERSATION_MAX_TOKENS=${CONVERSATION_MAX_TOKENS:-""} | ||||
CHARACTER_DESC=${CHARACTER_DESC:-""} | CHARACTER_DESC=${CHARACTER_DESC:-""} | ||||
EXPIRES_IN_SECONDS=${EXPIRES_IN_SECONDS:-""} | |||||
# CHATGPT_ON_WECHAT_PREFIX is empty, use /app | # CHATGPT_ON_WECHAT_PREFIX is empty, use /app | ||||
if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then | if [ "$CHATGPT_ON_WECHAT_PREFIX" == "" ] ; then | ||||
@@ -39,10 +41,13 @@ else | |||||
echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m" | echo -e "\033[31m[Warning] You need to set OPEN_AI_API_KEY before running!\033[0m" | ||||
fi | fi | ||||
if [ "$WECHATY_PUPPET_SERVICE_TOKEN" != "" ] ; then | |||||
sed -i "3c \"wechaty_puppet_service_token\": \"$WECHATY_PUPPET_SERVICE_TOKEN\"," $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
else | |||||
echo -e "\033[31m[Info] You need to set WECHATY_PUPPET_SERVICE_TOKEN if you use wechaty!\033[0m" | |||||
# use http_proxy as default | |||||
if [ "$HTTP_PROXY" != "" ] ; then | |||||
sed -i "3c \"proxy\": \"$HTTP_PROXY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
fi | |||||
if [ "$OPEN_AI_PROXY" != "" ] ; then | |||||
sed -i "3c \"proxy\": \"$OPEN_AI_PROXY\"," $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
fi | fi | ||||
if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then | if [ "$SINGLE_CHAT_PREFIX" != "" ] ; then | ||||
@@ -70,7 +75,11 @@ if [ "$CONVERSATION_MAX_TOKENS" != "" ] ; then | |||||
fi | fi | ||||
if [ "$CHARACTER_DESC" != "" ] ; then | if [ "$CHARACTER_DESC" != "" ] ; then | ||||
sed -i "10c \"character_desc\": \"$CHARACTER_DESC\"" $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
sed -i "10c \"character_desc\": \"$CHARACTER_DESC\"," $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
fi | |||||
if [ "$EXPIRES_IN_SECONDS" != "" ] ; then | |||||
sed -i "11c \"expires_in_seconds\": $EXPIRES_IN_SECONDS" $CHATGPT_ON_WECHAT_CONFIG_PATH | |||||
fi | fi | ||||
# go to prefix dir | # go to prefix dir | ||||
@@ -1,5 +1,5 @@ | |||||
OPEN_AI_API_KEY=YOUR API KEY | OPEN_AI_API_KEY=YOUR API KEY | ||||
WECHATY_PUPPET_SERVICE_TOKEN=WECHATY PUPPET SERVICE TOKEN | |||||
OPEN_AI_PROXY= | |||||
SINGLE_CHAT_PREFIX=["bot", "@bot"] | SINGLE_CHAT_PREFIX=["bot", "@bot"] | ||||
SINGLE_CHAT_REPLY_PREFIX="[bot] " | SINGLE_CHAT_REPLY_PREFIX="[bot] " | ||||
GROUP_CHAT_PREFIX=["@bot"] | GROUP_CHAT_PREFIX=["@bot"] | ||||
@@ -7,6 +7,7 @@ GROUP_NAME_WHITE_LIST=["ChatGPT测试群", "ChatGPT测试群2"] | |||||
IMAGE_CREATE_PREFIX=["画", "看", "找"] | IMAGE_CREATE_PREFIX=["画", "看", "找"] | ||||
CONVERSATION_MAX_TOKENS=1000 | CONVERSATION_MAX_TOKENS=1000 | ||||
CHARACTER_DESC=你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。 | CHARACTER_DESC=你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。 | ||||
EXPIRES_IN_SECONDS=3600 | |||||
# Optional | # Optional | ||||
#CHATGPT_ON_WECHAT_PREFIX=/app | #CHATGPT_ON_WECHAT_PREFIX=/app | ||||