בנוף של ימינו של אינטראקציות אחד על אחד עם לקוחות לביצוע הזמנות, הנוהג הרווח ממשיך להסתמך על מלווים אנושיים, אפילו במסגרות כמו בתי קפה מובילים ומפעלי מזון מהיר. גישה מסורתית זו מציבה מספר אתגרים: היא תלויה במידה רבה בתהליכים ידניים, נאבקת להרחיב ביעילות עם דרישות הלקוחות הגוברת, מציגה פוטנציאל לטעויות אנוש ופועלת בתוך שעות מסוימות מזמינות. בנוסף, בשווקים תחרותיים, עסקים שדבקים בתהליכים ידניים בלבד עשויים למצוא את זה מאתגר לספק שירות יעיל ותחרותי. למרות ההתקדמות הטכנולוגית, המודל הממוקד באדם נשאר טבוע עמוק בעיבוד הסדר, מה שמוביל למגבלות אלו.
הסיכוי להשתמש בטכנולוגיה לסיוע בעיבוד הזמנות אחד על אחד זמין כבר זמן מה. עם זאת, הפתרונות הקיימים יכולים לעתים קרובות להתחלק לשתי קטגוריות: מערכות מבוססות כללים הדורשות זמן ומאמץ משמעותיים עבור התקנה ותחזוקה, או מערכות נוקשות שחסרות את הגמישות הנדרשת לאינטראקציות דמויות אדם עם לקוחות. כתוצאה מכך, עסקים וארגונים מתמודדים עם אתגרים ביישום מהיר ויעיל של פתרונות כאלה. למרבה המזל, עם הופעתו של AI ייצור ו מודלים של שפה גדולה (LLMs), כעת ניתן ליצור מערכות אוטומטיות שיכולות להתמודד עם שפה טבעית ביעילות, ועם ציר זמן מואץ של תנועה מואצת.
סלע אמזון הוא שירות מנוהל במלואו המציע מבחר של דגמי יסוד (FM) בעלי ביצועים גבוהים מחברות בינה מלאכותית מובילות כמו AI21 Labs, Anthropic, Cohere, Meta, Stability AI ואמזון באמצעות API יחיד, יחד עם סט רחב של יכולות שאתה צריך לבנות יישומי AI גנרטיביים עם אבטחה, פרטיות ו-AI אחראי. בנוסף ל-Amazon Bedrock, אתה יכול להשתמש בשירותי AWS אחרים כמו אמזון SageMaker JumpStart ו אמזון לקס ליצור סוכני עיבוד הזמנות בינה מלאכותית אוטומטית לחלוטין וניתנת להתאמה בקלות.
בפוסט זה, אנו מראים לך כיצד לבנות סוכן עיבוד הזמנות בעל יכולת דיבור באמצעות Amazon Lex, Amazon Bedrock ו AWS למבדה.
סקירת פתרונות
התרשים הבא ממחיש את ארכיטקטורת הפתרונות שלנו.
זרימת העבודה מורכבת מהשלבים הבאים:
- לקוח מבצע את ההזמנה באמצעות Amazon Lex.
- הבוט של Amazon Lex מפרש את כוונות הלקוח ומפעיל א
DialogCodeHook
.
- פונקציית Lambda מושכת את תבנית ההנחיות המתאימה משכבת Lambda ומעצבת הנחיות מודל על ידי הוספת קלט הלקוח בתבנית ההנחיות המשויכת.
- השמיים
RequestValidation
הנחיה מאמתת את ההזמנה עם פריט התפריט ומודיעה ללקוח דרך Amazon Lex אם יש משהו שהוא רוצה להזמין שאינו חלק מהתפריט ויספק המלצות. ההנחיה גם מבצעת אימות ראשוני לשלמות ההזמנה.
- השמיים
ObjectCreator
הנחיה ממירה את בקשות השפה הטבעית למבנה נתונים (פורמט JSON).
- פונקציית אימות הלקוח Lambda מאמתת את התכונות הנדרשות להזמנה ומאשרת אם כל המידע הדרוש לעיבוד ההזמנה קיים.
- פונקציית Lambda של לקוח לוקחת את מבנה הנתונים כקלט לעיבוד ההזמנה ומעבירה את סך ההזמנה בחזרה לפונקציית Lambda המתזמרת.
- פונקציית Lambda המתזמרת קוראת לנקודת הקצה Amazon Bedrock LLM כדי ליצור סיכום הזמנה סופי הכולל את סך ההזמנות ממערכת מסד הנתונים של הלקוחות (לדוגמה, אמזון דינמו).
- סיכום ההזמנה מועבר בחזרה ללקוח באמצעות Amazon Lex. לאחר שהלקוח יאשר את ההזמנה, ההזמנה תטופל.
תנאים מוקדמים
פוסט זה מניח שיש לך חשבון AWS פעיל והיכרות עם המושגים והשירותים הבאים:
כמו כן, על מנת לגשת ל- Amazon Bedrock מפונקציות Lambda, עליך לוודא שלזמן הריצה של Lambda יש את הספריות הבאות:
- boto3>=1.28.57
- awscli>=1.29.57
- botocore>=1.31.57
ניתן לעשות זאת באמצעות א שכבת למדה או באמצעות AMI ספציפי עם הספריות הנדרשות.
יתר על כן, ספריות אלו נדרשות בעת קריאה ל-Amazon Bedrock API מ סטודיו SageMaker של אמזון. ניתן לעשות זאת על ידי הפעלת תא עם הקוד הבא:
%pip install --no-build-isolation --force-reinstall
"boto3>=1.28.57"
"awscli>=1.29.57"
"botocore>=1.31.57"
לבסוף, אתה יוצר את המדיניות הבאה ומצרף אותה מאוחר יותר לכל תפקיד הניגש ל- Amazon Bedrock:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": "bedrock:*",
"Resource": "*"
}
]
}
צור טבלה של DynamoDB
בתרחיש הספציפי שלנו, יצרנו טבלת DynamoDB כמערכת מסד הנתונים של הלקוחות שלנו, אבל אתה יכול גם להשתמש שירות מסדי נתונים יחסי של אמזון (Amazon RDS). השלם את השלבים הבאים כדי לספק את טבלת DynamoDB שלך (או התאם אישית את ההגדרות לפי הצורך עבור מקרה השימוש שלך):
- במסוף DynamoDB בחר לוחות בחלונית הניווט.
- בחרו צור טבלה.
- בעד שם טבלה, הזן שם (לדוגמה,
ItemDetails
).
- בעד מפתח מחיצה, הזן מפתח (עבור פוסט זה אנו משתמשים
Item
).
- בעד מפתח מיון, הזן מפתח (עבור פוסט זה אנו משתמשים
Size
).
- בחרו צור טבלה.
כעת אתה יכול לטעון את הנתונים לטבלת DynamoDB. עבור פוסט זה, אנו משתמשים בקובץ CSV. אתה יכול לטעון את הנתונים לטבלת DynamoDB באמצעות קוד Python במחברת SageMaker.
ראשית, עלינו להגדיר פרופיל בשם dev.
- פתח מסוף חדש ב- SageMaker Studio והפעל את הפקודה הבאה:
aws configure --profile dev
פקודה זו תבקש ממך להזין את מזהה מפתח הגישה של AWS, מפתח הגישה הסודי, אזור ברירת המחדל של AWS ופורמט הפלט.
- חזור למחברת SageMaker וכתוב קוד Python כדי להגדיר חיבור ל-DynamoDB באמצעות ספריית Boto3 ב-Python. קטע קוד זה יוצר הפעלה באמצעות פרופיל AWS ספציפי בשם dev ולאחר מכן יוצר לקוח DynamoDB באמצעות הפעלה זו. להלן דגימת הקוד לטעינת הנתונים:
%pip install boto3
import boto3
import csv
# Create a session using a profile named 'dev'
session = boto3.Session(profile_name='dev')
# Create a DynamoDB resource using the session
dynamodb = session.resource('dynamodb')
# Specify your DynamoDB table name
table_name = 'your_table_name'
table = dynamodb.Table(table_name)
# Specify the path to your CSV file
csv_file_path = 'path/to/your/file.csv'
# Read CSV file and put items into DynamoDB
with open(csv_file_path, 'r', encoding='utf-8-sig') as csvfile:
csvreader = csv.reader(csvfile)
# Skip the header row
next(csvreader, None)
for row in csvreader:
# Extract values from the CSV row
item = {
'Item': row[0], # Adjust the index based on your CSV structure
'Size': row[1],
'Price': row[2]
}
# Put item into DynamoDB
response = table.put_item(Item=item)
print(f"Item added: {response}")
print(f"CSV data has been loaded into the DynamoDB table: {table_name}")
לחלופין, ניתן להשתמש שולחן עבודה NoSQL או כלים אחרים לטעינה מהירה של הנתונים לטבלת DynamoDB שלך.
להלן צילום מסך לאחר הוספת הנתונים לדוגמה לטבלה.
צור תבניות במחברת SageMaker באמצעות ה-API של Amazon Bedrock Invocation
כדי ליצור את תבנית ההנחיה שלנו עבור מקרה שימוש זה, אנו משתמשים ב- Amazon Bedrock. אתה יכול לגשת ל- Amazon Bedrock מה- קונסולת הניהול של AWS ובאמצעות קריאות API. במקרה שלנו, אנו ניגשים ל-Amazon Bedrock דרך API מהנוחות של מחברת SageMaker Studio כדי ליצור לא רק את תבנית ההנחיה שלנו, אלא את קוד הפקת ה-API המלא שלנו, שבו נוכל להשתמש מאוחר יותר בפונקציית Lambda שלנו.
- במסוף SageMaker, גש לדומיין קיים של SageMaker Studio או צור דומיין חדש כדי לגשת ל- Amazon Bedrock ממחברת SageMaker.
- לאחר שתיצור את הדומיין והמשתמש של SageMaker, בחר את המשתמש ובחר לשגר ו סטודיו. פעולה זו תפתח סביבת JupyterLab.
- כאשר סביבת JupyterLab מוכנה, פתח מחברת חדשה והתחל לייבא את הספריות הדרושות.
יש הרבה FMs זמינים דרך Amazon Bedrock Python SDK. במקרה זה, אנו משתמשים ב-Claude V2, מודל יסוד חזק שפותח על ידי Anthropic.
סוכן עיבוד ההזמנות צריך כמה תבניות שונות. זה יכול להשתנות בהתאם למקרה השימוש, אבל תכננו זרימת עבודה כללית שיכולה לחול על מספר הגדרות. עבור מקרה שימוש זה, תבנית Amazon Bedrock LLM תשיג את הדברים הבאים:
- אמת את כוונת הלקוח
- אמת את הבקשה
- צור את מבנה נתוני ההזמנה
- העברת סיכום ההזמנה ללקוח
- כדי להפעיל את המודל, צור אובייקט בזמן ריצה של סלע מ-Boto3.
#Model api request parameters
modelId = 'anthropic.claude-v2' # change this to use a different version from the model provider
accept = 'application/json'
contentType = 'application/json'
import boto3
import json
bedrock = boto3.client(service_name='bedrock-runtime')
נתחיל בעבודה על תבנית הבקשה לאימות הכוונות. זהו תהליך איטרטיבי, אך הודות למדריך ההנדסי המהיר של Anthropic, אתה יכול ליצור במהירות הנחיה שיכולה לבצע את המשימה.
- צור את תבנית ההנחיה הראשונה יחד עם פונקציית עזר שתעזור להכין את הגוף לקריאת ה-API.
להלן הקוד עבור prompt_template_intent_validator.txt:
"{"prompt": "Human: I will give you some instructions to complete my request.n<instructions>Given the Conversation between Human and Assistant, you need to identify the intent that the human wants to accomplish and respond appropriately. The valid intents are: Greeting,Place Order, Complain, Speak to Someone. Always put your response to the Human within the Response tags. Also add an XML tag to your output identifying the human intent.nHere are some examples:n<example><Conversation> H: hi there.nnA: Hi, how can I help you today?nnH: Yes. I would like a medium mocha please</Conversation>nnA:<intent>Place Order</intent><Response>nGot it.</Response></example>n<example><Conversation> H: hellonnA: Hi, how can I help you today?nnH: my coffee does not taste well can you please re-make it?</Conversation>nnA:<intent>Complain</intent><Response>nOh, I am sorry to hear that. Let me get someone to help you.</Response></example>n<example><Conversation> H: hinnA: Hi, how can I help you today?nnH: I would like to speak to someone else please</Conversation>nnA:<intent>Speak to Someone</intent><Response>nSure, let me get someone to help you.</Response></example>n<example><Conversation> H: howdynnA: Hi, how can I help you today?nnH:can I get a large americano with sugar and 2 mochas with no whipped cream</Conversation>nnA:<intent>Place Order</intent><Response>nSure thing! Please give me a moment.</Response></example>n<example><Conversation> H: hinn</Conversation>nnA:<intent>Greeting</intent><Response>nHi there, how can I help you today?</Response></example>n</instructions>nnPlease complete this request according to the instructions and examples provided above:<request><Conversation>REPLACEME</Conversation></request>nnAssistant:n", "max_tokens_to_sample": 250, "temperature": 1, "top_k": 250, "top_p": 0.75, "stop_sequences": ["nnHuman:", "nnhuman:", "nnCustomer:", "nncustomer:"]}"
- שמור תבנית זו בקובץ כדי להעלות לאמזון S3 ולהתקשר מפונקציית Lambda בעת הצורך. שמור את התבניות כמחרוזות מסודרות של JSON בקובץ טקסט. צילום המסך הקודם מציג את דוגמת הקוד כדי להשיג זאת גם כן.
- חזור על אותם שלבים עם שאר התבניות.
להלן כמה צילומי מסך של התבניות האחרות והתוצאות כאשר קוראים ל- Amazon Bedrock עם חלק מהן.
להלן הקוד עבור prompt_template_request_validator.txt:
"{"prompt": "Human: I will give you some instructions to complete my request.n<instructions>Given the context do the following steps: 1. verify that the items in the input are valid. If customer provided an invalid item, recommend replacing it with a valid one. 2. verify that the customer has provided all the information marked as required. If the customer missed a required information, ask the customer for that information. 3. When the order is complete, provide a summary of the order and ask for confirmation always using this phrase: 'is this correct?' 4. If the customer confirms the order, Do not ask for confirmation again, just say the phrase inside the brackets [Great, Give me a moment while I try to process your order]</instructions>n<context>nThe VALID MENU ITEMS are: [latte, frappe, mocha, espresso, cappuccino, romano, americano].nThe VALID OPTIONS are: [splenda, stevia, raw sugar, honey, whipped cream, sugar, oat milk, soy milk, regular milk, skimmed milk, whole milk, 2 percent milk, almond milk].nThe required information is: size. Size can be: small, medium, large.nHere are some examples: <example>H: I would like a medium latte with 1 Splenda and a small romano with no sugar please.nnA: <Validation>:nThe Human is ordering a medium latte with one splenda. Latte is a valid menu item and splenda is a valid option. The Human is also ordering a small romano with no sugar. Romano is a valid menu item.</Validation>n<Response>nOk, I got: nt-Medium Latte with 1 Splenda and.nt-Small Romano with no Sugar.nIs this correct?</Response>nnH: yep.nnA:n<Response>nGreat, Give me a moment while I try to process your order</example>nn<example>H: I would like a cappuccino and a mocha please.nnA: <Validation>:nThe Human is ordering a cappuccino and a mocha. Both are valid menu items. The Human did not provide the size for the cappuccino. The human did not provide the size for the mocha. I will ask the Human for the required missing information.</Validation>n<Response>nSure thing, but can you please let me know the size for the Cappuccino and the size for the Mocha? We have Small, Medium, or Large.</Response></example>nn<example>H: I would like a small cappuccino and a large lemonade please.nnA: <Validation>:nThe Human is ordering a small cappuccino and a large lemonade. Cappuccino is a valid menu item. Lemonade is not a valid menu item. I will suggest the Human a replacement from our valid menu items.</Validation>n<Response>nSorry, we don't have Lemonades, would you like to order something else instead? Perhaps a Frappe or a Latte?</Response></example>nn<example>H: Can I get a medium frappuccino with sugar please?nnA: <Validation>:n The Human is ordering a Frappuccino. Frappuccino is not a valid menu item. I will suggest a replacement from the valid menu items in my context.</Validation>n<Response>nI am so sorry, but Frappuccino is not in our menu, do you want a frappe or a cappuccino instead? perhaps something else?</Response></example>nn<example>H: I want two large americanos and a small latte please.nnA: <Validation>:n The Human is ordering 2 Large Americanos, and a Small Latte. Americano is a valid menu item. Latte is a valid menu item.</Validation>n<Response>nOk, I got: nt-2 Large Americanos and.nt-Small Latte.nIs this correct?</Response>nnH: looks correct, yes.nnA:n<Response>nGreat, Give me a moment while I try to process your order.</Response></example>nn</Context>nnPlease complete this request according to the instructions and examples provided above:<request>REPLACEME</request>nnAssistant:n", "max_tokens_to_sample": 250, "temperature": 0.3, "top_k": 250, "top_p": 0.75, "stop_sequences": ["nnHuman:", "nnhuman:", "nnCustomer:", "nncustomer:"]}"
להלן תגובתנו מאמזון Bedrock באמצעות תבנית זו.
להלן הקוד עבור prompt_template_object_creator.txt
:
"{"prompt": "Human: I will give you some instructions to complete my request.n<instructions>Given the Conversation between Human and Assistant, you need to create a json object in Response with the appropriate attributes.nHere are some examples:n<example><Conversation> H: I want a latte.nnA:nCan I have the size?nnH: Medium.nnA: So, a medium latte.nIs this Correct?nnH: Yes.</Conversation>nnA:<Response>{"1":{"item":"latte","size":"medium","addOns":[]}}</Response></example>n<example><Conversation> H: I want a large frappe and 2 small americanos with sugar.nnA: Okay, let me confirm:nn1 large frappenn2 small americanos with sugarnnIs this correct?nnH: Yes.</Conversation>nnA:<Response>{"1":{"item":"frappe","size":"large","addOns":[]},"2":{"item":"americano","size":"small","addOns":["sugar"]},"3":{"item":"americano","size":"small","addOns":["sugar"]}}</Response>n</example>n<example><Conversation> H: I want a medium americano.nnA: Okay, let me confirm:nn1 medium americanonnIs this correct?nnH: Yes.</Conversation>nnA:<Response>{"1":{"item":"americano","size":"medium","addOns":[]}}</Response></example>n<example><Conversation> H: I want a large latte with oatmilk.nnA: Okay, let me confirm:nnLarge latte with oatmilknnIs this correct?nnH: Yes.</Conversation>nnA:<Response>{"1":{"item":"latte","size":"large","addOns":["oatmilk"]}}</Response></example>n<example><Conversation> H: I want a small mocha with no whipped cream please.nnA: Okay, let me confirm:nnSmall mocha with no whipped creamnnIs this correct?nnH: Yes.</Conversation>nnA:<Response>{"1":{"item":"mocha","size":"small","addOns":["no whipped cream"]}}</Response>nn</example></instructions>nnPlease complete this request according to the instructions and examples provided above:<request><Conversation>REPLACEME</Conversation></request>nnAssistant:n", "max_tokens_to_sample": 250, "temperature": 0.3, "top_k": 250, "top_p": 0.75, "stop_sequences": ["nnHuman:", "nnhuman:", "nnCustomer:", "nncustomer:"]}"
להלן הקוד עבור prompt_template_order_summary.txt:
"{"prompt": "Human: I will give you some instructions to complete my request.n<instructions>Given the Conversation between Human and Assistant, you need to create a summary of the order with bullet points and include the order total.nHere are some examples:n<example><Conversation> H: I want a large frappe and 2 small americanos with sugar.nnA: Okay, let me confirm:nn1 large frappenn2 small americanos with sugarnnIs this correct?nnH: Yes.</Conversation>nn<OrderTotal>10.50</OrderTotal>nnA:<Response>nHere is a summary of your order along with the total:nn1 large frappenn2 small americanos with sugar.nYour Order total is $10.50</Response></example>n<example><Conversation> H: I want a medium americano.nnA: Okay, let me confirm:nn1 medium americanonnIs this correct?nnH: Yes.</Conversation>nn<OrderTotal>3.50</OrderTotal>nnA:<Response>nHere is a summary of your order along with the total:nn1 medium americano.nYour Order total is $3.50</Response></example>n<example><Conversation> H: I want a large latte with oat milk.nnA: Okay, let me confirm:nnLarge latte with oat milknnIs this correct?nnH: Yes.</Conversation>nn<OrderTotal>6.75</OrderTotal>nnA:<Response>nHere is a summary of your order along with the total:nnLarge latte with oat milk.nYour Order total is $6.75</Response></example>n<example><Conversation> H: I want a small mocha with no whipped cream please.nnA: Okay, let me confirm:nnSmall mocha with no whipped creamnnIs this correct?nnH: Yes.</Conversation>nn<OrderTotal>4.25</OrderTotal>nnA:<Response>nHere is a summary of your order along with the total:nnSmall mocha with no whipped cream.nYour Order total is $6.75</Response>nn</example>n</instructions>nnPlease complete this request according to the instructions and examples provided above:<request><Conversation>REPLACEME</Conversation>nn<OrderTotal>REPLACETOTAL</OrderTotal></request>nnAssistant:n", "max_tokens_to_sample": 250, "temperature": 0.3, "top_k": 250, "top_p": 0.75, "stop_sequences": ["nnHuman:", "nnhuman:", "nnCustomer:", "nncustomer:", "[Conversation]"]}"
כפי שאתה יכול לראות, השתמשנו בתבניות ההנחיות שלנו כדי לאמת פריטי תפריט, לזהות מידע נדרש חסר, ליצור מבנה נתונים ולסכם את הסדר. המודלים הבסיסיים הזמינים ב- Amazon Bedrock הם חזקים מאוד, כך שתוכל לבצע אפילו יותר משימות באמצעות תבניות אלה.
השלמת את הנדסת ההנחיות ושמרת את התבניות בקבצי טקסט. כעת אתה יכול להתחיל ליצור את הבוט של Amazon Lex ואת פונקציות ה-Lambda הקשורות אליו.
צור שכבת Lambda עם תבניות ההנחיות
השלם את השלבים הבאים כדי ליצור את שכבת ה-Lambda שלך:
- ב-SageMaker Studio, צור תיקייה חדשה עם תיקיית משנה בשם
python
.
- העתק את קבצי ההנחיה שלך ל-
python
תיקייה.
- אתה יכול להוסיף את ספריית ה-ZIP למופע המחברת שלך על ידי הפעלת הפקודה הבאה.
!conda install -y -c conda-forge zip
- כעת, הפעל את הפקודה הבאה כדי ליצור את קובץ ה-ZIP להעלאה לשכבת Lambda.
!zip -r prompt_templates_layer.zip prompt_templates_layer/.
- לאחר שתיצור את קובץ ה-ZIP, תוכל להוריד את הקובץ. עבור אל Lambda, צור שכבה חדשה על ידי העלאת הקובץ ישירות או על ידי העלאה לאמזון S3 תחילה.
- לאחר מכן חבר את השכבה החדשה הזו לפונקציית ה-Lambda התזמורת.
כעת קבצי תבנית ההנחיות שלך מאוחסנים באופן מקומי בסביבת זמן הריצה של Lambda שלך. זה יאיץ את התהליך במהלך ריצות הבוט שלך.
צור שכבת Lambda עם הספריות הנדרשות
השלם את השלבים הבאים כדי ליצור את שכבת ה-Lambda שלך עם הספריות הנדרשות:
- פתח את AWS Cloud9 סביבת מופע, צור תיקיה עם תיקיית משנה בשם
python
.
- פתח מסוף בתוך
python
תיקייה.
- הפעל את הפקודות הבאות מהמסוף:
pip install “boto3>=1.28.57” -t .
pip install “awscli>=1.29.57" -t .
pip install “botocore>=1.31.57” -t .
- הפעלה
cd ..
ותמקם את עצמך בתוך התיקייה החדשה שלך שבה יש לך גם את python
תיקיית משנה.
- הפעל את הפקודה הבאה:
- לאחר שתיצור את קובץ ה-ZIP, תוכל להוריד את הקובץ. עבור אל Lambda, צור שכבה חדשה על ידי העלאת הקובץ ישירות או על ידי העלאה לאמזון S3 תחילה.
- לאחר מכן חבר את השכבה החדשה הזו לפונקציית ה-Lambda התזמורת.
צור את הבוט ב- Amazon Lex v2
עבור מקרה שימוש זה, אנו בונים בוט של Amazon Lex שיכול לספק ממשק קלט/פלט לארכיטקטורה על מנת לקרוא לאמזון Bedrock באמצעות קול או טקסט מכל ממשק. מכיוון שה-LLM יטפל בקטע השיחה של סוכן עיבוד ההזמנות הזה, ולמבדה תארגן את זרימת העבודה, אתה יכול ליצור בוט עם שלוש כוונות וללא משבצות.
- בקונסולת Amazon Lex, צור בוט חדש בשיטה צור בוט ריק.
כעת אתה יכול להוסיף כוונה עם כל אמירה ראשונית מתאימה עבור משתמשי הקצה כדי להתחיל את השיחה עם הבוט. אנו משתמשים בברכות פשוטות ומוסיפים תגובת בוט ראשונית כדי שמשתמשי קצה יוכלו לספק את הבקשות שלהם. בעת יצירת הבוט, הקפד להשתמש בהוק קוד Lambda עם הכוונות; זה יפעיל פונקציית Lambda שתארגן את זרימת העבודה בין הלקוח, Amazon Lex וה-LLM.
- הוסף את הכוונה הראשונה שלך, אשר מפעילה את זרימת העבודה ומשתמשת בתבנית הנחיית אימות הכוונה כדי להתקשר לאמזון Bedrock ולזהות מה הלקוח מנסה להשיג. הוסף כמה אמירות פשוטות למשתמשי קצה כדי להתחיל שיחה.
אינך צריך להשתמש בכל משבצות או קריאה ראשונית באף אחת מכוונות הבוט. למעשה, אין צורך להוסיף אמירות לכוונות השניות או השלישיות. הסיבה לכך היא שה-LLM ינחה את Lambda לאורך כל התהליך.
- הוסף בקשת אישור. אתה יכול להתאים אישית הודעה זו בפונקציית Lambda מאוחר יותר.
- תַחַת ווים קוד, בחר השתמש בפונקציית Lambda לאתחול ואימות.
- צור כוונה שנייה ללא אמירה וללא תגובה ראשונית. זה
PlaceOrder
כוונה.
כאשר ה-LLM מזהה שהלקוח מנסה לבצע הזמנה, פונקציית Lambda תפעיל כוונה זו ותאמת את בקשת הלקוח מול התפריט, ותוודא שלא חסר מידע נדרש. זכור שכל זה נמצא בתבניות ההנחיות, כך שתוכל להתאים את זרימת העבודה הזו לכל מקרה שימוש על ידי שינוי תבניות ההנחיות.
- אל תוסיף משבצות, אלא הוסף בקשת אישור ודחה תגובה.
- בחר השתמש בפונקציית Lambda לאתחול ואימות.
- צור כוונה שלישית בשם
ProcessOrder
ללא אמירות לדוגמה וללא משבצות.
- הוסף תגובה ראשונית, בקשת אישור ותגובת דחייה.
לאחר שה-LLM אימת את בקשת הלקוח, פונקציית Lambda מפעילה את הכוונה השלישית והאחרונה לעבד את ההזמנה. כאן, Lambda תשתמש בתבנית יוצר האובייקטים כדי ליצור את מבנה הנתונים של JSON להזמנה כדי לבצע שאילתה בטבלת DynamoDB, ולאחר מכן תשתמש בתבנית סיכום ההזמנה כדי לסכם את כל ההזמנה יחד עם הסכום הכולל כדי שאמזון לקס תוכל להעביר אותה ללקוח.
- בחר השתמש בפונקציית Lambda לאתחול ואימות. זה יכול להשתמש בכל פונקציית Lambda כדי לעבד את ההזמנה לאחר שהלקוח נתן את האישור הסופי.
- לאחר שתיצור את כל שלוש הכוונות, עבור אל בונה החזותי עבור ה
ValidateIntent
, הוסף שלב לכוונה, וחבר את הפלט של האישור החיובי לשלב זה.
- לאחר הוספת כוונת הבחירה, ערוך אותה ובחר בכוונת PlaceOrder כשם הכוונה.
- באופן דומה, ללכת ל-Visual Builder עבור
PlaceOrder
כוונה וחבר את הפלט של האישור החיובי ל- ProcessOrder
ללכת לכוונה. לא נדרשת עריכה עבור ProcessOrder
כוונה.
- כעת עליך ליצור את פונקציית Lambda שמתזמרת את Amazon Lex וקוראת לטבלת DynamoDB, כמפורט בסעיף הבא.
צור פונקציית Lambda כדי לתזמן את הבוט של Amazon Lex
כעת אתה יכול לבנות את פונקציית Lambda שמתזמרת את הבוט של Amazon Lex ואת זרימת העבודה. השלם את השלבים הבאים:
- צור פונקציית Lambda עם מדיניות הביצוע הרגילה ואפשר למבדה ליצור עבורך תפקיד.
- בחלון הקוד של הפונקציה שלכם, הוסיפו כמה פונקציות שירות שיעזרו: עיצוב ההנחיות על ידי הוספת ה-lex context לתבנית, התקשר ל-Amazon Bedrock LLM API, חילץ את הטקסט הרצוי מהתגובות ועוד. ראה את הקוד הבא:
import json
import re
import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
bedrock = boto3.client(service_name='bedrock-runtime')
def CreatingCustomPromptFromLambdaLayer(object_key,replace_items):
folder_path = '/opt/order_processing_agent_prompt_templates/python/'
try:
file_path = folder_path + object_key
with open(file_path, "r") as file1:
raw_template = file1.read()
# Modify the template with the custom input prompt
#template['inputs'][0].insert(1, {"role": "user", "content": '### Input:n' + user_request})
for key,value in replace_items.items():
value = json.dumps(json.dumps(value).replace('"','')).replace('"','')
raw_template = raw_template.replace(key,value)
modified_prompt = raw_template
return modified_prompt
except Exception as e:
return {
'statusCode': 500,
'body': f'An error occurred: {str(e)}'
}
def CreatingCustomPrompt(object_key,replace_items):
logger.debug('replace_items is: {}'.format(replace_items))
#retrieve user request from intent_request
#we first propmt the model with current order
bucket_name = 'your-bucket-name'
#object_key = 'prompt_template_order_processing.txt'
try:
s3 = boto3.client('s3')
# Retrieve the existing template from S3
response = s3.get_object(Bucket=bucket_name, Key=object_key)
raw_template = response['Body'].read().decode('utf-8')
raw_template = json.loads(raw_template)
logger.debug('raw template is {}'.format(raw_template))
#template_json = json.loads(raw_template)
#logger.debug('template_json is {}'.format(template_json))
#template = json.dumps(template_json)
#logger.debug('template is {}'.format(template))
# Modify the template with the custom input prompt
#template['inputs'][0].insert(1, {"role": "user", "content": '### Input:n' + user_request})
for key,value in replace_items.items():
raw_template = raw_template.replace(key,value)
logger.debug("Replacing: {} nwith: {}".format(key,value))
modified_prompt = json.dumps(raw_template)
logger.debug("Modified template: {}".format(modified_prompt))
logger.debug("Modified template type is: {}".format(print(type(modified_prompt))))
#modified_template_json = json.loads(modified_prompt)
#logger.debug("Modified template json: {}".format(modified_template_json))
return modified_prompt
except Exception as e:
return {
'statusCode': 500,
'body': f'An error occurred: {str(e)}'
}
def validate_intent(intent_request):
logger.debug('starting validate_intent: {}'.format(intent_request))
#retrieve user request from intent_request
user_request = 'Human: ' + intent_request['inputTranscript'].lower()
#getting current context variable
current_session_attributes = intent_request['sessionState']['sessionAttributes']
if len(current_session_attributes) > 0:
full_context = current_session_attributes['fullContext'] + 'nn' + user_request
dialog_context = current_session_attributes['dialogContext'] + 'nn' + user_request
else:
full_context = user_request
dialog_context = user_request
#Preparing validation prompt by adding context to prompt template
object_key = 'prompt_template_intent_validator.txt'
#replace_items = {"REPLACEME":full_context}
#replace_items = {"REPLACEME":dialog_context}
replace_items = {"REPLACEME":dialog_context}
#validation_prompt = CreatingCustomPrompt(object_key,replace_items)
validation_prompt = CreatingCustomPromptFromLambdaLayer(object_key,replace_items)
#Prompting model for request validation
intent_validation_completion = prompt_bedrock(validation_prompt)
intent_validation_completion = re.sub(r'["]','',intent_validation_completion)
#extracting response from response completion and removing some special characters
validation_response = extract_response(intent_validation_completion)
validation_intent = extract_intent(intent_validation_completion)
#business logic depending on intents
if validation_intent == 'Place Order':
return validate_request(intent_request)
elif validation_intent in ['Complain','Speak to Someone']:
##adding session attributes to keep current context
full_context = full_context + 'nn' + intent_validation_completion
dialog_context = dialog_context + 'nnAssistant: ' + validation_response
intent_request['sessionState']['sessionAttributes']['fullContext'] = full_context
intent_request['sessionState']['sessionAttributes']['dialogContext'] = dialog_context
intent_request['sessionState']['sessionAttributes']['customerIntent'] = validation_intent
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close',validation_response)
if validation_intent == 'Greeting':
##adding session attributes to keep current context
full_context = full_context + 'nn' + intent_validation_completion
dialog_context = dialog_context + 'nnAssistant: ' + validation_response
intent_request['sessionState']['sessionAttributes']['fullContext'] = full_context
intent_request['sessionState']['sessionAttributes']['dialogContext'] = dialog_context
intent_request['sessionState']['sessionAttributes']['customerIntent'] = validation_intent
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'InProgress','ConfirmIntent',validation_response)
def validate_request(intent_request):
logger.debug('starting validate_request: {}'.format(intent_request))
#retrieve user request from intent_request
user_request = 'Human: ' + intent_request['inputTranscript'].lower()
#getting current context variable
current_session_attributes = intent_request['sessionState']['sessionAttributes']
if len(current_session_attributes) > 0:
full_context = current_session_attributes['fullContext'] + 'nn' + user_request
dialog_context = current_session_attributes['dialogContext'] + 'nn' + user_request
else:
full_context = user_request
dialog_context = user_request
#Preparing validation prompt by adding context to prompt template
object_key = 'prompt_template_request_validator.txt'
replace_items = {"REPLACEME":dialog_context}
#validation_prompt = CreatingCustomPrompt(object_key,replace_items)
validation_prompt = CreatingCustomPromptFromLambdaLayer(object_key,replace_items)
#Prompting model for request validation
request_validation_completion = prompt_bedrock(validation_prompt)
request_validation_completion = re.sub(r'["]','',request_validation_completion)
#extracting response from response completion and removing some special characters
validation_response = extract_response(request_validation_completion)
##adding session attributes to keep current context
full_context = full_context + 'nn' + request_validation_completion
dialog_context = dialog_context + 'nnAssistant: ' + validation_response
intent_request['sessionState']['sessionAttributes']['fullContext'] = full_context
intent_request['sessionState']['sessionAttributes']['dialogContext'] = dialog_context
return close(intent_request['sessionState']['sessionAttributes'],'PlaceOrder','InProgress','ConfirmIntent',validation_response)
def process_order(intent_request):
logger.debug('starting process_order: {}'.format(intent_request))
#retrieve user request from intent_request
user_request = 'Human: ' + intent_request['inputTranscript'].lower()
#getting current context variable
current_session_attributes = intent_request['sessionState']['sessionAttributes']
if len(current_session_attributes) > 0:
full_context = current_session_attributes['fullContext'] + 'nn' + user_request
dialog_context = current_session_attributes['dialogContext'] + 'nn' + user_request
else:
full_context = user_request
dialog_context = user_request
# Preparing object creator prompt by adding context to prompt template
object_key = 'prompt_template_object_creator.txt'
replace_items = {"REPLACEME":dialog_context}
#object_creator_prompt = CreatingCustomPrompt(object_key,replace_items)
object_creator_prompt = CreatingCustomPromptFromLambdaLayer(object_key,replace_items)
#Prompting model for object creation
object_creation_completion = prompt_bedrock(object_creator_prompt)
#extracting response from response completion
object_creation_response = extract_response(object_creation_completion)
inputParams = json.loads(object_creation_response)
inputParams = json.dumps(json.dumps(inputParams))
logger.debug('inputParams is: {}'.format(inputParams))
client = boto3.client('lambda')
response = client.invoke(FunctionName = 'arn:aws:lambda:us-east-1:<AccountNumber>:function:aws-blog-order-validator',InvocationType = 'RequestResponse',Payload = inputParams)
responseFromChild = json.load(response['Payload'])
validationResult = responseFromChild['statusCode']
if validationResult == 205:
order_validation_error = responseFromChild['validator_response']
return close(intent_request['sessionState']['sessionAttributes'],'PlaceOrder','InProgress','ConfirmIntent',order_validation_error)
#invokes Order Processing lambda to query DynamoDB table and returns order total
response = client.invoke(FunctionName = 'arn:aws:lambda:us-east-1: <AccountNumber>:function:aws-blog-order-processing',InvocationType = 'RequestResponse',Payload = inputParams)
responseFromChild = json.load(response['Payload'])
orderTotal = responseFromChild['body']
###Prompting the model to summarize the order along with order total
object_key = 'prompt_template_order_summary.txt'
replace_items = {"REPLACEME":dialog_context,"REPLACETOTAL":orderTotal}
#order_summary_prompt = CreatingCustomPrompt(object_key,replace_items)
order_summary_prompt = CreatingCustomPromptFromLambdaLayer(object_key,replace_items)
order_summary_completion = prompt_bedrock(order_summary_prompt)
#extracting response from response completion
order_summary_response = extract_response(order_summary_completion)
order_summary_response = order_summary_response + '. Shall I finalize processing your order?'
##adding session attributes to keep current context
full_context = full_context + 'nn' + order_summary_completion
dialog_context = dialog_context + 'nnAssistant: ' + order_summary_response
intent_request['sessionState']['sessionAttributes']['fullContext'] = full_context
intent_request['sessionState']['sessionAttributes']['dialogContext'] = dialog_context
return close(intent_request['sessionState']['sessionAttributes'],'ProcessOrder','InProgress','ConfirmIntent',order_summary_response)
""" --- Main handler and Workflow functions --- """
def lambda_handler(event, context):
"""
Route the incoming request based on intent.
The JSON body of the request is provided in the event slot.
"""
logger.debug('event is: {}'.format(event))
return dispatch(event)
def dispatch(intent_request):
"""
Called when the user specifies an intent for this bot. If intent is not valid then returns error name
"""
logger.debug('intent_request is: {}'.format(intent_request))
intent_name = intent_request['sessionState']['intent']['name']
confirmation_state = intent_request['sessionState']['intent']['confirmationState']
# Dispatch to your bot's intent handlers
if intent_name == 'ValidateIntent' and confirmation_state == 'None':
return validate_intent(intent_request)
if intent_name == 'PlaceOrder' and confirmation_state == 'None':
return validate_request(intent_request)
elif intent_name == 'PlaceOrder' and confirmation_state == 'Confirmed':
return process_order(intent_request)
elif intent_name == 'PlaceOrder' and confirmation_state == 'Denied':
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close','Got it. Let me know if I can help you with something else.')
elif intent_name == 'PlaceOrder' and confirmation_state not in ['Denied','Confirmed','None']:
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close','Sorry. I am having trouble completing the request. Let me get someone to help you.')
logger.debug('exiting intent {} here'.format(intent_request['sessionState']['intent']['name']))
elif intent_name == 'ProcessOrder' and confirmation_state == 'None':
return validate_request(intent_request)
elif intent_name == 'ProcessOrder' and confirmation_state == 'Confirmed':
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close','Perfect! Your order has been processed. Please proceed to payment.')
elif intent_name == 'ProcessOrder' and confirmation_state == 'Denied':
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close','Got it. Let me know if I can help you with something else.')
elif intent_name == 'ProcessOrder' and confirmation_state not in ['Denied','Confirmed','None']:
return close(intent_request['sessionState']['sessionAttributes'],intent_request['sessionState']['intent']['name'],'Fulfilled','Close','Sorry. I am having trouble completing the request. Let me get someone to help you.')
logger.debug('exiting intent {} here'.format(intent_request['sessionState']['intent']['name']))
raise Exception('Intent with name ' + intent_name + ' not supported')
def prompt_bedrock(formatted_template):
logger.debug('prompt bedrock input is:'.format(formatted_template))
body = json.loads(formatted_template)
modelId = 'anthropic.claude-v2' # change this to use a different version from the model provider
accept = 'application/json'
contentType = 'application/json'
response = bedrock.invoke_model(body=body, modelId=modelId, accept=accept, contentType=contentType)
response_body = json.loads(response.get('body').read())
response_completion = response_body.get('completion')
logger.debug('response is: {}'.format(response_completion))
#print_ww(response_body.get('completion'))
#print(response_body.get('results')[0].get('outputText'))
return response_completion
#function to extract text between the <Response> and </Response> tags within model completion
def extract_response(response_completion):
if '<Response>' in response_completion:
customer_response = response_completion.replace('<Response>','||').replace('</Response>','').split('||')[1]
logger.debug('modified response is: {}'.format(response_completion))
return customer_response
else:
logger.debug('modified response is: {}'.format(response_completion))
return response_completion
#function to extract text between the <Response> and </Response> tags within model completion
def extract_intent(response_completion):
if '<intent>' in response_completion:
customer_intent = response_completion.replace('<intent>','||').replace('</intent>','||').split('||')[1]
return customer_intent
else:
return customer_intent
def close(session_attributes, intent, fulfillment_state, action_type, message):
#This function prepares the response in the appropiate format for Lex V2
response = {
"sessionState": {
"sessionAttributes":session_attributes,
"dialogAction": {
"type": action_type
},
"intent": {
"name":intent,
"state":fulfillment_state
},
},
"messages":
[{
"contentType":"PlainText",
"content":message,
}]
,
}
return response
- חבר את שכבת ה-Lambda שיצרת קודם לפונקציה הזו.
- בנוסף, צרף את השכבה לתבניות ההנחיות שיצרת.
- בתפקיד ביצוע Lambda, צרף את המדיניות לגישה ל- Amazon Bedrock, שנוצרה קודם לכן.
תפקיד הביצוע של Lambda צריך להיות בעל ההרשאות הבאות.
צרף את הפונקציה Orchestration Lambda לבוט של Amazon Lex
- לאחר שתיצור את הפונקציה בסעיף הקודם, חזור לקונסולת Amazon Lex ונווט אל הבוט שלך.
- תַחַת שפות בחלונית הניווט, בחר אנגלית.
- בעד מָקוֹר, בחר את בוט עיבוד ההזמנה שלך.
- בעד גרסת פונקציה למבדה או כינוי, בחר $LATEST.
- בחרו שמור.
צור פונקציות מסייעות למבדה
השלם את השלבים הבאים כדי ליצור פונקציות Lambda נוספות:
- צור פונקציית Lambda כדי לבצע שאילתה בטבלת DynamoDB שיצרת קודם לכן:
import json
import boto3
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# Initialize the DynamoDB client
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('your-table-name')
def calculate_grand_total(input_data):
# Initialize the total price
total_price = 0
try:
# Loop through each item in the input JSON
for item_id, item_data in input_data.items():
item_name = item_data['item'].lower() # Convert item name to lowercase
item_size = item_data['size'].lower() # Convert item size to lowercase
# Query the DynamoDB table for the item based on Item and Size
response = table.get_item(
Key={'Item': item_name,
'Size': item_size}
)
# Check if the item was found in the table
if 'Item' in response:
item = response['Item']
price = float(item['Price'])
total_price += price # Add the item's price to the total
return total_price
except Exception as e:
raise Exception('An error occurred: {}'.format(str(e)))
def lambda_handler(event, context):
try:
# Parse the input JSON from the Lambda event
input_json = json.loads(event)
# Calculate the grand total
grand_total = calculate_grand_total(input_json)
# Return the grand total in the response
return {'statusCode': 200,'body': json.dumps(grand_total)}
except Exception as e:
return {
'statusCode': 500,
'body': json.dumps('An error occurred: {}'.format(str(e)))
- נווט אל תְצוּרָה לשונית בפונקציית Lambda ובחר הרשאות.
- צרף הצהרת מדיניות מבוססת משאבים המאפשרת לפונקציית Lambda לעיבוד הזמנות להפעיל פונקציה זו.
- נווט לתפקיד הביצוע של IAM עבור פונקציית Lambda זו והוסף מדיניות כדי לגשת לטבלת DynamoDB.
- צור פונקציית Lambda נוספת כדי לאמת אם כל התכונות הנדרשות הועברו מהלקוח. בדוגמה הבאה, אנו מאמתים אם תכונת הגודל נלכדת עבור הזמנה:
import json
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, context):
# Define customer orders from the input event
customer_orders = json.loads(event)
# Initialize a list to collect error messages
order_errors = {}
missing_size = []
error_messages = []
# Iterate through each order in customer_orders
for order_id, order in customer_orders.items():
if "size" not in order or order["size"] == "":
missing_size.append(order['item'])
order_errors['size'] = missing_size
if order_errors:
items_missing_size = order_errors['size']
error_message = f"could you please provide the size for the following items: {', '.join(items_missing_size)}?"
error_messages.append(error_message)
# Prepare the response message
if error_messages:
response_message = "n".join(error_messages)
return {
'statusCode': 205,
'validator_response': response_message
}
else:
response_message = "Order is validated successfully"
return {
'statusCode': 200,
'validator_response': response_message
}
- נווט אל תְצוּרָה לשונית בפונקציית Lambda ובחר הרשאות.
- צרף הצהרת מדיניות מבוססת משאבים המאפשרת לפונקציית Lambda לעיבוד הזמנות להפעיל פונקציה זו.
בדוק את הפתרון
כעת נוכל לבדוק את הפתרון עם הזמנות לדוגמה שלקוחות מבצעים דרך Amazon Lex.
לדוגמא הראשונה שלנו, הלקוח ביקש פרפוצ'ינו, שאינו בתפריט. המודל מאמת בעזרת תבנית אימות הזמנות ומציע כמה המלצות על סמך התפריט. לאחר שהלקוח מאשר את הזמנתו, הוא מקבל הודעה על סך ההזמנה וסיכום ההזמנה. ההזמנה תטופל בהתאם לאישור הסופי של הלקוח.
בדוגמה הבאה שלנו, הלקוח מזמין קפוצ'ינו גדול ולאחר מכן משנה את הגודל מגדול לבינוני. הדגם לוכד את כל השינויים הנדרשים ומבקש מהלקוח לאשר את ההזמנה. המודל מציג את סך ההזמנה וסיכום ההזמנה, ומעבד את ההזמנה על סמך האישור הסופי של הלקוח.
לדוגמא האחרונה שלנו, הלקוח ביצע הזמנה עבור מספר פריטים והגודל חסר עבור כמה פריטים. המודל ופונקציית Lambda יוודאו אם כל התכונות הנדרשות קיימות לעיבוד ההזמנה ולאחר מכן יבקשו מהלקוח לספק את המידע החסר. לאחר שהלקוח מספק את המידע החסר (במקרה זה, גודל הקפה), יוצגו לו סך ההזמנה וסיכום ההזמנה. ההזמנה תטופל בהתאם לאישור הסופי של הלקוח.
מגבלות LLM
פלטי LLM הם סטוכסטיים מטבעם, מה שאומר שהתוצאות מה-LLM שלנו יכולות להשתנות בפורמט, או אפילו בצורה של תוכן לא אמיתי (הזיות). לכן, מפתחים צריכים להסתמך על לוגיקה טובה לטיפול בשגיאות בכל הקוד שלהם על מנת להתמודד עם תרחישים אלו ולהימנע מחוויית משתמש קצה מושפלת.
לנקות את
אם אינך זקוק עוד לפתרון זה, תוכל למחוק את המשאבים הבאים:
- פונקציות למבדה
- קופסת אמזון לקס
- שולחן DynamoDB
- דלי S3
בנוסף, כבה את מופע SageMaker Studio אם היישום אינו נדרש עוד.
הערכת עלויות
למידע על תמחור עבור השירותים העיקריים המשמשים פתרון זה, ראה את הפרטים הבאים:
שים לב שאתה יכול להשתמש ב- Claude v2 ללא צורך בהקצאה, כך שהעלויות הכוללות נשארות למינימום. כדי להפחית עוד יותר עלויות, אתה יכול להגדיר את טבלת DynamoDB עם ההגדרה לפי דרישה.
סיכום
פוסט זה הדגים כיצד לבנות סוכן עיבוד הזמנות בינה מלאכותית התומכת בדיבור באמצעות Amazon Lex, Amazon Bedrock ושירותי AWS אחרים. הראינו כיצד הנדסה מהירה עם מודל AI יצירתי רב עוצמה כמו קלוד יכולה לאפשר הבנת שפה טבעית חזקה וזרימות שיחה לעיבוד הזמנות ללא צורך בנתוני הדרכה נרחבים.
ארכיטקטורת הפתרון משתמשת ברכיבים ללא שרת כמו Lambda, Amazon S3 ו-DynamoDB כדי לאפשר יישום גמיש וניתן להרחבה. אחסון תבניות ההנחיה באמזון S3 מאפשר לך להתאים אישית את הפתרון למקרי שימוש שונים.
השלבים הבאים יכולים לכלול הרחבת היכולות של הסוכן לטיפול במגוון רחב יותר של בקשות לקוחות ומקרי קצה. תבניות ההנחיות מספקות דרך לשפר באופן איטרטיבי את כישורי הסוכן. התאמות אישיות נוספות יכולות לכלול שילוב של נתוני ההזמנה עם מערכות קצה כמו מלאי, CRM או קופה. לבסוף, הסוכן יכול להיות זמין בנקודות מגע שונות של לקוחות כמו אפליקציות לנייד, נסיעה, קיוסקים ועוד באמצעות היכולות הרב-ערוציות של Amazon Lex.
למידע נוסף, עיין במשאבים הקשורים הבאים:
- פריסה וניהול בוטים מרובי-ערוצים:
- הנדסה מהירה עבור קלוד ודגמים אחרים:
- דפוסים ארכיטקטוניים ללא שרת עבור עוזרי AI ניתנים להרחבה:
על הכותבים
מומיטה דוטה הוא אדריכל פתרונות שותפים בשירותי האינטרנט של אמזון. בתפקידה, היא משתפת פעולה באופן הדוק עם שותפים לפיתוח נכסים ניתנים להרחבה ושימוש חוזר המייעלים פריסות ענן ומשפרים את היעילות התפעולית. היא חברה בקהילת AI/ML ומומחית AI Generative ב-AWS. בשעות הפנאי שלה היא נהנית מגינון ורכיבה על אופניים.
פרננדו לממוגליה הוא ארכיטקט פתרונות שותפים בשירותי האינטרנט של אמזון, עובד בשיתוף פעולה הדוק עם שותפי AWS בהובלת הפיתוח והאימוץ של פתרונות AI מתקדמים ביחידות עסקיות. מנהיג אסטרטגי עם מומחיות בארכיטקטורת ענן, AI גנרטיבי, למידת מכונה וניתוח נתונים. הוא מתמחה בביצוע אסטרטגיות יציאה לשוק ובמתן פתרונות בינה מלאכותית משפיעה בהתאם ליעדים הארגוניים. בזמנו הפנוי הוא אוהב לבלות עם משפחתו ולטייל במדינות אחרות.
מיטול פאטל הוא ארכיטקט פתרונות בכיר בחברת Amazon Web Services. בתפקידו כמאפשר טכנולוגיית ענן, הוא עובד עם לקוחות כדי להבין את המטרות והאתגרים שלהם, ומספק הדרכה מרשימה להשגת מטרתם עם הצעות AWS. הוא חבר בקהילת AI/ML ושגריר AI Generative ב-AWS. בזמנו הפנוי הוא נהנה לטייל ולשחק כדורגל.