Skip to content

refactor(model): Refactor the model download logic, support multiple solutions, and optimize automatic resource deployment - #105

Merged
rsonghuster merged 1 commit into
masterfrom
fix-model-sdk
Nov 13, 2025
Merged

rsonghuster merged 1 commit into
masterfrom
fix-model-sdk

Conversation

@mozhou52

@mozhou52 mozhou52 commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@mozhou52
mozhou52 requested a review from rsonghuster November 4, 2025 10:00
@mozhou52
mozhou52 force-pushed the fix-model-sdk branch 2 times, most recently from 81f9513 to ac0e0a8 Compare November 7, 2025 02:51
@mozhou52 mozhou52 changed the title refactor(model):重构模型下载逻辑,支持多种解决方案并优化资源自动部署 refactor(model): Refactor the model download logic, support multiple solutions, and optimize automatic resource deployment Nov 7, 2025
private async _handleOssAutoDeployment(region: IRegion, credential: any) {
let ossEndpoint = `https://oss-${region}.aliyuncs.com`;
if (process.env.FC_REGION === region) {
ossEndpoint = `oss-${region}-internal.aliyuncs.com`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种之前线上测试过吗? 最好预发杭州和预发新加坡都测试下

logger.info(`ossAuto code to ${ossEndpoint}`);
const oss = new OSS(region, credential as ICredentials, ossEndpoint);
const { ossBucket } = await oss.deploy();
logger.write(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oss auto 的逻辑,泽文优化的一版的, 你看下他优化后的代码, auto 包应该有一些变化,支持更多参数自定义

Comment thread src/subCommands/model/index.ts Outdated
throw new Error(errorMessage);
}
const { nasConfig, vpcConfig, ossMountConfig } = this.local;
logger.debug(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个日志建议 info, 很重要, 涉及到调用下载服务那边的入参,方便查问题

Comment thread src/subCommands/model/index.ts Outdated
const { AccountID: accountID } = await this.inputs.getCredential();
const { credential } = this.inputs;
const { region, supplement, annotations } = this.inputs.props;
const { supplement, annotations } = this.inputs.props;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

线上没有这个, supplement 直接remove 掉吧

Comment thread src/subCommands/model/index.ts Outdated
files: modelConfig.files,
conflictResolution: modelConfig?.downloadStrategy?.conflictResolution || 'overwrite',
mode: modelConfig?.downloadStrategy?.mode || 'once',
timeout: modelConfig?.downloadStrategy?.timeout,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个默认值我们先定义为 40 分钟, 2400s

syncStrategy: process.env.MODEL_DOWNLOAD_STRATEGY || 'incremental_once',
};

if (typeof ossMountConfig === 'object' && ossMountConfig?.mountPoints) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个时候按道理,应该没有 auto 的情况,基本都是正确的情况, 除非 fc3 props 中传过来的值就不对, 对吧

Comment thread src/subCommands/model/index.ts Outdated
@@ -79,363 +64,233 @@ export class Model {
this.envName = envName;
const name = `${projectName}$${envName}$${functionName}`;

@rsonghuster rsonghuster Nov 7, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 这个 deploy 和 remove 中 name 的获取有重复代码, 提取成一个 method 吧
  2. ${uid}$${projectName}$${envName}$${functionName} 最后前面再加一个 uid, 因为下载服务也是 region 化的,region 就不用传了, 但是 uid 需要加上,不然有 name 冲突

Comment thread src/subCommands/model/model.ts Outdated
if (process.env.artifact_endpoint) {
return process.env.artifact_endpoint;
}
return DEFAULT_ENDPOINT;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devs.{region}.aliyuncs.com

Comment thread src/subCommands/model/constants.ts Outdated
export const NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT: number =
parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT as string, 10) || 60 * 1000;
export const NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT: number =
parseInt(process.env.NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT as string, 10) || 86400 * 1000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个值都改成 5min 先

Comment thread src/subCommands/model/model.ts Outdated
}`,
});

logger.info(`new models service init, ARTIFACT_ENDPOINT endpoint: ${config.endpoint}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEVS_ENDPOINT

Comment thread src/subCommands/model/fileManager.ts Outdated

let endpoint: string;

endpoint = 'devs-pre.cn-hangzhou.aliyuncs.com';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一提取到 utils.ts, 还有那个 name generate

Comment thread src/subCommands/model/fileManager.ts Outdated
connectTimeout: NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT,
userAgent: `${
this.inputs.userAgent ||
`Component:cap-model;Nodejs:${process.version};OS:${process.platform}-${process.arch}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fun-art, fun-model 同理

Comment thread src/subCommands/model/fileManager.ts Outdated
}
}

private _displayProgressComplete(filePath: string, currentBytes: number, totalBytes: number) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

进度条抽取到 utils.ts 中去

Comment thread src/subCommands/model/fileManager.ts Outdated
}
}

private _getSourcePath(source: any, sourceUri: string, validSourcePattern: RegExp): string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参数命名清晰, 增加注释

Comment thread src/subCommands/model/fileManager.ts Outdated
}
}

private _getSourcePath(source: any, sourceUri: string, validSourcePattern: RegExp): string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validSourcePattern 不用作为参数

Comment thread src/subCommands/model/fileManager.ts Outdated
return new DevClient(config);
}

getSource(uri, file, nasMountPoints, ossMountPoints, targetUri) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveSourceAndTarget, 举个例子,取一个有意义的字段

Comment thread src/subCommands/model/fileManager.ts Outdated
return;
}

if (!_.isEmpty(files)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if(_.isEmpty(files)){
log.warn();
return
}

Comment thread src/subCommands/model/utils/index.ts Outdated
readTimeout: NEW_MODEL_SERVICE_CLIENT_READ_TIMEOUT,
connectTimeout: NEW_MODEL_SERVICE_CLIENT_CONNECT_TIMEOUT,
userAgent: `${inputs.userAgent ||
`Component:fun-art;Nodejs:${process.version};OS:${process.platform}-${process.arch}`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个为什么写死 fun-art

Comment thread src/subCommands/model/fileManager.ts Outdated
: true;

if (!needDownload) {
logger.info(`[Download-model] ${file.source.path} The file has been downloaded..`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结尾多了一个点

Comment thread src/subCommands/model/fileManager.ts Outdated

// 文件下载失败,抛出错误
if (failureCount > 0) {
throw new Error(`[Download-model] ${failureCount} out of ${filesNeed.length} files failed to download.`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个能打印下原始错误或者 rid, 方便能让ohye 查下后端的问题

Comment thread src/subCommands/model/index.ts Outdated
const { credential: { AccountID: accountID } } = this.inputs;
const projectName = getEnvVariable('ALIYUN_DEVS_REMOTE_PROJECT_NAME');
const envName = getEnvVariable('ALIYUN_DEVS_REMOTE_ENV_NAME');
this.name = `${getUuid(String(accountID))}$${projectName}$${envName}$${functionName}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议前缀最好还是有 uid, 完全 uuid 都不知道是哪个用户的了

${uid}{projectname}{uuid} 这种同时具备可读性和唯一性

@mozhou52
mozhou52 force-pushed the fix-model-sdk branch 14 times, most recently from 83b90ea to 87f48c7 Compare November 12, 2025 07:59
@mozhou52
mozhou52 force-pushed the fix-model-sdk branch 18 times, most recently from a39f5cd to c1f4a28 Compare November 13, 2025 08:25
…solutions, and optimize automatic resource deployment

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@rsonghuster
rsonghuster merged commit 3f02e25 into master Nov 13, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants