Wendong-Fan commited on
Commit
d83de9d
·
2 Parent(s): d3bd7a8 f82f658

修复 | 语法错误,中文乱码 (#156)

Browse files
.container/build_docker.bat CHANGED
@@ -1,14 +1,18 @@
1
  @echo off
 
2
  setlocal enabledelayedexpansion
3
 
4
- echo 在Windows上构建Docker镜像... | Building Docker image on Windows...
 
5
 
6
- REM 设置配置变量 | Set configuration variables
 
7
  set CACHE_DIR=.docker-cache\pip
8
  set BUILD_ARGS=--build-arg BUILDKIT_INLINE_CACHE=1
9
  set COMPOSE_FILE=docker-compose.yml
10
 
11
- REM 解析命令行参数 | Parse command line arguments
 
12
  set CLEAN_CACHE=0
13
  set REBUILD=0
14
  set SERVICE=
@@ -32,80 +36,106 @@ if /i "%~1"=="--service" (
32
  goto :parse_args
33
  )
34
  if /i "%~1"=="--help" (
35
- echo 用法 | Usage: build_docker.bat [选项 | options]
36
- echo 选项 | Options:
37
- echo --clean 清理缓存目录 | Clean cache directory
38
- echo --rebuild 强制重新构建镜像 | Force rebuild image
39
- echo --service 指定要构建的服务名称 | Specify service name to build
40
- echo --help 显示此帮助信息 | Show this help message
 
 
 
 
 
 
41
  exit /b 0
42
  )
43
  shift
44
  goto :parse_args
45
  :end_parse_args
46
 
47
- REM 检查Docker是否安装 | Check if Docker is installed
 
48
  where docker >nul 2>nul
49
  if %ERRORLEVEL% NEQ 0 (
50
- echo 错误 | Error: Docker未安装 | Docker not installed
51
- echo 请先安装Docker Desktop | Please install Docker Desktop first: https://docs.docker.com/desktop/install/windows-install/
 
 
52
  pause
53
  exit /b 1
54
  )
55
 
56
- REM 检查Docker是否运行 | Check if Docker is running
 
57
  docker info >nul 2>nul
58
  if %ERRORLEVEL% NEQ 0 (
59
- echo 错误 | Error: Docker未运行 | Docker not running
60
- echo 请启动Docker Desktop应用程序 | Please start Docker Desktop application
 
 
61
  pause
62
  exit /b 1
63
  )
64
 
65
- REM 检查docker-compose.yml文件是否存在 | Check if docker-compose.yml file exists
 
66
  if not exist "%COMPOSE_FILE%" (
67
- echo 错误 | Error: 未找到%COMPOSE_FILE%文件 | %COMPOSE_FILE% file not found
68
- echo 请确保在正确的目录中运行此脚本 | Please make sure you are running this script in the correct directory
 
 
69
  pause
70
  exit /b 1
71
  )
72
 
73
- REM 检查Docker Compose命令 | Check Docker Compose command
 
74
  where docker-compose >nul 2>nul
75
  if %ERRORLEVEL% EQU 0 (
76
  set COMPOSE_CMD=docker-compose
77
  ) else (
78
- echo 尝试使用新的docker compose命令... | Trying to use new docker compose command...
 
79
  docker compose version >nul 2>nul
80
  if %ERRORLEVEL% EQU 0 (
81
  set COMPOSE_CMD=docker compose
82
  ) else (
83
- echo 错误 | Error: 未找到Docker Compose命令 | Docker Compose command not found
84
- echo 请确保Docker Desktop已正确安装 | Please make sure Docker Desktop is properly installed
 
 
85
  pause
86
  exit /b 1
87
  )
88
  )
89
 
90
- REM 设置Docker BuildKit环境变量 | Set Docker BuildKit environment variables
 
91
  set DOCKER_BUILDKIT=1
92
  set COMPOSE_DOCKER_CLI_BUILD=1
93
 
94
- echo 启用Docker BuildKit加速构建... | Enabling Docker BuildKit to accelerate build...
 
95
 
96
- REM 清理缓存(如果指定) | Clean cache (if specified)
 
97
  if %CLEAN_CACHE% EQU 1 (
98
- echo 清理缓存目录... | Cleaning cache directory...
 
99
  if exist "%CACHE_DIR%" rmdir /s /q "%CACHE_DIR%"
100
  )
101
 
102
- REM 创建缓存目录 | Create cache directory
 
103
  if not exist "%CACHE_DIR%" (
104
- echo 创建缓存目录... | Creating cache directory...
 
105
  mkdir "%CACHE_DIR%"
106
  )
107
 
108
- REM 添加构建时间标记 | Add build time tag
 
109
  for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
110
  set "YEAR=%dt:~0,4%"
111
  set "MONTH=%dt:~4,2%"
@@ -115,33 +145,42 @@ set "MINUTE=%dt:~10,2%"
115
  set "BUILD_TIME=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%"
116
  set "BUILD_ARGS=%BUILD_ARGS% --build-arg BUILD_TIME=%BUILD_TIME%"
117
 
118
- REM 构建Docker镜像 | Build Docker image
119
- echo 开始构建Docker镜像... | Starting to build Docker image...
 
 
120
 
121
  if "%SERVICE%"=="" (
122
  if %REBUILD% EQU 1 (
123
- echo 强制重新构建所有服务... | Force rebuilding all services...
 
124
  %COMPOSE_CMD% build --no-cache %BUILD_ARGS%
125
  ) else (
126
  %COMPOSE_CMD% build %BUILD_ARGS%
127
  )
128
  ) else (
129
  if %REBUILD% EQU 1 (
130
- echo 强制重新构建服务 %SERVICE%... | Force rebuilding service %SERVICE%...
 
131
  %COMPOSE_CMD% build --no-cache %BUILD_ARGS% %SERVICE%
132
  ) else (
133
- echo 构建服务 %SERVICE%... | Building service %SERVICE%...
 
134
  %COMPOSE_CMD% build %BUILD_ARGS% %SERVICE%
135
  )
136
  )
137
 
138
  if %ERRORLEVEL% EQU 0 (
139
- echo Docker镜像构建成功! | Docker image build successful!
140
- echo 构建时间 | Build time: %BUILD_TIME%
141
- echo 可以使用以下命令启动容器: | You can use the following command to start the container:
 
 
 
142
  echo %COMPOSE_CMD% up -d
143
  ) else (
144
- echo Docker镜像构建失败,请检查错误信息。 | Docker image build failed, please check error messages.
 
145
  )
146
 
147
  pause
 
1
  @echo off
2
+ chcp 65001 >nul
3
  setlocal enabledelayedexpansion
4
 
5
+ echo 在Windows上构建Docker镜像...
6
+ echo Building Docker image on Windows...
7
 
8
+ REM 设置配置变量
9
+ REM Set configuration variables
10
  set CACHE_DIR=.docker-cache\pip
11
  set BUILD_ARGS=--build-arg BUILDKIT_INLINE_CACHE=1
12
  set COMPOSE_FILE=docker-compose.yml
13
 
14
+ REM 解析命令行参数
15
+ REM Parse command line arguments
16
  set CLEAN_CACHE=0
17
  set REBUILD=0
18
  set SERVICE=
 
36
  goto :parse_args
37
  )
38
  if /i "%~1"=="--help" (
39
+ echo 用法: build_docker.bat [选项]
40
+ echo Usage: build_docker.bat [options]
41
+ echo 选项:
42
+ echo Options:
43
+ echo --clean 清理缓存目录
44
+ echo --clean Clean cache directory
45
+ echo --rebuild 强制重新构建镜像
46
+ echo --rebuild Force rebuild image
47
+ echo --service 指定要构建的服务名称
48
+ echo --service Specify service name to build
49
+ echo --help 显示此帮助信息
50
+ echo --help Show this help message
51
  exit /b 0
52
  )
53
  shift
54
  goto :parse_args
55
  :end_parse_args
56
 
57
+ REM 检查Docker是否安装
58
+ REM Check if Docker is installed
59
  where docker >nul 2>nul
60
  if %ERRORLEVEL% NEQ 0 (
61
+ echo 错误: Docker未安装
62
+ echo Error: Docker not installed
63
+ echo 请先安装Docker Desktop
64
+ echo Please install Docker Desktop first: https://docs.docker.com/desktop/install/windows-install/
65
  pause
66
  exit /b 1
67
  )
68
 
69
+ REM 检查Docker是否运行
70
+ REM Check if Docker is running
71
  docker info >nul 2>nul
72
  if %ERRORLEVEL% NEQ 0 (
73
+ echo 错误: Docker未运行
74
+ echo Error: Docker not running
75
+ echo 请启动Docker Desktop应用程序
76
+ echo Please start Docker Desktop application
77
  pause
78
  exit /b 1
79
  )
80
 
81
+ REM 检查docker-compose.yml文件是否存在
82
+ REM Check if docker-compose.yml file exists
83
  if not exist "%COMPOSE_FILE%" (
84
+ echo 错误: 未找到%COMPOSE_FILE%文件
85
+ echo Error: %COMPOSE_FILE% file not found
86
+ echo 请确保在正确的目录中运行此脚本
87
+ echo Please make sure you are running this script in the correct directory
88
  pause
89
  exit /b 1
90
  )
91
 
92
+ REM 检查Docker Compose命令
93
+ REM Check Docker Compose command
94
  where docker-compose >nul 2>nul
95
  if %ERRORLEVEL% EQU 0 (
96
  set COMPOSE_CMD=docker-compose
97
  ) else (
98
+ echo 尝试使用新的docker compose命令...
99
+ echo Trying to use new docker compose command...
100
  docker compose version >nul 2>nul
101
  if %ERRORLEVEL% EQU 0 (
102
  set COMPOSE_CMD=docker compose
103
  ) else (
104
+ echo 错误: 未找到Docker Compose命令
105
+ echo Error: Docker Compose command not found
106
+ echo 请确保Docker Desktop已正确安装
107
+ echo Please make sure Docker Desktop is properly installed
108
  pause
109
  exit /b 1
110
  )
111
  )
112
 
113
+ REM 设置Docker BuildKit环境变量
114
+ REM Set Docker BuildKit environment variables
115
  set DOCKER_BUILDKIT=1
116
  set COMPOSE_DOCKER_CLI_BUILD=1
117
 
118
+ echo 启用Docker BuildKit加速构建...
119
+ echo Enabling Docker BuildKit to accelerate build...
120
 
121
+ REM 清理缓存(如果指定)
122
+ REM Clean cache (if specified)
123
  if %CLEAN_CACHE% EQU 1 (
124
+ echo 清理缓存目录...
125
+ echo Cleaning cache directory...
126
  if exist "%CACHE_DIR%" rmdir /s /q "%CACHE_DIR%"
127
  )
128
 
129
+ REM 创建缓存目录
130
+ REM Create cache directory
131
  if not exist "%CACHE_DIR%" (
132
+ echo 创建缓存目录...
133
+ echo Creating cache directory...
134
  mkdir "%CACHE_DIR%"
135
  )
136
 
137
+ REM 添加构建时间标记
138
+ REM Add build time tag
139
  for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
140
  set "YEAR=%dt:~0,4%"
141
  set "MONTH=%dt:~4,2%"
 
145
  set "BUILD_TIME=%YEAR%%MONTH%%DAY%_%HOUR%%MINUTE%"
146
  set "BUILD_ARGS=%BUILD_ARGS% --build-arg BUILD_TIME=%BUILD_TIME%"
147
 
148
+ REM 构建Docker镜像
149
+ REM Build Docker image
150
+ echo 开始构建Docker镜像...
151
+ echo Starting to build Docker image...
152
 
153
  if "%SERVICE%"=="" (
154
  if %REBUILD% EQU 1 (
155
+ echo 强制重新构建所有服务...
156
+ echo Force rebuilding all services...
157
  %COMPOSE_CMD% build --no-cache %BUILD_ARGS%
158
  ) else (
159
  %COMPOSE_CMD% build %BUILD_ARGS%
160
  )
161
  ) else (
162
  if %REBUILD% EQU 1 (
163
+ echo 强制重新构建服务 %SERVICE%...
164
+ echo Force rebuilding service %SERVICE%...
165
  %COMPOSE_CMD% build --no-cache %BUILD_ARGS% %SERVICE%
166
  ) else (
167
+ echo 构建服务 %SERVICE%...
168
+ echo Building service %SERVICE%...
169
  %COMPOSE_CMD% build %BUILD_ARGS% %SERVICE%
170
  )
171
  )
172
 
173
  if %ERRORLEVEL% EQU 0 (
174
+ echo Docker镜像构建成功!
175
+ echo Docker image build successful!
176
+ echo 构建时间: %BUILD_TIME%
177
+ echo Build time: %BUILD_TIME%
178
+ echo 可以使用以下命令启动容器:
179
+ echo You can use the following command to start the container:
180
  echo %COMPOSE_CMD% up -d
181
  ) else (
182
+ echo Docker镜像构建失败,请检查错误信息。
183
+ echo Docker image build failed, please check error messages.
184
  )
185
 
186
  pause
.container/check_docker.bat CHANGED
@@ -1,62 +1,88 @@
1
  @echo off
2
- echo 检查Docker环境... | Checking Docker environment...
 
 
3
 
4
- REM 检查Docker是否安装 | Check if Docker is installed
 
5
  where docker >nul 2>nul
6
  if %ERRORLEVEL% NEQ 0 (
7
- echo 错误 | Error: Docker未安装 | Docker not installed
8
- echo 在Windows上安装Docker的方法 | How to install Docker on Windows:
9
- echo 1. 访问 | Visit https://docs.docker.com/desktop/install/windows-install/ 下载Docker Desktop | to download Docker Desktop
10
- echo 2. 安装并启动Docker Desktop | Install and start Docker Desktop
 
 
 
 
11
  pause
12
  exit /b 1
13
  )
14
 
15
- echo Docker已安装 | Docker is installed
 
16
 
17
- REM 检查Docker Compose是否安装 | Check if Docker Compose is installed
 
18
  where docker-compose >nul 2>nul
19
  if %ERRORLEVEL% NEQ 0 (
20
- echo 警告 | Warning: Docker-Compose未找到,尝试使用新的docker compose命令 | Docker-Compose not found, trying to use new docker compose command
 
21
  docker compose version >nul 2>nul
22
  if %ERRORLEVEL% NEQ 0 (
23
- echo 错误 | Error: Docker Compose未安装 | Docker Compose not installed
24
- echo Docker Desktop for Windows应该已包含Docker Compose | Docker Desktop for Windows should already include Docker Compose
25
- echo 请确保Docker Desktop已正确安装 | Please make sure Docker Desktop is properly installed
 
 
 
26
  pause
27
  exit /b 1
28
  ) else (
29
- echo 使用新的docker compose命令 | Using new docker compose command
 
30
  set COMPOSE_CMD=docker compose
31
  )
32
  ) else (
33
- echo Docker-Compose已安装 | Docker-Compose is installed
 
34
  set COMPOSE_CMD=docker-compose
35
  )
36
 
37
- REM 检查Docker是否正在运行 | Check if Docker is running
 
38
  docker info >nul 2>nul
39
  if %ERRORLEVEL% NEQ 0 (
40
- echo 错误 | Error: Docker未运行 | Docker not running
41
- echo 请启动Docker Desktop应用程序 | Please start Docker Desktop application
 
 
42
  pause
43
  exit /b 1
44
  )
45
 
46
- echo Docker正在运行 | Docker is running
 
47
 
48
- REM 检查是否有.env文件 | Check if .env file exists
49
- if not exist "owl\.env" (
50
- echo 警告 | Warning: 未找到owl\.env文件 | owl\.env file not found
51
- echo 请运行以下命令创建环境变量文件 | Please run the following command to create environment variable file:
52
- echo copy owl\.env_template owl\.env
53
- echo 然后编辑owl\.env文件,填写必要的API密钥 | Then edit owl\.env file and fill in necessary API keys
 
 
 
 
54
  ) else (
55
- echo 环境变量文件已存在 | Environment variable file exists
 
56
  )
57
 
58
- echo 所有检查完成,您的系统已准备好构建和运行OWL项目的Docker容器 | All checks completed, your system is ready to build and run OWL project Docker container
59
- echo 请运行以下命令构建Docker镜像 | Please run the following command to build Docker image:
 
 
60
  echo %COMPOSE_CMD% build
61
 
62
  pause
 
1
  @echo off
2
+ chcp 65001 >nul
3
+ echo 检查Docker环境...
4
+ echo Checking Docker environment...
5
 
6
+ REM 检查Docker是否安装
7
+ REM Check if Docker is installed
8
  where docker >nul 2>nul
9
  if %ERRORLEVEL% NEQ 0 (
10
+ echo 错误: Docker未安装
11
+ echo Error: Docker not installed
12
+ echo 在Windows上安装Docker的方法:
13
+ echo How to install Docker on Windows:
14
+ echo 1. 访问 https://docs.docker.com/desktop/install/windows-install/ 下载Docker Desktop
15
+ echo 1. Visit https://docs.docker.com/desktop/install/windows-install/ to download Docker Desktop
16
+ echo 2. 安装并启动Docker Desktop
17
+ echo 2. Install and start Docker Desktop
18
  pause
19
  exit /b 1
20
  )
21
 
22
+ echo Docker已安装
23
+ echo Docker is installed
24
 
25
+ REM 检查Docker Compose是否安装
26
+ REM Check if Docker Compose is installed
27
  where docker-compose >nul 2>nul
28
  if %ERRORLEVEL% NEQ 0 (
29
+ echo 警告: Docker-Compose未找到,尝试使用新的docker compose命令
30
+ echo Warning: Docker-Compose not found, trying to use new docker compose command
31
  docker compose version >nul 2>nul
32
  if %ERRORLEVEL% NEQ 0 (
33
+ echo 错误: Docker Compose未安装
34
+ echo Error: Docker Compose not installed
35
+ echo Docker Desktop for Windows应该已包含Docker Compose
36
+ echo Docker Desktop for Windows should already include Docker Compose
37
+ echo 请确保Docker Desktop已正确安装
38
+ echo Please make sure Docker Desktop is properly installed
39
  pause
40
  exit /b 1
41
  ) else (
42
+ echo 使用新的docker compose命令
43
+ echo Using new docker compose command
44
  set COMPOSE_CMD=docker compose
45
  )
46
  ) else (
47
+ echo Docker-Compose已安装
48
+ echo Docker-Compose is installed
49
  set COMPOSE_CMD=docker-compose
50
  )
51
 
52
+ REM 检查Docker是否正在运行
53
+ REM Check if Docker is running
54
  docker info >nul 2>nul
55
  if %ERRORLEVEL% NEQ 0 (
56
+ echo 错误: Docker未运行
57
+ echo Error: Docker not running
58
+ echo 请启动Docker Desktop应用程序
59
+ echo Please start Docker Desktop application
60
  pause
61
  exit /b 1
62
  )
63
 
64
+ echo Docker正在运行
65
+ echo Docker is running
66
 
67
+ REM 检查是否有.env文件
68
+ REM Check if .env file exists
69
+ if not exist "..\owl\.env" (
70
+ echo 警告: 未找到owl\.env文件
71
+ echo Warning: owl\.env file not found
72
+ echo 请运行以下命令创建环境变量文件
73
+ echo Please run the following command to create environment variable file:
74
+ echo copy ..\owl\.env_template ..\owl\.env
75
+ echo 然后编辑owl\.env文件,填写必要的API密钥
76
+ echo Then edit owl\.env file and fill in necessary API keys
77
  ) else (
78
+ echo 环境变量文件已存在
79
+ echo Environment variable file exists
80
  )
81
 
82
+ echo 所有检查完成,您的系统���准备好构建和运行OWL项目的Docker容器
83
+ echo All checks completed, your system is ready to build and run OWL project Docker container
84
+ echo 请运行以下命令构建Docker镜像:
85
+ echo Please run the following command to build Docker image:
86
  echo %COMPOSE_CMD% build
87
 
88
  pause
.container/run_in_docker.bat CHANGED
@@ -1,116 +1,178 @@
1
  @echo off
 
2
  setlocal enabledelayedexpansion
3
 
4
- REM 定义配置变量 | Define configuration variables
 
5
  set SERVICE_NAME=owl
6
  set PYTHON_CMD=xvfb-python
7
  set MAX_WAIT_SECONDS=60
8
  set CHECK_INTERVAL_SECONDS=2
9
 
10
- REM 检查参数 | Check parameters
 
11
  if "%~1"=="" (
12
- echo 用法 | Usage: run_in_docker.bat [脚本名称 | script name] "你的问题 | your question"
13
- echo 例如 | Example: run_in_docker.bat run.py "什么是人工智能? | What is artificial intelligence?"
14
- echo 或者 | Or: run_in_docker.bat run_deepseek_example.py "什么是人工智能? | What is artificial intelligence?"
15
- echo 如果不指定脚本名称,默认使用 run.py | If script name is not specified, run.py will be used by default
 
 
 
 
16
  exit /b 1
17
  )
18
 
19
- REM 判断第一个参数是否是脚本名称 | Determine if the first parameter is a script name
 
20
  set SCRIPT_NAME=%~1
21
  set QUERY=%~2
22
 
23
  if "!SCRIPT_NAME:~-3!"==".py" (
24
- REM 如果提供了第二个参数,则为查询内容 | If a second parameter is provided, it's the query content
 
25
  if "!QUERY!"=="" (
26
- echo 请提供查询参数,例如 | Please provide query parameter, e.g.: run_in_docker.bat !SCRIPT_NAME! "你的问题 | your question"
 
27
  exit /b 1
28
  )
29
  ) else (
30
- REM 如果第一个参数不是脚本名称,则默认使用 run.py | If the first parameter is not a script name, use run.py by default
 
31
  set QUERY=!SCRIPT_NAME!
32
  set SCRIPT_NAME=run.py
33
  )
34
 
35
- REM 检查脚本是否存在 | Check if the script exists
36
- if not exist "owl\!SCRIPT_NAME!" (
37
- echo 错误 | Error: 脚本 | Script 'owl\!SCRIPT_NAME!' 不存在 | does not exist
38
- echo 可用的脚本有 | Available scripts:
39
- dir /b owl\*.py | findstr /v "__"
 
 
 
40
  exit /b 1
41
  )
42
 
43
- echo 使用脚本 | Using script: !SCRIPT_NAME!
44
- echo 查询内容 | Query content: !QUERY!
 
 
45
 
46
- REM docker-compose.yml获取服务名称(如果文件存在) | Get service name from docker-compose.yml (if file exists)
47
- if exist ".container\docker-compose.yml" (
48
- for /f "tokens=*" %%a in ('findstr /r "^ [a-zA-Z0-9_-]*:" .container\docker-compose.yml') do (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  set line=%%a
50
  set service=!line:~2,-1!
51
  if not "!service!"=="" (
52
- REM 使用第一个找到的服务名称 | Use the first service name found
 
53
  set SERVICE_NAME=!service!
54
- echo 从docker-compose.yml检测到服务名称 | Detected service name from docker-compose.yml: !SERVICE_NAME!
 
55
  goto :found_service
56
  )
57
  )
58
  )
59
  :found_service
60
 
61
- REM 确保Docker容器正在运行 | Ensure Docker container is running
62
- docker-compose ps | findstr "!SERVICE_NAME!.*Up" > nul
 
63
  if errorlevel 1 (
64
- echo 启动Docker容器... | Starting Docker container...
65
- docker-compose up -d
 
66
 
67
- REM 使用循环检查容器是否就绪 | Use loop to check if container is ready
68
- echo 等待容器启动... | Waiting for container to start...
 
 
69
  set /a total_wait=0
70
 
71
  :wait_loop
72
  timeout /t !CHECK_INTERVAL_SECONDS! /nobreak > nul
73
  set /a total_wait+=!CHECK_INTERVAL_SECONDS!
74
 
75
- docker-compose ps | findstr "!SERVICE_NAME!.*Up" > nul
76
  if errorlevel 1 (
77
  if !total_wait! LSS !MAX_WAIT_SECONDS! (
78
- echo 容器尚未就绪,已等待!total_wait!秒,继续等待... | Container not ready yet, waited for !total_wait! seconds, continuing to wait...
 
79
  goto :wait_loop
80
  ) else (
81
- echo 错误 | Error:容器启动超时,已等待!MAX_WAIT_SECONDS!秒 | Container startup timeout, waited for !MAX_WAIT_SECONDS! seconds
82
- echo 请检查Docker容器状态 | Please check Docker container status:docker-compose ps
 
 
83
  exit /b 1
84
  )
85
  ) else (
86
- echo 容器已就绪,共等待了!total_wait!秒 | Container is ready, waited for !total_wait! seconds in total
 
87
  )
88
  )
89
 
90
- REM 检查容器中是否存在xvfb-python命令 | Check if xvfb-python command exists in container
91
- echo 检查容器中的命令... | Checking commands in container...
92
- docker-compose exec -T !SERVICE_NAME! which !PYTHON_CMD! > nul 2>&1
 
 
93
  if errorlevel 1 (
94
- echo 警告 | Warning:容器中未找到!PYTHON_CMD!命令,尝试使用python替代 | !PYTHON_CMD! command not found in container, trying to use python instead
 
95
  set PYTHON_CMD=python
96
 
97
- REM 检查python命令是否存在 | Check if python command exists
98
- docker-compose exec -T !SERVICE_NAME! which python > nul 2>&1
 
99
  if errorlevel 1 (
100
- echo 错误 | Error:容器中未找到python命令 | python command not found in container
101
- echo 请检查容器配置 | Please check container configuration
 
 
102
  exit /b 1
103
  )
104
  )
105
 
106
- REM 在容器中运行指定的脚本,传递查询参数 | Run the specified script in container, passing query parameter
107
- echo 在Docker容器中使用!PYTHON_CMD!运行脚本... | Running script in Docker container using !PYTHON_CMD!...
108
- docker-compose exec -T !SERVICE_NAME! !PYTHON_CMD! !SCRIPT_NAME! "!QUERY!"
 
 
109
 
110
  if errorlevel 0 (
111
- echo 查询完成! | Query completed!
 
112
  ) else (
113
- echo 查询执行失败,请检查错误信息。 | Query execution failed, please check error messages.
 
114
  )
115
 
116
  pause
 
1
  @echo off
2
+ chcp 65001 >nul
3
  setlocal enabledelayedexpansion
4
 
5
+ REM 定义配置变量
6
+ REM Define configuration variables
7
  set SERVICE_NAME=owl
8
  set PYTHON_CMD=xvfb-python
9
  set MAX_WAIT_SECONDS=60
10
  set CHECK_INTERVAL_SECONDS=2
11
 
12
+ REM 检查参数
13
+ REM Check parameters
14
  if "%~1"=="" (
15
+ echo 用法: run_in_docker.bat [脚本名称] "你的问题"
16
+ echo Usage: run_in_docker.bat [script name] "your question"
17
+ echo 例如: run_in_docker.bat run.py "什么是人工智能?"
18
+ echo Example: run_in_docker.bat run.py "What is artificial intelligence?"
19
+ echo 或者: run_in_docker.bat run_deepseek_example.py "什么是人工智能?"
20
+ echo Or: run_in_docker.bat run_deepseek_example.py "What is artificial intelligence?"
21
+ echo 如果不指定脚本名称,默认使用 run.py
22
+ echo If script name is not specified, run.py will be used by default
23
  exit /b 1
24
  )
25
 
26
+ REM 判断第一个参数是否是脚本名称
27
+ REM Determine if the first parameter is a script name
28
  set SCRIPT_NAME=%~1
29
  set QUERY=%~2
30
 
31
  if "!SCRIPT_NAME:~-3!"==".py" (
32
+ REM 如果提供了第二个参数,则为查询内容
33
+ REM If a second parameter is provided, it's the query content
34
  if "!QUERY!"=="" (
35
+ echo 请提供查询参数,例如: run_in_docker.bat !SCRIPT_NAME! "你的问题"
36
+ echo Please provide query parameter, e.g.: run_in_docker.bat !SCRIPT_NAME! "your question"
37
  exit /b 1
38
  )
39
  ) else (
40
+ REM 如果第一个参数不是脚本名称,则默认使用 run.py
41
+ REM If the first parameter is not a script name, use run.py by default
42
  set QUERY=!SCRIPT_NAME!
43
  set SCRIPT_NAME=run.py
44
  )
45
 
46
+ REM 检查脚本是否存在
47
+ REM Check if the script exists
48
+ if not exist "..\owl\!SCRIPT_NAME!" (
49
+ echo 错误: 脚本 '..\owl\!SCRIPT_NAME!' 不存在
50
+ echo Error: Script '..\owl\!SCRIPT_NAME!' does not exist
51
+ echo 可用的脚本有:
52
+ echo Available scripts:
53
+ dir /b ..\owl\*.py | findstr /v "__"
54
  exit /b 1
55
  )
56
 
57
+ echo 使用脚本: !SCRIPT_NAME!
58
+ echo Using script: !SCRIPT_NAME!
59
+ echo 查询内容: !QUERY!
60
+ echo Query content: !QUERY!
61
 
62
+ REM 优先检查新版 docker compose 命令
63
+ REM Check new docker compose command first
64
+ docker compose version >nul 2>nul
65
+ if %ERRORLEVEL% EQU 0 (
66
+ echo 使用新版 docker compose 命令
67
+ echo Using new docker compose command
68
+ set COMPOSE_CMD=docker compose
69
+ ) else (
70
+ REM 如果新版不可用,检查旧版 docker-compose
71
+ REM If new version is not available, check old docker-compose
72
+ where docker-compose >nul 2>nul
73
+ if %ERRORLEVEL% EQU 0 (
74
+ echo 使用旧版 docker-compose 命令
75
+ echo Using old docker-compose command
76
+ set COMPOSE_CMD=docker-compose
77
+ ) else (
78
+ echo 错误: Docker Compose 未安装
79
+ echo Error: Docker Compose not installed
80
+ echo 请确保 Docker Desktop 已正确安装
81
+ echo Please make sure Docker Desktop is properly installed
82
+ pause
83
+ exit /b 1
84
+ )
85
+ )
86
+
87
+ REM 从docker-compose.yml获取服务名称(如果文件存在)
88
+ REM Get service name from docker-compose.yml (if file exists)
89
+ if exist "docker-compose.yml" (
90
+ for /f "tokens=*" %%a in ('findstr /r "^ [a-zA-Z0-9_-]*:" docker-compose.yml') do (
91
  set line=%%a
92
  set service=!line:~2,-1!
93
  if not "!service!"=="" (
94
+ REM 使用第一个找到的服务名称
95
+ REM Use the first service name found
96
  set SERVICE_NAME=!service!
97
+ echo 从docker-compose.yml检测到服务名称: !SERVICE_NAME!
98
+ echo Detected service name from docker-compose.yml: !SERVICE_NAME!
99
  goto :found_service
100
  )
101
  )
102
  )
103
  :found_service
104
 
105
+ REM 确保Docker容器正在运行
106
+ REM Ensure Docker container is running
107
+ %COMPOSE_CMD% ps | findstr "!SERVICE_NAME!.*Up" > nul
108
  if errorlevel 1 (
109
+ echo 启动Docker容器...
110
+ echo Starting Docker container...
111
+ %COMPOSE_CMD% up -d
112
 
113
+ REM 使用循环检查容器是否就绪
114
+ REM Use loop to check if container is ready
115
+ echo 等待容器启动...
116
+ echo Waiting for container to start...
117
  set /a total_wait=0
118
 
119
  :wait_loop
120
  timeout /t !CHECK_INTERVAL_SECONDS! /nobreak > nul
121
  set /a total_wait+=!CHECK_INTERVAL_SECONDS!
122
 
123
+ %COMPOSE_CMD% ps | findstr "!SERVICE_NAME!.*Up" > nul
124
  if errorlevel 1 (
125
  if !total_wait! LSS !MAX_WAIT_SECONDS! (
126
+ echo 容器尚未就绪,已等待!total_wait!秒,继续等待...
127
+ echo Container not ready yet, waited for !total_wait! seconds, continuing to wait...
128
  goto :wait_loop
129
  ) else (
130
+ echo 错误:容器启动超时,已等待!MAX_WAIT_SECONDS!秒
131
+ echo Error: Container startup timeout, waited for !MAX_WAIT_SECONDS! seconds
132
+ echo 请检查Docker容器状态:%COMPOSE_CMD% ps
133
+ echo Please check Docker container status: %COMPOSE_CMD% ps
134
  exit /b 1
135
  )
136
  ) else (
137
+ echo 容器已就绪,共等待了!total_wait!秒
138
+ echo Container is ready, waited for !total_wait! seconds in total
139
  )
140
  )
141
 
142
+ REM 检查容器中是否存在xvfb-python命令
143
+ REM Check if xvfb-python command exists in container
144
+ echo 检查容器中的命令...
145
+ echo Checking commands in container...
146
+ %COMPOSE_CMD% exec -T !SERVICE_NAME! which !PYTHON_CMD! > nul 2>&1
147
  if errorlevel 1 (
148
+ echo 警告:容器中未找到!PYTHON_CMD!命令,尝试使用python替代
149
+ echo Warning: !PYTHON_CMD! command not found in container, trying to use python instead
150
  set PYTHON_CMD=python
151
 
152
+ REM 检查python命令是否存在
153
+ REM Check if python command exists
154
+ %COMPOSE_CMD% exec -T !SERVICE_NAME! which python > nul 2>&1
155
  if errorlevel 1 (
156
+ echo 错误:容器中未找到python命令
157
+ echo Error: python command not found in container
158
+ echo 请检查容器配置
159
+ echo Please check container configuration
160
  exit /b 1
161
  )
162
  )
163
 
164
+ REM 在容器中运行指定的脚本,传递查询参数
165
+ REM Run the specified script in container, passing query parameter
166
+ echo 在Docker容器中使用!PYTHON_CMD!运行脚本...
167
+ echo Running script in Docker container using !PYTHON_CMD!...
168
+ %COMPOSE_CMD% exec -T !SERVICE_NAME! !PYTHON_CMD! !SCRIPT_NAME! "!QUERY!"
169
 
170
  if errorlevel 0 (
171
+ echo 查询完成!
172
+ echo Query completed!
173
  ) else (
174
+ echo 查询执行失败,请检查错误信息。
175
+ echo Query execution failed, please check error messages.
176
  )
177
 
178
  pause