本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立工作階段後,請使用 CreateInvocation API 在工作階段中建立互動群組。對於每個分組,請使用 PutInvocationStep API 操作來儲存每次互動的狀態檢查點,包括文字和影像。
如何在調用中組織調用步驟取決於您的使用案例。例如,如果您的代理程式協助客戶預訂行程,您的調用和調用步驟可能如下所示:
-
調用可以做為客服人員與特定飯店客戶檢查不同晚數之房間可用性對話的文字分組。
-
每個調用步驟可能是客服人員與使用者之間的每個訊息,以及客服人員擷取可用性所採取的每個步驟。
在 PutInvocationStep API 中,您可以匯入與對話相關聯的映像。
-
您最多可以包含 20 個影像。每個影像的大小、高度和寬度分別不得超過 3.75 MB、8000 px 和 8000 px。
-
您可以匯入下列類型的映像:
-
PNG
-
JPEG
-
GIF
-
WEBP
-
CreateInvocation 範例
下列程式碼範例示範如何使用 將調用新增至作用中工作階段 適用於 Python (Boto3) 的 AWS SDK。對於 sessionIdentifier
,您可以指定工作階段的 sessionId 或其 Amazon Resource Name (ARN)。如需 API 的詳細資訊,請參閱 CreateInvocation。
def create_invocation(session_identifier):
try:
invocationId = client.create_invocation(
sessionIdentifier=session_identifier,
description="User asking about weather in Seattle",
invocationId="12345abc-1234-abcd-1234-abcdef123456"
)["invocationId"]
print("invocation created")
return invocationId
except ClientError as e:
print(f"Error: {e}")
PutInvocationSteps 範例
下列程式碼範例示範如何使用 將調用步驟新增至作用中工作階段 適用於 Python (Boto3) 的 AWS SDK。程式碼會從工作目錄中在 中新增文字和映像。對於 sessionIdentifier
,您可以指定工作階段的 sessionId 或其 Amazon Resource Name (ARN)。針對調用識別符,指定調用的唯一識別符 (UUID 格式),以將調用步驟新增至其中。如需 API 的詳細資訊,請參閱 PutInvocationStep。
def put_invocation_step(invocation_identifier, session_identifier):
with open('weather.png', 'rb') as image_file:
weather_image = image_file.read()
try:
client.put_invocation_step(
sessionIdentifier=session_identifier,
invocationIdentifier=invocation_identifier,
invocationStepId="12345abc-1234-abcd-1234-abcdef123456",
invocationStepTime="2023-08-08T12:00:00Z",
payload={
'contentBlocks': [
{
'text': 'What\'s the weather in Seattle?',
},
{
'image': {
'format': 'png',
'source': {'bytes': weather_image}
}
}
]
}
)
print("invocation step created")
except ClientError as e:
print(f"Error: {e}")