From 2fe283d304f5c34d3b3d78fb5ba0c3c0ab23d8de Mon Sep 17 00:00:00 2001 From: wujiyu115 Date: Mon, 27 Mar 2023 17:20:32 +0800 Subject: [PATCH] update docker image add openai api_base update api base update chatgpt add api_base update chatgpt add api_base --- .github/workflows/docker-image.yaml | 45 +++++++++++++++++++++++++++++ Dockerfile | 11 +++++++ config-template.json | 1 + model/openai/chatgpt_model.py | 6 +++- model/openai/open_ai_model.py | 5 ++++ requirements.txt | 4 +++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-image.yaml create mode 100644 Dockerfile create mode 100644 requirements.txt diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml new file mode 100644 index 0000000..be63c25 --- /dev/null +++ b/.github/workflows/docker-image.yaml @@ -0,0 +1,45 @@ +# docker-image.yml +name: Publish Docker image + +on: + push: + branches: # master分支有push时触发此workflow + - 'master' + tags: # tag更新时触发此workflow + - '*' + +jobs: + + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + + steps: + - name: Check out the repo + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} # 配置dockerhub的认证,在Github项目主页 【Settings】 -> 【Secrets】 添加对应变量 + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - uses: jungwinter/split@v2 + id: split + with: + msg: ${{ github.repository }} + separator: "/" + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.split.outputs._1 }} #dockerhub用户名/仓库名 + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + file: Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2b2cc6b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.7-alpine + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "app.py"] diff --git a/config-template.json b/config-template.json index 58fa42a..e494383 100644 --- a/config-template.json +++ b/config-template.json @@ -3,6 +3,7 @@ "type" : "chatgpt", "openai": { "api_key": "YOUR API KEY", + "api_base": "https://api.xxx.com/v1", "model": "gpt-3.5-turbo", "proxy": "", "conversation_max_tokens": 1000, diff --git a/model/openai/chatgpt_model.py b/model/openai/chatgpt_model.py index 9880888..333d2c8 100644 --- a/model/openai/chatgpt_model.py +++ b/model/openai/chatgpt_model.py @@ -13,10 +13,14 @@ user_session = dict() class ChatGPTModel(Model): def __init__(self): openai.api_key = model_conf(const.OPEN_AI).get('api_key') + api_base = model_conf(const.OPEN_AI).get('api_base') + if api_base: + openai.api_base = api_base proxy = model_conf(const.OPEN_AI).get('proxy') if proxy: openai.proxy = proxy - + log.info("[CHATGPT] api_base={} proxy={}".format( + api_base, proxy)) def reply(self, query, context=None): # acquire reply content if not context or not context.get('type') or context.get('type') == 'TEXT': diff --git a/model/openai/open_ai_model.py b/model/openai/open_ai_model.py index 21a77c9..d514f0e 100644 --- a/model/openai/open_ai_model.py +++ b/model/openai/open_ai_model.py @@ -13,6 +13,11 @@ user_session = dict() class OpenAIModel(Model): def __init__(self): openai.api_key = model_conf(const.OPEN_AI).get('api_key') + api_base = model_conf(const.OPEN_AI).get('api_base') + if api_base: + openai.api_base = api_base + proxy = model_conf(const.OPEN_AI).get('proxy') + log.info("[OPEN_AI] api_base={}".format(openai.api_base)) def reply(self, query, context=None): diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..57a56a2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +PyJWT +flask +itchat-uos==1.5.0.dev0 +openai \ No newline at end of file