资讯 社区 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

新建我的模型版本

功能介绍

用于新建我的模型版本。

使用说明

本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程

SDK调用

调用示例

从bos导入模型

import os
from qianfan  import resources

# 通过环境变量初始化认证信息
# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"

resp = resources.console.utils.call_action(
    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
    "/v2/model", 
    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
    "CreateCustomModel", 
    # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
    {
        "modelSetId":"am-ih8****",
        "sourceType":"Import",
        "importMeta":{
            "bucket":"test",
            "objectPath":"demoModel",
            "modelFormat":"HuggingFace.Transformers",
            "modelApplicationType":"chat",
            "transformerVersion":"4.36.2",
            "chatConf": {
                "historyQATemplate": "\\n\\nUser: {question} \\nAssistant: {answer}\\n",
                "latestQuestionTemplate": "\\n\\nUser: {question} \\nAssistant:",
                "promptTemplate": "你是一个对话机器人,根据下文输入完成回答\n### 输入:\n{input}\n### 回答: "
            }
        }
    }
)
print(resp.body)
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/baidubce/bce-qianfan-sdk/go/qianfan"
)

func main() {
     // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
    os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
    os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
    
    ca := qianfan.NewConsoleAction()
    
     res, err := ca.Call(context.TODO(),
     // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
     "/v2/model",
     // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
     "CreateCustomModel",
     // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
     map[string]interface{}{
            "modelSetId":"am-ih8***",
            "sourceType":"Import",
            "importMeta":map[string]any{
                "bucket":"test",
                "objectPath":"demoModel",
                "modelFormat":"HuggingFace.Transformers",
                "modelApplicationType":"chat",
                "transformerVersion":"4.36.2",
                "chatConf": map[string]any{
                    "historyQATemplate": "\\n\\nUser: {question} \\nAssistant: {answer}\\n",
                    "latestQuestionTemplate": "\\n\\nUser: {question} \\nAssistant:",
                    "promptTemplate": "你是一个对话机器人,根据下文输入完成回答\n### 输入:\n{input}\n### 回答: ",
                },
            },
    })
    
    if err != nil {
        panic(err)
    }
    fmt.Println(string(res.Body))
    
}
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.console.ConsoleResponse;
import com.baidubce.qianfan.util.CollUtils;
import com.baidubce.qianfan.util.Json;
import java.util.Map;

public class Dome {
    public static void main(String args[]){
        // 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
        Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
        
        ConsoleResponse<Map<String, Object>> response = qianfan.console()
                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
                .route("/v2/model")
                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
                .action("CreateCustomModel")
                // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
                // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
                // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
                .body(CollUtils.mapOf(
                    "modelSetId","am-ih8***",
                    "sourceType","Import",
                    "importMeta",CollUtils.mapOf(
                        "bucket","test",
                        "objectPath","demoModel",
                        "modelFormat","HuggingFace.Transformers",
                        "modelApplicationType","chat",
                        "transformerVersion","4.36.2",
                        "chatConf", CollUtils.mapOf(
                            "historyQATemplate", "\\n\\nUser: {question} \\nAssistant: {answer}\\n",
                            "latestQuestionTemplate", "\\n\\nUser: {question} \\nAssistant:",
                            "promptTemplate", "你是一个对话机器人,根据下文输入完成回答\n### 输入:\n{input}\n### 回答: "
                        )
                    )
                ))
                .execute();

        System.out.println(Json.serialize(response));
    }
}
import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";

// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');

async function main() {
  //base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
  //action:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
  //data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
  const res = await consoleAction({base_api_route: '/v2/model', action: 'CreateCustomModel', data: {
        "modelSetId":"am-ih8****",
        "sourceType":"Import",
        "importMeta":{
            "bucket":"test",
            "objectPath":"demoModel",
            "modelFormat":"HuggingFace.Transformers",
            "modelApplicationType":"chat",
            "transformerVersion":"4.36.2",
            "chatConf": {
                "historyQATemplate": "\\n\\nUser: {question} \\nAssistant: {answer}\\n",
                "latestQuestionTemplate": "\\n\\nUser: {question} \\nAssistant:",
                "promptTemplate": "你是一个对话机器人,根据下文输入完成回答\n### 输入:\n{input}\n### 回答: "
            }
        }
    }
  });    
    
  console.log(res);
}

main();

从训练任务创建成模型

import os
from qianfan  import resources

# 通过环境变量初始化认证信息
# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
os.environ["QIANFAN_ACCESS_KEY"] = "your_access_key"
os.environ["QIANFAN_SECRET_KEY"] = "your_secret_key"

resp = resources.console.utils.call_action(
    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
    "/v2/model", 
    # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
    "CreateCustomModel", 
    # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
    {
       "modelSetId": "am-ash****",
        "sourceType": "Train",
        "trainMeta": {
            "taskId": "task-sdvsdfbhjsdfb",
            "step": 50
        }
    }
)
print(resp.body)
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/baidubce/bce-qianfan-sdk/go/qianfan"
)

func main() {
     // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
    os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
    os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
    
    ca := qianfan.NewConsoleAction()
    
    res, err := ca.Call(context.TODO(),
    // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
    "/v2/model",
    // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
    "CreateCustomModel",
    // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
    map[string]interface{}{
            "modelSetId": "am-ashdagwfy234",
            "sourceType": "Train",
            "trainMeta": map[string]any{
                "taskId": "task-sdvsdfbhjsdfb",
                "step": 50,
            },
    })
    
    if err != nil {
        panic(err)
    }
    
    fmt.Println(string(res.Body))
    
}
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.console.ConsoleResponse;
import com.baidubce.qianfan.util.CollUtils;
import com.baidubce.qianfan.util.Json;
import java.util.Map;

public class Dome {
    public static void main(String args[]){
        // 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
        Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
        
        ConsoleResponse<Map<String, Object>> response = qianfan.console()
                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
                .route("/v2/model")
                // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
                .action("DescribeServices")
                // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
                // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
                // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
                .body(CollUtils.mapOf(
                        "modelSetId", "am-ashd****",
                        "sourceType", "Train",
                        "trainMeta", CollUtils.mapOf(
                            "taskId", "task-sdvsdfbhjsdfb",
                            "step", 50
                        )
                ))
                .execute();

        System.out.println(Json.serialize(response));
    }
}
import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";

// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');

async function main() {
  //base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
  //action:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action 
  //data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
  const res = await consoleAction({base_api_route: '/v2/model', action: 'CreateCustomModel', body: {
        "modelSetId": "am-ash****",
        "sourceType": "Train",
        "trainMeta": {
            "taskId": "task-sdvsdfbhjsdfb",
            "step": 50
        }
    }
  });    
    
  console.log(res);
}

main();

返回示例

{
    "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
    "result": {
        "modelSetId": "am-5sxpz4xn25uw",
        "modelId": "amv-21qxxr97z8fp"
    }
}
{
    "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
    "result": {
        "modelSetId": "am-5sxpz4xn25uw",
        "modelId": "amv-21qxxr97z8fp"
    }
}
{
    "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
    "result": {
        "modelSetId": "am-5sxpz4xn25uw",
        "modelId": "amv-21qxxr97z8fp"
    }
}
{
    requestId: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
    result: {
        modelSetId: 'am-5sxpz4xn25uw',
        modelId: 'amv-21qxxr97z8fp'
    }
}

请求参数

名称 类型 必填 描述
modelSetId string 模型版本归属的模型ID,示例:am-gh0azfeb9adu,说明:通过以下任一方式获取该字段值:
· 方式一:调用新建获取我的模型列表接口,返回的modelSetId字段获取
· 方式二:在控制台-我的模型查看,如下图所示
image.png
description string 模型版本描述,长度为 [0, 300]
sourceType string 版本来源,可选值如下:
· Train:训练模型发布
· Import:外部导入模型发布
trainMeta TrainSourceMeta 当sourceType=Train时,此字段必填
importMeta ImportSourceMeta 当sourceType=Import时,此字段必填

TrainSourceMeta说明

名称 类型 必填 描述
taskId string 训练任务ID
checkpointStep int 选择step发布时填写此字段

ImportSourceMeta说明

名称 类型 必填 描述
bucket string bucket名称
objectPath string object路径
modelFormat string 模型格式,可选值如下:
· HuggingFace.Transformers:HF导入模型
· Safetensors:文生图模型
modelApplicationType string 输入输出模式,可选值如下:
· chat:对话模式
· completion:续写模式
· Text-to-Image:文生图模式
chatConf ChatConf 对话模型平台预置对话模板,说明:
(1)该字段仅导入HF模型有效
(2)该字段与customSpec字段不能同时使用,只能选择其中一个
customSpec CustomSpec 对话模型自定义对话模板,说明:
(1)该字段仅导入HF模型有效
(2)该字段与chatConf字段不能同时使用,只能选择其中一个
advanceConf string 说明:
(1)该字段仅导入HF模型有效
(2)该字段值通过调用获取导入模型平台预置高级配置接口,返回的result获取
transformerVersion string 说明:
(1)该字段仅导入HF模型有效
(2)transformer版本,目前支持4.34.0、4.36.2、4.39.3和4.40.2
vLLMVersion string 说明:
(1)该字段仅导入HF模型可填
(2)vLLM版本,目前支持0.3.2、0.4.0
advancedSettings object 量化压缩配置

ChatConf说明

名称 类型 必填 描述
historyQATemplate string 历史对话模板, 长度限制[1,200]
latestQuestionTemplate string 最新对话模板, 长度限制[1,200]
promptTemplate string prompt模板,长度限制[0,300]

CustomSpec说明

名称 类型 必填 描述
displayName string 自定义配置文件展示名称,长度限制[1,200]
fileName string 自定义配置平台存储文件名称,该字段值通过调用上传自定义对话模板文件接口,返回result字段获取

modelCompConf说明

名称 类型 必填 描述
samplingStrategy string 压缩时的采样策略,
(1)当导入HF模型,且推理引擎为vLLM时,该字段有效
(2)可选值:
· 多项式采样:multinomialSampling
· 束搜索:beamSearch
· 贪心搜索 greedySearch
numSampling int 返回序列数量,当导入HF模型可填,采样策略选择multinomialSampling且推理引擎为vLLM时可填,范围为1~15
numBeams int 束数量,当导入HF模型,该字段有效,取值范围2-15

返回参数

名称 类型 描述
requestId string 请求ID
result object 请求结果

result说明

名称 类型 描述
modelSetId string 模型ID
modelId string 模型版本ID
上一篇
删除我的模型
下一篇
上传自定义对话模板文件