From 080498e3abbf3b36479131b6809b056e206e2d88 Mon Sep 17 00:00:00 2001 From: zh3305 Date: Wed, 27 Sep 2023 15:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0Docker?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 编译: build # docker build --pull --rm -f "Dockerfile" -t localcodeinterpreter:latest "." 运行:run # docker run --rm -it -e OPENAI_API_KEY= -p 7860:7860 localcodeinterpreter --- Dockerfile | 25 +++++++++++++++++++++++++ README_CN.md | 30 +++++++++++++++++++++++++++--- src/bot_backend.py | 13 ++++--------- src/web_ui.py | 2 +- 4 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4a9afaa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Use an official Python runtime as a parent image +FROM python:3.9.16 + +# Set the working directory in the container to /app +WORKDIR /app + +# Add the current directory contents into the container at /app +ADD . /app + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements_full.txt +# Copy the config.example.json to src/config.json +RUN cp /app/config_example/config.example.json /app/src/config.json + +# 使用sed命令更改API_KEY的值 +# RUN sed -i 's/\"API_KEY\": \".*\"/\"API_KEY\": \"\"/' /app/src/config.json + +# Change into the cloned repository +WORKDIR /app/src + +# Make port 7860 available to the world outside this container +EXPOSE 7860 + +# Run web_ui.py when the container launches +CMD ["python", "web_ui.py"] diff --git a/README_CN.md b/README_CN.md index 81a7fd6..0e6f0eb 100644 --- a/README_CN.md +++ b/README_CN.md @@ -17,12 +17,36 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A - **数据更安全**:代码在本地运行,无需将文件上传至网络,提高了数据的安全性。 +- **[open-interpreter](https://github.com/KillianLucas/open-interpreter/tree/main)**:相对于open-interpreter有更小的Token使用量,在GPT-3.5模型下有更好的效果. + ## 注意事项 在您自己的设备上执行AI生成但未经人工审核的代码可能存在安全风险。在运行此程序前,您应当采用一些安全措施,例如使用虚拟机,以保护您的设备和数据。使用此程序所产生的所有后果,您需自行承担。 ## 使用方法 -### 安装 +### 在Docker中运行 + +#### 直接运行 + +```bash +docker run +--rm +-it +-e OPENAI_API_base=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 `API key` +-e INTERPETER_API_TYPE="open_ai" `API_TYPE` +-e INTERPETER_API_BASE=https://chatgpt2.nextweb.fun/api/proxy/v1 `API 访问地址` +-e INTERPETER_API_VERSION="" `API_VERSION` +-e http_proxy=http://192.168.1.10:11992 `http代理地址` +-e https_proxy=http://192.168.1.10:11992 `https代理地址` +-p 7860:7860 `#Web访问端口` +localcodeinterpreter +``` + + + +### 手动部署 + +#### 安装 1. 克隆本仓库 ```shell @@ -45,7 +69,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A ```shell pip install -r requirements_full.txt ``` -### 配置 +#### 配置 1. 在`src`目录中创建一个`config.json`文件,参照`config_example`目录中提供的示例进行配置。 @@ -82,7 +106,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A export OPENAI_API_KEY=<你的API密钥> ``` -## 使用 +#### 运行 1. 进入`src`目录。 ```shell diff --git a/src/bot_backend.py b/src/bot_backend.py index 4620a73..63e09ef 100644 --- a/src/bot_backend.py +++ b/src/bot_backend.py @@ -40,11 +40,6 @@ with open('config.json') as f: config = json.load(f) -if not config['API_KEY']: - config['API_KEY'] = os.getenv('OPENAI_API_KEY') - os.unsetenv('OPENAI_API_KEY') - - def get_config(): return config @@ -127,10 +122,10 @@ def _init_conversation(self): def _init_api_config(self): self.config = get_config() - api_type = self.config['API_TYPE'] - api_base = self.config['API_base'] - api_version = self.config['API_VERSION'] - api_key = config['API_KEY'] + api_type =os.getenv("INTERPETER_API_TYPE", self.config['API_TYPE'] ) + api_base =os.getenv('INTERPETER_API_BASE',self.config['API_base']) + api_version = os.getenv('INTERPETER_API_VERSION',self.config['API_VERSION'] ) + api_key = os.getenv('OPENAI_API_KEY',self.config['API_KEY']) config_openai_api(api_type, api_base, api_version, api_key) def _init_kwargs_for_chat_completion(self): diff --git a/src/web_ui.py b/src/web_ui.py index e5df941..1fb9668 100644 --- a/src/web_ui.py +++ b/src/web_ui.py @@ -182,4 +182,4 @@ def bot(state_dict: Dict, history: List) -> List: block.load(fn=initialization, inputs=[state]) block.queue() - block.launch(inbrowser=True) + block.launch(inbrowser=False,server_port=7860,server_name="0.0.0.0")