获取单个Prompt模板详情
更新时间:2025-05-16
功能介绍
本接口用于获取单个Prompt模板详情,如Prompt模板ID、名称等。
使用说明
本文API支持通过Python SDK、Go SDK、Java SDK 和 Node.js SDK调用,调用流程请参考SDK安装及使用流程。
SDK调用
调用示例
1import os
2from qianfan import resources
3
4# 通过环境变量初始化认证信息
5# 使用安全认证AK/SK调用,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk,如何获取请查看https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
6os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
7os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"
8
9
10
11resp = resources.console.utils.call_action(
12 # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
13 "/v2/promptTemplates",
14 # 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
15 "DescribePromptTemplate",
16 # 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
17 {
18 "templateId":"pt-wx****g9if",
19 "var1":"hello world"
20 }
21)
22
23print(resp.body)
1package main
2import (
3 "context"
4 "fmt"
5 "os"
6 "github.com/baidubce/bce-qianfan-sdk/go/qianfan"
7)
8func main() {
9 // 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
10 os.Setenv("QIANFAN_ACCESS_KEY", "your_iam_ak")
11 os.Setenv("QIANFAN_SECRET_KEY", "your_iam_sk")
12
13 ca := qianfan.NewConsoleAction()
14
15 res, err := ca.Call(context.TODO(),
16 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
17 "/v2/promptTemplates",
18 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
19 "DescribePromptTemplate",
20 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
21 map[string]interface{}{
22 "templateId":"pt-wx****g9if",
23 "var1":"hello world",
24 })
25 if err != nil {
26 panic(err)
27 }
28 fmt.Println(string(res.Body))
29
30}
1import com.baidubce.qianfan.Qianfan;
2import com.baidubce.qianfan.model.console.ConsoleResponse;
3import com.baidubce.qianfan.util.CollUtils;
4import com.baidubce.qianfan.util.Json;
5import java.util.Map;
6
7public class Dome {
8 public static void main(String args[]){
9 // 使用安全认证AK/SK鉴权,替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
10 Qianfan qianfan = new Qianfan("your_iam_ak", "your_iam_sk");
11
12 ConsoleResponse<Map<String, Object>> response = qianfan.console()
13 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
14 .route("/v2/promptTemplates")
15 // 调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
16 .action("DescribePromptTemplate")
17 // 需要传入参数的场景,可以自行封装请求类,或者使用Map.of()来构建请求Body
18 // Java 8可以使用SDK提供的CollUtils.mapOf()来替代Map.of()
19 // 请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
20 .body(CollUtils.mapOf(
21 "templateId","wx****g9if",
22 "var1","hello world"
23 ))
24 .execute();
25
26 System.out.println(Json.serialize(response));
27 }
28}
1import {consoleAction, setEnvVariable} from "@baiducloud/qianfan";
2
3// 使用安全认证AK/SK鉴权,通过环境变量初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
4setEnvVariable('QIANFAN_ACCESS_KEY','your_iam_ak');
5setEnvVariable('QIANFAN_SECRET_KEY','your_iam_sk');
6
7async function main() {
8 //base_api_route:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求结构-请求地址的后缀
9 //action:调用本文API,该参数值为固定值,无需修改;对应API调用文档-请求参数-Query参数的Action
10 //data:请查看本文请求参数说明,根据实际使用选择参数;对应API调用文档-请求参数-Body参数
11 const res = await consoleAction({base_api_route: '/v2/promptTemplates', action: 'DescribePromptTemplate', data: {
12 "templateId":"pt-wx****g9if",
13 "var1":"hello world"
14 }
15 });
16
17 console.log(res);
18}
19
20main();
返回示例
1{
2 "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
3 "result": {
4 "templateId": "pt-wx****g9if",
5 "templateName": "3D角色",
6 "templateContent": "snowing winter in {location}, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
7 "content": "snowing winter, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
8 "templateVariables": ["location"],
9 "variableIdentifier": "{}",
10 "negativeTemplateContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
11 "negativeContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
12 "labels": [
13 {
14 "labelId": "pl-***g9if",
15 "labelName": "图像生成"
16 }
17 ],
18 "type": "System",
19 "sceneType": "TextToImage",
20 "frameworkType": "None",
21 "hyperParametersStatus": "On",
22 "hyperParameters": {
23 "modelName": "开源模型",
24 // 文生文相关参数
25 "temperature": 0.5,
26 "topP": 1,
27 "penaltyScore": 0.5,
28 "system": "system",
29 "stop": [
30 "stop1",
31 "stop2"
32 ],
33 "disableSearch": True,
34 "enableCitation": True
35 }
36 }
37}
1{
2 "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
3 "result": {
4 "templateId": "pt-wx****g9if",
5 "templateName": "3D角色",
6 "templateContent": "snowing winter in {location}, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
7 "content": "snowing winter, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
8 "templateVariables": ["location"],
9 "variableIdentifier": "{}",
10 "negativeTemplateContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
11 "negativeContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
12 "labels": [
13 {
14 "labelId": "pl-***g9if",
15 "labelName": "图像生成"
16 }
17 ],
18 "type": "System",
19 "sceneType": "TextToImage",
20 "frameworkType": "None",
21 "hyperParametersStatus": "On",
22 "hyperParameters": {
23 "modelName": "开源模型",
24 // 文生文相关参数
25 "temperature": 0.5,
26 "topP": 1,
27 "penaltyScore": 0.5,
28 "system": "system",
29 "stop": [
30 "stop1",
31 "stop2"
32 ],
33 "disableSearch": true,
34 "enableCitation": true
35 }
36 }
37}
1{
2 "requestId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
3 "result": {
4 "templateId": "pt-wx****g9if",
5 "templateName": "3D角色",
6 "templateContent": "snowing winter in {location}, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
7 "content": "snowing winter, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K",
8 "templateVariables": ["location"],
9 "variableIdentifier": "{}",
10 "negativeTemplateContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
11 "negativeContent": "(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors",
12 "labels": [
13 {
14 "labelId": "pl-9d4***30x5",
15 "labelName": "图像生成"
16 }
17 ],
18 "type": "System",
19 "sceneType": "TextToImage",
20 "frameworkType": "None",
21 "hyperParametersStatus": "On",
22 "hyperParameters": {
23 "modelName": "开源模型",
24 // 文生文相关参数
25 "temperature": 0.5,
26 "topP": 1,
27 "penaltyScore": 0.5,
28 "system": "system",
29 "stop": [
30 "stop1",
31 "stop2"
32 ],
33 "disableSearch": true,
34 "enableCitation": true
35 }
36 }
37}
1{
2 requestId: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
3 result: {
4 templateId: 'pt-838e92379b93991e',
5 templateName: '3D角色',
6 templateContent: 'snowing winter in {location}, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K',
7 content: 'snowing winter, super cute baby pixar style white fairy bear, shiny snow-white fluffy, big bright eyes, wearing a woolly cyan hat, delicate and fine, high detailed, bright color, natural light, simple background, octane render, ultra wide angle, 8K',
8 templateVariables: ['location'],
9 variableIdentifier: '{}',
10 negativeTemplateContent: '(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors',
11 negativeContent: '(worst quality, low quality:1.4),signature, watermark, simple background, dated, low res, line art, flat colors',
12 labels: [
13 {
14 labelId: 'pl-9d***d30x5',
15 labelName: '图像生成'
16 }
17 ],
18 type: 'System',
19 sceneType: 'TextToImage',
20 frameworkType: 'None',
21 hyperParametersStatus: 'On',
22 hyperParameters: {
23 modelName: '开源模型',
24 // 文生文相关参数
25 temperature: 0.5,
26 topP: 1,
27 penaltyScore: 0.5,
28 system: 'system',
29 stop: [
30 'stop1',
31 'stop2'
32 ],
33 disableSearch: true,
34 enableCitation: true
35 }
36 }
37}
请求参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
templateId | string | 是 | Prompt模板ID,通过以下任一方式获取该字段值: · 方式一:调用创建Prompt模板接口,返回的字段templateId获取 · 方式二:调用获取Prompt模板列表接口,返回的字段templateId获取 · 方式三:在控制台-Prompt模板-点击自制模板页面,选择模板,在模板详情查看模板ID,如下图所示: ![]() |
插值变量1 | string | 是 | 插值变量1对应的值 |
插值变量2 | string | 是 | 插值变量2对应的值 |
插值变量n | string | 是 | 插值变量n对应的值 |
返回参数
名称 | 类型 | 描述 |
---|---|---|
requestId | string | 请求ID |
code | string | 错误码,错误时返回 |
message | string | 错误信息,请求失败时返回 |
result | object | 请求结果,请求成功时返回 |
result说明
名称 | 类型 | 描述 |
---|---|---|
templateId | string | Prompt模板ID |
templateName | string | Prompt模板的名称 |
templateContent | string | 模板内容,说明: (1)如果不使用框架,示例:请以{number}字数生成{province}省相关简介" (2)如果使用模型框架该字段值需符合框架要求,详见模板框架说明 |
templateVariables | List<string> | 模板变量列表 |
variableIdentifier | string | 变量识别符号,现有符号: · 大括号{} · 双大括号{{}} · 中括号[] · 双中括号[[]] · 小括号() · 双小括号(()) |
negativeTemplateContent | string | 反向prompt模板内容,表示不希望大模型生成的内容,说明:只有sceneType为TextToImage,即场景类型为文生图时,返回该字段 |
negativeTemplateVariables | string | 反向prompt模板的变量,说明:只有sceneType为TextToImage时,即场景类型为文生图时,返回该字段 |
labels | List<object> | 模板标签 |
type | string | 模板类型 · System:系统预置模板 · Custom:用户创建模板 |
sceneType | string | 场景类型: · TextToText:文生文 · TextToImage:文生图 |
frameworkType | string | 模板框架,说明: · None:表示无框架,如果不传,默认是0 · Basic:Basic Prompt Framework · CRISPE:CRISPE Prompt Framework · FewShot:Few-shot Promt |
hyperParameters | object | 推理参数,仅在开启推理时有效 |
labels说明
名称 | 类型 | 描述 |
---|---|---|
labelId | string | 标签ID |
labelName | string | 标签名称 |
hyperParameters说明
- 文生文相关推理参数
名称 | 类型 | 描述 |
---|---|---|
modelName | string | 模型类别,可选值如下: · EB-Turbo · ERNIE-Bot · open-source |
temperature | float64 | 温度,说明: (1)较高的数值会使输出更加随机,而较低的数值会使其更加集中和确定 (2)默认0.95,范围 (0, 1.0],不能为0 (3)建议该参数和top_p只设置1个 (4)建议top_p和temperature不要同时更改 |
topP | int | 多样性,说明: (1)影响输出文本的多样性,取值越大,生成文本的多样性越强 (2)默认0.8,取值范围 [0, 1.0] (3)建议该参数和temperature只设置1个 (4)建议top_p和temperature不要同时更改 |
penaltyScore | float64 | 重复惩罚,通过对已生成的token增加惩罚,减少重复生成的现象,说明: (1)值越大表示惩罚越大 (2)默认1.0,取值范围:[1.0, 2.0] |
disableSearch | bool | 实时搜索,是否强制关闭实时搜索功能,默认false,表示不关闭 |
enableCitation | bool | 角标返回,是否开启上角标返回,说明: (1)开启后,有概率触发搜索溯源信息search_info,search_info内容见search_info说明 (2)默认false,不开启 |
stop | List<string> | 停止标识 |
system | string | 模型人设,主要用于人设设定,例如,你是xxx公司制作的AI助手,长度限制1024个字符 |
- 文生图相关推理参数
名称 | 类型 | 描述 |
---|---|---|
picSize | string | 图片比例,入参size。生成图片长宽,说明: (1)默认值 1024x1024 (2)取值范围如下:["512x512", "768x768", "768x1024", "1024x768", "576x1024", "1024x576", "1024x1024"] 注意:建议选择较大尺寸,结合完善的prompt,以保障图片质量 |
picNum | int | 图片数量,入参n。生成图片数量,说明: (1)默认值为1 (2)取值范围为1-4 (3)单次生成的图片较多及请求较频繁可能导致请求超时 |
samplingSteps | int | 采样步数,入参step。进行采样的次数,说明: (1)默认值为20 (2)取值范围为10-50 |
samplingMode | string | 采样方式,入参sampler_index,说明: (1)默认值:Euler a (2)值如下: · Euler · Euler a · DPM++ 2M · DPM++ 2M Karras · LMS Karras · DPM++ SDE · DPM++ SDE Karras · DPM2 a Karras · Heun · DPM++ 2M SDE · DPM++ 2M SDE Karras · DPM2 · DPM2 Karras · DPM2 a · LMS |
search_info说明
名称 | 类型 | 描述 |
---|---|---|
search_results | List<object> | 搜索结果列表 |
search_results说明
名称 | 类型 | 描述 |
---|---|---|
index | int | 序号 |
url | string | 搜索结果URL |
title | string | 搜索结果标题 |