跳至內容

當我調用 Amazon Bedrock 隨需模型時,如何新增成本分配標籤?

1 分的閱讀內容
0

我想在調用 Amazon Bedrock 隨需模型時新增成本分配標籤。

解決方法

將標籤指派給應用程式推論設定檔,然後將該設定檔連結到隨需模型。

**注意:**您無法將標籤指派給隨需模型。

建立應用程式推論設定檔

使用 CreateInferenceProfile。以下範例會建立一個連結到 amazon.nova-pro-v1:0 的應用程式推論設定檔,其中包含標籤 "key": "CostAllocateTag","value": "project123"

範例:

aws bedrock create-inference-profile --region 'us-east-1' \
    --inference-profile-name 'profile-project123' \
    --description 'profile-project123' \
    --model-source '{"copyFrom": "arn:aws:bedrock:us-east-1::foundation-model/amazon.nova-pro-v1:0"}' \
    --tags '[{"key": "CostAllocateTag","value": "project123"}]'

輸出範例:

{
    "inferenceProfileArn": "arn:aws:bedrock:us-east-1:AccountId:application-inference-profile/y1pcpudi2mb7",
    "status": "ACTIVE"
}

啟動成本分配標籤

若要啟動成本分配標籤,請使用 AWS 帳單與成本管理主控台

**注意:**標籤會在 24 小時內顯示在成本分配標籤頁面上。

調用模型

若要調用模型,請使用應用程式推論設定檔。如果是模型識別碼,請指定應用程式推論設定檔的 ARN,而不是隨需模型識別碼。

範例:

aws bedrock-runtime converse --region 'us-east-1' \
    --model-id 'arn:aws:bedrock:us-east-1:AccountId:application-inference-profile/y1pcpudi2mb7' \
    --messages '[{"role": "user", "content": [{"text": "Hello"}]}]'

輸出範例:

{
    "output": {
        "message": {
            "role": "assistant",
            "content": [
                {
                    "text": "Hello! It's nice to have you here. I'm here to help with whatever you might need. Whether you have a question, need assistance with a topic, or just want to chat, feel free to ask. What can I assist you with today?"
                }
            ]
        }
    },
    "stopReason": "end_turn",
    "usage": {
        "inputTokens": 1,
        "outputTokens": 54,
        "totalTokens": 55
    },
    "metrics": {
        "latencyMs": 889
    }
}