

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Stable Image Core 請求和回應
<a name="model-parameters-diffusion-stable-image-core-text-image-request-response"></a>

請求內文在請求的 `body` 欄位傳遞到 [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)。

**模型調用請求內文欄位**

當您使用 Stability AI Stable Diffusion Stable Image Core 模型進行 InvokeModel 呼叫時，請在內文欄位中填入如下所示的 JSON 物件。

```
{
        'prompt': 'Create an image of a panda'
    }
```

**模型調用回應內文欄位**

當您使用 Stability AI Stable Diffusion Stable Image Core 模型進行 InvokeModel 呼叫時，回應如下所示 

```
{
        'seeds': [2130420379], 
        'finish_reasons': [null], 
        'images': ['...']
    }
```
+ **seeds** – (字串) 用於為模型產生影像的種子清單。
+ **finish\$1reasons** – 指出請求是否已經過篩選的列舉。`null` 將指出請求成功。目前可能的值：`"Filter reason: prompt", "Filter reason: output image", "Filter reason: input image", "Inference error", null`。
+ **images** – 產生的影像清單，採用 base64 字串格式。

如需詳細資訊，請參閱 https：//[https://platform.us.stability.ai/docs/api-reference\$1tag/v1generation](https://platform.us.stability.ai/docs/api-reference#tag/v1generation)。

------
#### [ Text to image ]

Stable Image Core 模型具有下列推論參數，可用於文字轉影像推論呼叫。

 **text\$1prompts** (必要) — 用於生成的文字提示陣列。每個元素都是 JSON 物件，其中包含提示和提示的權重。
+ **prompt** – (字串) 您想要在輸出影像中看到的內容。一個強烈的描述性提示會清楚定義元素、顏色和主題，將帶來更好的結果。    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/bedrock/latest/userguide/model-parameters-diffusion-stable-image-core-text-image-request-response.html)

**選用欄位**
+ **aspect\$1ratio** – (字串) 控制所產生影像的長寬比。此參數僅適用於文字轉影像請求。預設值為 1:1。列舉：16:9、1:1、21:9、2:3、3:2、4:5、5:4、9:16、9:21。
+ **output\$1format** – 指定輸出影像的格式。支援的格式：JPEG、PNG。支援的維度：高度 640 到 1,536 像素，寬度 640 到 1,536 像素。
+ **seed** – (數字) 用來引導產生「隨機性」的特定值。(省略此參數或傳遞 0 以使用隨機種子。) 範圍：0 到 4294967295。
+ **negative\$1prompt** – 您不希望在輸出影像中看到的關鍵字。上限：10.000 個字元。

```
     import boto3
     import json
     import base64
     import io
     from PIL import Image
     
     bedrock = boto3.client('bedrock-runtime', region_name='us-west-2')
     response = bedrock.invoke_model(
         modelId='stability.stable-image-core-v1:0',
         body=json.dumps({
             'prompt': 'A car made out of vegetables.'
         })
     )
     output_body = json.loads(response["body"].read().decode("utf-8"))
     base64_output_image = output_body["images"][0]
     image_data = base64.b64decode(base64_output_image)
     image = Image.open(io.BytesIO(image_data))
     image.save("image.png")
```

------