Skip to content

Commit 02fb09c

Browse files
committed
✨ feat: 增加Docker支持
编译: build # docker build --pull --rm -f "Dockerfile" -t localcodeinterpreter:latest "." 运行:run # docker run --rm -it -e OPENAI_API_KEY=<youApikey> -p 7860:7860 localcodeinterpreter
1 parent 62370dd commit 02fb09c

4 files changed

Lines changed: 57 additions & 13 deletions

File tree

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.9.16
3+
4+
# Set the working directory in the container to /app
5+
WORKDIR /app
6+
7+
# Add the current directory contents into the container at /app
8+
ADD . /app
9+
10+
# Install any needed packages specified in requirements.txt
11+
RUN pip install --no-cache-dir -r requirements_full.txt
12+
# Copy the config.example.json to src/config.json
13+
RUN cp /app/config_example/config.example.json /app/src/config.json
14+
15+
# 使用sed命令更改API_KEY的值
16+
RUN sed -i 's/\"API_KEY\": \".*\"/\"API_KEY\": \"\"/' /app/src/config.json
17+
18+
# Change into the cloned repository
19+
WORKDIR /app/src
20+
21+
# Make port 7860 available to the world outside this container
22+
EXPOSE 7860
23+
24+
# Run web_ui.py when the container launches
25+
CMD ["python", "web_ui.py"]

README_CN.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,36 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A
1717

1818
- **数据更安全**:代码在本地运行,无需将文件上传至网络,提高了数据的安全性。
1919

20+
- **[open-interpreter](https://github.com/KillianLucas/open-interpreter/tree/main)**:相对于open-interpreter有更小的Token使用量,在GPT-3.5模型下有更好的效果.
21+
2022
## 注意事项
2123
在您自己的设备上执行AI生成但未经人工审核的代码可能存在安全风险。在运行此程序前,您应当采用一些安全措施,例如使用虚拟机,以保护您的设备和数据。使用此程序所产生的所有后果,您需自行承担。
2224

2325
## 使用方法
2426

25-
### 安装
27+
### 在Docker中运行
28+
29+
#### 直接运行
30+
31+
```bash
32+
docker run
33+
--rm
34+
-it
35+
-e OPENAI_API_base=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 `API key`
36+
-e INTERPETER_API_TYPE="open_ai" `API_TYPE`
37+
-e INTERPETER_API_BASE=https://chatgpt2.nextweb.fun/api/proxy/v1 `API 访问地址`
38+
-e INTERPETER_API_VERSION="" `API_VERSION`
39+
-e http_proxy=http://192.168.1.10:11992 `http代理地址`
40+
-e https_proxy=http://192.168.1.10:11992 `https代理地址`
41+
-p 7860:7860 `#Web访问端口`
42+
localcodeinterpreter
43+
```
44+
45+
46+
47+
### 手动部署
48+
49+
#### 安装
2650

2751
1. 克隆本仓库
2852
```shell
@@ -45,7 +69,7 @@ OpenAI的ChatGPT代码解释器(Code Interpreter,现更名为Advanced Data A
4569
```shell
4670
pip install -r requirements_full.txt
4771
```
48-
### 配置
72+
#### 配置
4973

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

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

85-
## 使用
109+
#### 运行
86110

87111
1. 进入`src`目录。
88112
```shell

src/bot_backend.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
with open('config.json') as f:
4141
config = json.load(f)
4242

43-
if not config['API_KEY']:
44-
config['API_KEY'] = os.getenv('OPENAI_API_KEY')
45-
os.unsetenv('OPENAI_API_KEY')
46-
47-
4843
def get_config():
4944
return config
5045

@@ -127,10 +122,10 @@ def _init_conversation(self):
127122

128123
def _init_api_config(self):
129124
self.config = get_config()
130-
api_type = self.config['API_TYPE']
131-
api_base = self.config['API_base']
132-
api_version = self.config['API_VERSION']
133-
api_key = config['API_KEY']
125+
api_type =os.getenv("INTERPETER_API_TYPE", self.config['API_TYPE'] )
126+
api_base =os.getenv('INTERPETER_API_BASE',self.config['API_base'])
127+
api_version = os.getenv('INTERPETER_API_VERSION',self.config['API_VERSION'] )
128+
api_key = os.getenv('OPENAI_API_KEY',self.config['API_KEY'])
134129
config_openai_api(api_type, api_base, api_version, api_key)
135130

136131
def _init_kwargs_for_chat_completion(self):

src/web_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ def bot(state_dict: Dict, history: List) -> List:
182182
block.load(fn=initialization, inputs=[state])
183183

184184
block.queue()
185-
block.launch(inbrowser=True)
185+
block.launch(inbrowser=False,server_port=7860,server_name="0.0.0.0")

0 commit comments

Comments
 (0)