本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
完成請求結構描述
叫用 API (串流和非串流) 與 Converse API 之間的請求結構描述幾乎相同。與影像和影片承載編碼相關的細微差異。由於 Amazon Nova Micro 不支援影像或影片做為輸入,因此請求結構描述的這些部分不適用於 Amazon Nova Micro。否則,所有 Amazon Nova 理解模型的請求結構描述都相同。
重要
對 Amazon Nova 進行推論呼叫的逾時期間為 60 分鐘。根據預設, AWS SDK 用戶端會在 1 分鐘後逾時。建議您將 AWS SDK 用戶端的讀取逾時期間增加到至少 60 分鐘。例如,在 AWS Python botocore SDK 中,將 botocore.configread_timeout
欄位值變更為至少 3600。
client = boto3.client( "bedrock-runtime", region_name="us-east-1", config=Config( connect_timeout=3600, # 60 minutes read_timeout=3600, # 60 minutes retries={'max_attempts': 1} ) )
{ "system": [ { "text":
"string"
} ], "messages": [ { "role": "user", //first turn should always be the user turn "content": [ { "text":"string"
}, { "image": { "format": "jpeg" | "png" | "gif" | "webp", "source": { "bytes":image
// Binary array (Converse API) or Base64-encoded string (Invoke API) } } }, { "video": { "format": "mkv" | "mov" | "mp4" | "webm" | "three_gp" | "flv" | "mpeg" | "mpg" | "wmv", "source": { // Option 1: Sending a S3 location "s3Location": { "uri":"string"
, // example: s3://my-bucket/object-key "bucketOwner":"string"
// (Optional) example: "123456789012" }, // Option 2: Sending file bytes "bytes":video
// Binary array (Converse API) or Base64-encoded string (Invoke API) } } } ] }, { "role": "assistant", "content": [ { "text":"string"
//prefilling assistant turn } ] } ], "inferenceConfig":{ // all Optional, Invoke parameter names used in this example "maxTokens":int
, // greater than 0, equal or less than 5k (default: dynamic*) "temperature":float
, // greater than 0 and less than 1.0 (default: 0.7) "topP":float
, // greater than 0, equal or less than 1.0 (default: 0.9) "topK":int
, // 0 or greater (default: 50) "stopSequences":["string"]
}, "toolConfig": { // all Optional "tools": [ { "toolSpec": { "name":"string"
, //meaningful tool name (Max char: 64) "description":"string"
, //meaningful description of the tool "inputSchema": { "json": { // The JSON schema for the tool. For more information, see JSON Schema Reference "type": "object
", "properties": {"arg1"
: { //arguments "type": "string
", //argument data type "description": "string
" //meaningful description } }, "required": ["string"
//args ] } } } } ], }, "toolChoice": { "auto": {} } //Amazon Nova models ONLY support tool choice of "auto" }
以下是必要的參數:
-
system
– (選用) 請求的系統提示。系統提示是提供內容和指示給 Amazon Nova 的一種方式,例如指定特定目標或角色。
-
messages
– (必要) 輸入訊息。-
role
– 對話的角色輪換。有效值為user
和assistant
。 -
content
– (必要) 包含對話內容的 ContentBlock 物件清單。每個物件都包含一個金鑰,指定內容的類型 (text
、image
或video
)。物件的值取決於金鑰類型。金鑰支援下列類型:-
text
– 映射到包含單一欄位 的物件text
,其值是對話轉彎的文字提示。如果對話轉彎也包含image
或video
物件,text
物件會解譯為影像或影片隨附的文字提示。 -
image
– (Amazon Nova Micro 不支援) 映射至代表影像內容且包含下列欄位的物件:-
format
– (必要) 影像格式。您可以指定下列影像格式:-
jpeg
-
png
-
webp
-
gif
-
-
source
– (必要) 影像資料。對於調用 API,這必須是 Base64 編碼的影像字串。對於 Converse API,這必須是位元組陣列。 -
bytes
– (必要) 影像資料。對於調用 API,這必須是 Base64 編碼的影像字串。對於 Converse API,這必須是位元組陣列。
-
-
video
– (Amazon Nova Micro 不支援) 映射至代表視訊內容且包含下列欄位的物件:-
format
– (必要) 影片格式。您可以指定下列值:-
mkv
-
mov
-
mp4
-
webm
-
three_gp
-
flv
-
mpeg
-
mpg
-
wmv
-
-
source
– (必要) 影片資料的來源。您可以在請求中指定 Amazon S3 URI 或影片檔案位元組。-
uri
– (必要) 影片檔案的 Amazon S3 URI。例如“s3://my-bucket/object-key”
-
bucketOwner
– (選用) 擁有儲存貯體的帳戶 ID。如果您要從個別帳戶叫用模型,請使用此選項。 -
bytes
– (必要) 影像資料。對於調用 API,這必須是 Base64 編碼的影像字串。對於 Converse API,這必須是位元組陣列。
-
-
-
-
-
inferenceConfig:
這些是可以推論傳遞的推論組態值。-
maxTokens
– (選用) 停止之前要產生的字符數目上限。請注意,Amazon Nova 模型可能會在達到 的值之前停止產生字符
maxTokens
。允許的最大新權杖值為 5K。 -
temperature
– (選用) 注入回應的隨機性量。有效值介於 0.00001 和 1 之間。預設值為 0.7。 -
topP
– (選用) 使用核取樣。Amazon Nova 會以較低的機率順序計算每個後續字符所有選項的累積分佈,並在達到 指定的特定機率時將其切斷
topP
。您應該更改temperature
或topP
,但不能更改兩者。有效值介於 0 到 1 之間,包括 。預設值為 0.9。 -
topK
– (選用) 僅針對每個後續字符從頂端 K 選項中抽樣。使用
topK
參數移除長尾、低機率回應。有效值介於 0 到 128 之間。預設值為未使用此參數。注意
搭配
topK
參數使用 Converse API 時, 欄位必須包含其他inferenceConfig
參數additionalModelRequestFields
。使用 Converse API 如需如何傳遞這些參數的範例,請參閱 。 -
stopSequences
– (選用) 包含停止序列的字串陣列。如果模型產生任何這些字串,產生將會停止,並在該時間點之前傳回回應。
Parameter Default value Range 溫度
0.7 0.00001-1 topP
0.9 0-1 topK
Not used 0-128 -
-
toolConfig
– (選用) ToolConfig 結構描述後面的 JSON 物件,其中包含工具規格和工具選擇。此結構描述與 Converse API 後面相同