Skip to content

Commit aaf320a

Browse files
authored
Merge pull request #81 from devsapp/fix-model
fix: model progress bar
2 parents b48c637 + d8ebfb6 commit aaf320a

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

example/s.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ access: quanxi
44

55
resources:
66
modelDemo:
7-
component: fc3
7+
component: ${path('../')}
88
props:
99
region: cn-shanghai
1010
runtime: custom-container

src/subCommands/model/index.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,49 @@ mountPoints:
178178
const modelStatus = await this.getModelStatus(devClient, name);
179179

180180
if (modelStatus.finished) {
181+
// 清除进度条并换行
182+
process.stdout.write('\n');
181183
const durationMs = modelStatus.finishedTime - modelStatus.startTime;
182-
logger.warn(`Time taken for model download: ${durationMs}.`);
184+
const durationSeconds = Math.floor(durationMs / 1000);
185+
logger.info(`Time taken for model download: ${durationSeconds}s.`);
183186
logger.info(`[Download-model] Download model finished.`);
184187
return true;
185188
}
189+
// 显示下载进度
190+
if (modelStatus.currentBytes !== undefined && modelStatus.fileSize !== undefined) {
191+
const percentage = (modelStatus.currentBytes / modelStatus.fileSize) * 100;
192+
const currentMB = (modelStatus.currentBytes / 1024 / 1024).toFixed(1);
193+
const totalMB = (modelStatus.fileSize / 1024 / 1024).toFixed(1);
194+
195+
// 每个等号代表2%,向下取整计算等号数量
196+
const totalBars = 50; // 总共50个字符位置
197+
const filledBars = Math.round(percentage / 2); // 每个等号代表2%
198+
const emptyBars = totalBars - filledBars;
199+
200+
const progressBar = '='.repeat(filledBars) + '.'.repeat(emptyBars);
201+
202+
process.stdout.write(
203+
`\r[Download-model] [${progressBar}] ${percentage.toFixed(2)}% (${currentMB}MB/${totalMB}MB)`
204+
);
205+
}
206+
186207

187208
if (Date.now() - modelStatus.startTime > MODEL_DOWNLOAD_TIMEOUT) {
188-
const errorMessage = `[Model-download] Download timeout after ${
189-
MODEL_DOWNLOAD_TIMEOUT / 1000 / 60
190-
} minutes`;
209+
// 清除进度条并换行
210+
process.stdout.write('\n');
211+
const errorMessage = `[Model-download] Download timeout after ${MODEL_DOWNLOAD_TIMEOUT / 1000 / 60
212+
} minutes`;
191213
throw new Error(errorMessage);
192214
}
193215

194-
logger.warn(`[Download-model] Download task not finished yet, polling in 10 seconds`);
195-
await sleep(10);
216+
// 根据文件大小调整轮询间隔
217+
let sleepTime = 2; // 默认2秒
218+
if (modelStatus.fileSize !== undefined && modelStatus.fileSize > 1024 * 1024 * 1024) {
219+
// 文件大于1GB时,轮询间隔为10秒
220+
sleepTime = 10;
221+
}
222+
223+
await sleep(sleepTime);
196224
}
197225
} else {
198226
throw new Error(

0 commit comments

Comments
 (0)