Skip to content

Commit

Permalink
✨ feat: 增加Docker支持
Browse files Browse the repository at this point in the history
编译: build # docker build --pull --rm -f "Dockerfile" -t localcodeinterpreter:latest "."
运行:run # docker run   --rm -it  -e OPENAI_API_KEY=<youApikey> -p 7860:7860 localcodeinterpreter
  • Loading branch information
a3305 committed Sep 28, 2023
1 parent 62370dd commit 080498e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
30 changes: 27 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +69,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A
```shell
pip install -r requirements_full.txt
```
### 配置
#### 配置

1.`src`目录中创建一个`config.json`文件,参照`config_example`目录中提供的示例进行配置。

Expand Down Expand Up @@ -82,7 +106,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A
export OPENAI_API_KEY=<你的API密钥>
```

## 使用
#### 运行

1. 进入`src`目录。
```shell
Expand Down
13 changes: 4 additions & 9 deletions src/bot_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/web_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 080498e

Please sign in to comment.