From 080498e3abbf3b36479131b6809b056e206e2d88 Mon Sep 17 00:00:00 2001 From: zh3305 Date: Wed, 27 Sep 2023 15:05:41 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=A2=9E=E5=8A=A0Docke?= =?UTF-8?q?r=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") From f4cb22ff18323c626cdf3019108e7ac3fb27ce88 Mon Sep 17 00:00:00 2001 From: XiangYang <1029589450@qq.com> Date: Thu, 28 Sep 2023 17:25:21 +0800 Subject: [PATCH 2/6] Create docker-image.yml --- .github/workflows/docker-image.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..589b52e --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,26 @@ +name: Docker Build and Push + +on: + push: + branches: + - main + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: zh3395/localcodeinterpreter:latest From c5174694c1e91da436d722a75397389702546525 Mon Sep 17 00:00:00 2001 From: XiangYang <1029589450@qq.com> Date: Thu, 28 Sep 2023 17:28:23 +0800 Subject: [PATCH 3/6] Update docker-image.yml --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 589b52e..aff53d0 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -23,4 +23,4 @@ jobs: with: context: . push: true - tags: zh3395/localcodeinterpreter:latest + tags: zh3305/localcodeinterpreter:latest From 1265aee2b8a5cc94eb0c9e503144f38b98f6a207 Mon Sep 17 00:00:00 2001 From: zh3305 Date: Thu, 28 Sep 2023 18:03:08 +0800 Subject: [PATCH 4/6] update README.md and README_CN.md --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++--- README_CN.md | 43 ++++++++++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 413263b..25428d5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,45 @@ Executing AI-generated code without human review on your own device is not safe. ## Usage -### Installation +### Run in Docker + +#### Directly run + +```bash +docker run -it --rm -e OPENAI_API_KEY=youOpenApiKey -p 7860:7860 zh3305/localcodeinterpreter:latest +``` + +##### Environment variables + +### `OPENAI_API_KEY` + +API key + +### `INTERPETER_API_TYPE` + +Default is `open_ai` + +### `INTERPETER_API_BASE` + +API access address, default is `https://api.openai.com/v1`, can use reverse proxy address, such as the proxy interface address provided by ChatGPT Next Web `https://chatgpt2.nextweb.fun/api/proxy/v1` + +### `INTERPETER_API_VERSION` + +If you use Azure OpenAI service, set it to `2023-07-01-preview`, other API versions do not support function calls. + +### `http_proxy`, `https_proxy` + +Proxy server address, can set the accessed proxy server. For example: -e http_proxy=http://192.168.1.10:11992 `http proxy address` -e https_proxy=http://192.168.1.10:11992 `https proxy address` + + +#### Manually build Docker image + +```bash +docker build --pull --rm -f "Dockerfile" -t localcodeinterpreter:latest "." +``` +### Manual deployment + +#### Installation 1. Clone this repository to your local device ```shell @@ -45,7 +83,7 @@ Executing AI-generated code without human review on your own device is not safe. ```shell pip install -r requirements_full.txt ``` -### Configuration +#### Configuration 1. Create a `config.json` file in the `src` directory, following the examples provided in the `config_example` directory. @@ -82,7 +120,7 @@ Please Note: export OPENAI_API_KEY= ``` -## Getting Started +#### Getting Started 1. Navigate to the `src` directory. ```shell diff --git a/README_CN.md b/README_CN.md index 0e6f0eb..ab94f1e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -29,17 +29,37 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A #### 直接运行 ```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 +docker run -it --rm -e OPENAI_API_KEY=youOpenApiKey -p 7860:7860 zh3305/localcodeinterpreter:latest +``` + +##### 环境变量 + +### `OPENAI_API_KEY` + +API密钥 + +### `INTERPETER_API_TYPE` + +默认为 `open_ai` + +### `INTERPETER_API_BASE` + +Api访问地址,默认为 `https://api.openai.com/v1` ,可使用反向代理地址,如ChatGPT Next Web提供的代理接口地址 `https://chatgpt2.nextweb.fun/api/proxy/v1` + +### `INTERPETER_API_VERSION` + +如果您使用Azure OpenAI服务,请在`设置为`2023-07-01-preview`,其他API版本不支持函数调用。 + +### `http_proxy`, `https_proxy` + +代理服务器地址,可设置访问的代理服务器 如: -e http_proxy=http://192.168.1.10:11992 `http代理地址` -e https_proxy=http://192.168.1.10:11992 `https代理地址` + + + +#### 手动编译Docker镜像 + +```bash +docker build --pull --rm -f "Dockerfile" -t localcodeinterpreter:latest "." ``` @@ -62,6 +82,7 @@ localcodeinterpreter ``` 其他系统或库版本也可能有效。 您可以使用以下命令直接安装所需的软件包: + ```shell pip install -r requirements.txt ``` From 7a75c69b54838c9ca95cfd25d7d1461f9f938915 Mon Sep 17 00:00:00 2001 From: zh3305 Date: Thu, 28 Sep 2023 18:16:07 +0800 Subject: [PATCH 5/6] update web_ui.py --- src/web_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web_ui.py b/src/web_ui.py index 1fb9668..e5df941 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=False,server_port=7860,server_name="0.0.0.0") + block.launch(inbrowser=True) From b87f53f6323a688e2037d187320fe983e1ad493b Mon Sep 17 00:00:00 2001 From: zh3305 Date: Thu, 28 Sep 2023 18:19:06 +0800 Subject: [PATCH 6/6] build: update Dockerfile --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4a9afaa..c71bc86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,12 +12,16 @@ 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的值 +# change config.json API_KEY value to empty string # RUN sed -i 's/\"API_KEY\": \".*\"/\"API_KEY\": \"\"/' /app/src/config.json # Change into the cloned repository WORKDIR /app/src + +ENV GRADIO_SERVER_NAME=0.0.0.0 +ENV GRADIO_SERVER_PORT=7860 + # Make port 7860 available to the world outside this container EXPOSE 7860