diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..aff53d0 --- /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: zh3305/localcodeinterpreter:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c71bc86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# 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 + +# 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 + +# Run web_ui.py when the container launches +CMD ["python", "web_ui.py"] 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 81a7fd6..ab94f1e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -17,12 +17,56 @@ 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 -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 "." +``` + + + +### 手动部署 + +#### 安装 1. 克隆本仓库 ```shell @@ -38,6 +82,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A ``` 其他系统或库版本也可能有效。 您可以使用以下命令直接安装所需的软件包: + ```shell pip install -r requirements.txt ``` @@ -45,7 +90,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A ```shell pip install -r requirements_full.txt ``` -### 配置 +#### 配置 1. 在`src`目录中创建一个`config.json`文件,参照`config_example`目录中提供的示例进行配置。 @@ -82,7 +127,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):