You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

翻译任务完成后调用getAllProperties获取模型属性为空的解决方法

解决Model Derivative API翻译后立即获取属性返回空的问题

问题核心原因

调用startJob仅提交了异步翻译任务,任务并未立即执行完成。此时直接调用getAllProperties,模型的属性数据还未生成,自然返回空结果。

具体解决方案

1. 轮询等待翻译任务完成

提交翻译任务后,必须等待任务执行成功,才能获取到可用的属性数据。实现轮询函数定期检查任务状态:

async function waitForTranslationComplete(accessToken, urn) {
  const checkInterval = 5000; // 每5秒检查一次状态
  while (true) {
    const jobStatus = await modelDerivativeClient.getJobStatus(accessToken, urn);
    switch (jobStatus.status) {
      case 'success':
        return; // 任务完成,退出轮询
      case 'failed':
        throw new Error(`翻译任务失败:${jobStatus.progress}`);
      default:
        await new Promise(resolve => setTimeout(resolve, checkInterval));
    }
  }
}

2. 正确获取Model GUID

翻译完成后,需要从模型的Manifest中提取正确的modelGuid(即衍生SVF文件的GUID),而非直接传入未验证的值:

async function getModelGuid(accessToken, urn) {
  const manifest = await modelDerivativeClient.getManifest(accessToken, urn);
  // 遍历Manifest找到SVF类型的衍生文件
  const findSvfGuid = (derivatives) => {
    for (const derivative of derivatives) {
      if (derivative.outputType === 'svf') {
        // 通常SVF的子节点包含具体的模型GUID
        return derivative.children?.[0]?.guid;
      }
      if (derivative.children) {
        const guid = findSvfGuid(derivative.children);
        if (guid) return guid;
      }
    }
    return null;
  };
  const modelGuid = findSvfGuid(manifest.derivatives);
  if (!modelGuid) throw new Error('未找到SVF格式的衍生模型GUID');
  return modelGuid;
}

3. 修改主流程代码

整合上述步骤,确保在翻译完成且获取到正确GUID后再调用属性接口:

const obj = await uploadObject(file.name, file.path, req.fields.bucketKey);
const urn = urnify(obj.objectId);
const modelZipEntrypoint = req.fields['model-zip-entrypoint'] as string;
const { access_token } = await getInternalToken();

await translateObject(urn, modelZipEntrypoint);
// 等待翻译完成
await waitForTranslationComplete(access_token, urn);
// 获取正确的Model GUID
const modelGuid = await getModelGuid(access_token, urn);
// 调用属性接口
const properties = await modelDerivativeClient.getAllProperties(access_token, urn, modelGuid);

console.log(properties.data.collections); // 此时应为非空

额外排查点

  • 确认access_token包含data:read和modelderivative:read权限;
  • 检查上传的模型文件(或压缩包)无损坏,且是Model Derivative支持的格式;
  • 验证urnify处理后的URN是正确的Base64编码(需去除末尾等号)。

内容的提问来源于stack exchange,提问作者xNastalgia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:43:13