2.6 MiB
2.6 MiB
In [1]:
class FakeDatabase:
def __init__(self):
self.customers = [
{"id": "1213210", "name": "John Doe", "email": "john@gmail.com", "phone": "123-456-7890", "username": "johndoe"},
{"id": "2837622", "name": "Priya Patel", "email": "priya@candy.com", "phone": "987-654-3210", "username": "priya123"},
{"id": "3924156", "name": "Liam Nguyen", "email": "lnguyen@yahoo.com", "phone": "555-123-4567", "username": "liamn"},
{"id": "4782901", "name": "Aaliyah Davis", "email": "aaliyahd@hotmail.com", "phone": "111-222-3333", "username": "adavis"},
{"id": "5190753", "name": "Hiroshi Nakamura", "email": "hiroshi@gmail.com", "phone": "444-555-6666", "username": "hiroshin"},
{"id": "6824095", "name": "Fatima Ahmed", "email": "fatimaa@outlook.com", "phone": "777-888-9999", "username": "fatimaahmed"},
{"id": "7135680", "name": "Alejandro Rodriguez", "email": "arodriguez@protonmail.com", "phone": "222-333-4444", "username": "alexr"},
{"id": "8259147", "name": "Megan Anderson", "email": "megana@gmail.com", "phone": "666-777-8888", "username": "manderson"},
{"id": "9603481", "name": "Kwame Osei", "email": "kwameo@yahoo.com", "phone": "999-000-1111", "username": "kwameo"},
{"id": "1057426", "name": "Mei Lin", "email": "meilin@gmail.com", "phone": "333-444-5555", "username": "mlin"}
]
self.orders = [
{"id": "24601", "customer_id": "1213210", "product": "Wireless Headphones", "quantity": 1, "price": 79.99, "status": "Shipped"},
{"id": "13579", "customer_id": "1213210", "product": "Smartphone Case", "quantity": 2, "price": 19.99, "status": "Processing"},
{"id": "97531", "customer_id": "2837622", "product": "Bluetooth Speaker", "quantity": 1, "price": "49.99", "status": "Shipped"},
{"id": "86420", "customer_id": "3924156", "product": "Fitness Tracker", "quantity": 1, "price": 129.99, "status": "Delivered"},
{"id": "54321", "customer_id": "4782901", "product": "Laptop Sleeve", "quantity": 3, "price": 24.99, "status": "Shipped"},
{"id": "19283", "customer_id": "5190753", "product": "Wireless Mouse", "quantity": 1, "price": 34.99, "status": "Processing"},
{"id": "74651", "customer_id": "6824095", "product": "Gaming Keyboard", "quantity": 1, "price": 89.99, "status": "Delivered"},
{"id": "30298", "customer_id": "7135680", "product": "Portable Charger", "quantity": 2, "price": 29.99, "status": "Shipped"},
{"id": "47652", "customer_id": "8259147", "product": "Smartwatch", "quantity": 1, "price": 199.99, "status": "Processing"},
{"id": "61984", "customer_id": "9603481", "product": "Noise-Cancelling Headphones", "quantity": 1, "price": 149.99, "status": "Shipped"},
{"id": "58243", "customer_id": "1057426", "product": "Wireless Earbuds", "quantity": 2, "price": 99.99, "status": "Delivered"},
{"id": "90357", "customer_id": "1213210", "product": "Smartphone Case", "quantity": 1, "price": 19.99, "status": "Shipped"},
{"id": "28164", "customer_id": "2837622", "product": "Wireless Headphones", "quantity": 2, "price": 79.99, "status": "Processing"}
]
def get_user(self, key, value):
if key in {"email", "phone", "username"}:
for customer in self.customers:
if customer[key] == value:
return customer
return f"Couldn't find a user with {key} of {value}"
else:
raise ValueError(f"Invalid key: {key}")
def get_order_by_id(self, order_id):
for order in self.orders:
if order["id"] == order_id:
return order
return None
def get_customer_orders(self, customer_id):
return [order for order in self.orders if order["customer_id"] == customer_id]
def cancel_order(self, order_id):
order = self.get_order_by_id(order_id)
if order:
if order["status"] == "Processing":
order["status"] = "Cancelled"
return "Cancelled the order"
else:
return "Order has already shipped. Can't cancel it."
return "Can't find that order!"In [2]:
db = FakeDatabase()In [3]:
db.get_user("email", "john@gmail.com")Out [3]:
{'id': '1213210',
'name': 'John Doe',
'email': 'john@gmail.com',
'phone': '123-456-7890',
'username': 'johndoe'}In [4]:
db.get_user("username", "adavis")Out [4]:
{'id': '4782901',
'name': 'Aaliyah Davis',
'email': 'aaliyahd@hotmail.com',
'phone': '111-222-3333',
'username': 'adavis'}In [5]:
db.get_user("phone", "666-777-8888")Out [5]:
{'id': '8259147',
'name': 'Megan Anderson',
'email': 'megana@gmail.com',
'phone': '666-777-8888',
'username': 'manderson'}In [6]:
db.get_customer_orders("1213210")Out [6]:
[{'id': '24601',
'customer_id': '1213210',
'product': 'Wireless Headphones',
'quantity': 1,
'price': 79.99,
'status': 'Shipped'},
{'id': '13579',
'customer_id': '1213210',
'product': 'Smartphone Case',
'quantity': 2,
'price': 19.99,
'status': 'Processing'},
{'id': '90357',
'customer_id': '1213210',
'product': 'Smartphone Case',
'quantity': 1,
'price': 19.99,
'status': 'Shipped'}]In [7]:
db.get_customer_orders("9603481")Out [7]:
[{'id': '61984',
'customer_id': '9603481',
'product': 'Noise-Cancelling Headphones',
'quantity': 1,
'price': 149.99,
'status': 'Shipped'}]In [8]:
db.get_order_by_id('24601')Out [8]:
{'id': '24601',
'customer_id': '1213210',
'product': 'Wireless Headphones',
'quantity': 1,
'price': 79.99,
'status': 'Shipped'}In [9]:
#Let's look up an order that has a status of processing:
db.get_order_by_id("47652")Out [9]:
{'id': '47652',
'customer_id': '8259147',
'product': 'Smartwatch',
'quantity': 1,
'price': 199.99,
'status': 'Processing'}In [10]:
#Now let's cancel it!
db.cancel_order("47652")Out [10]:
'Cancelled the order'
In [11]:
# It's status should now be "Cancelled"
db.get_order_by_id("47652")Out [11]:
{'id': '47652',
'customer_id': '8259147',
'product': 'Smartwatch',
'quantity': 1,
'price': 199.99,
'status': 'Cancelled'}In [12]:
tool1 = {
"toolSpec": {
"name": "get_order_by_id",
"description": "Retrieves the details of a specific order based on the order ID. Returns the order ID, product name, quantity, price, and order status.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The unique identifier for the order."
}
},
"required": ["order_id"]
}
}
}
}In [13]:
tool2 = {
"toolSpec": {
"name": "get_user",
"description": "Looks up a user by email, phone, or username.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"key": {
"type": "string",
"enum": ["email", "phone", "username"],
"description": "The attribute to search for a user by (email, phone, or username)."
},
"value": {
"type": "string",
"description": "The value to match for the specified attribute."
}
},
"required": ["key", "value"]
}
}
}
}In [14]:
tools = [
{
"toolSpec": {
"name": "get_user",
"description": "Looks up a user by email, phone, or username.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"key": {
"type": "string",
"enum": ["email", "phone", "username"],
"description": "The attribute to search for a user by (email, phone, or username)."
},
"value": {
"type": "string",
"description": "The value to match for the specified attribute."
}
},
"required": ["key", "value"]
}
}
}
},
{
"toolSpec": {
"name": "get_order_by_id",
"description": "Retrieves the details of a specific order based on the order ID. Returns the order ID, product name, quantity, price, and order status.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The unique identifier for the order."
}
},
"required": ["order_id"]
}
}
}
},
{
"toolSpec": {
"name": "get_customer_orders",
"description": "Retrieves the list of orders belonging to a user based on a user's customer id.",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"customer_id": {
"type": "string",
"description": "The customer_id belonging to the user"
}
},
"required": ["customer_id"]
}
}
}
},
{
"toolSpec": {
"name": "cancel_order",
"description": "Cancels an order based on a provided order_id. Only orders that are 'processing' can be cancelled",
"inputSchema": {
"json": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The order_id pertaining to a particular order"
}
},
"required": ["order_id"]
}
}
}
}
]In [15]:
def process_tool_call(tool_name, tool_input):
if tool_name == "get_user":
return db.get_user(tool_input["key"], tool_input["value"])
elif tool_name == "get_order_by_id":
return db.get_order_by_id(tool_input["order_id"])
elif tool_name == "get_customer_orders":
return db.get_customer_orders(tool_input["customer_id"])
elif tool_name == "cancel_order":
return db.cancel_order(tool_input["order_id"])In [16]:
import boto3
bedrock_client = boto3.client(service_name='bedrock-runtime', region_name="us-west-2")
model_id = "anthropic.claude-3-5-sonnet-20241022-v2:0"
messages = [{"role": "user", "content": [{"text": "Can you look up my orders? My email is john@gmail.com"}]}]
inference_config={"maxTokens":400}
tool_config = {"tools":tools}
# Send the message.
response = bedrock_client.converse(
modelId=model_id,
messages=messages,
inferenceConfig=inference_config,
toolConfig=tool_config,
)In [17]:
print(response["stopReason"])tool_use
In [18]:
import json
# Update messages to include Claude's response
messages.append(response["output"]["message"])
print(response)
#If Claude stops because it wants to use a tool:
if response["stopReason"] == "tool_use":
tool_use = response["output"]["message"]["content"][-1]["toolUse"] #Naive approach assumes only 1 tool is called at a time
tool_name = tool_use["name"]
tool_input = tool_use["input"]
print("Claude wants to use the {tool_name} tool")
print(f"Tool Input:")
print(json.dumps(tool_input, indent=2))
#Actually run the underlying tool functionality on our db
tool_result = process_tool_call(tool_name, tool_input)
print(f"\nTool Result:")
print(json.dumps(tool_result, indent=2))
#Add our tool_result message:
tool_response = {
"role": "user",
"content": [
{
"toolResult": {
"toolUseId": tool_use['toolUseId'],
"content": [
{
"text": json.dumps(tool_result)
}
]
}
}
]
}
messages.append(tool_response)
else:
#If Claude does NOT want to use a tool, just print out the text reponse
print("\nTechNova Support:" + f"{response['output']['message']['content'][0]['text']}"){'ResponseMetadata': {'RequestId': 'c0fa41c8-f176-4d42-80c6-7f91b730e9eb', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Thu, 14 Nov 2024 19:23:58 GMT', 'content-type': 'application/json', 'content-length': '483', 'connection': 'keep-alive', 'x-amzn-requestid': 'c0fa41c8-f176-4d42-80c6-7f91b730e9eb'}, 'RetryAttempts': 0}, 'output': {'message': {'role': 'assistant', 'content': [{'text': "I'll help you look up your orders. Let me first find your user information using your email, and then I can retrieve your orders.\n\nFirst, let's look up your user details:"}, {'toolUse': {'toolUseId': 'tooluse_fJ7fxaWMQmqlI8W3tRXfTw', 'name': 'get_user', 'input': {'key': 'email', 'value': 'john@gmail.com'}}}]}}, 'stopReason': 'tool_use', 'usage': {'inputTokens': 728, 'outputTokens': 114, 'totalTokens': 842}, 'metrics': {'latencyMs': 2726}}
Claude wants to use the {tool_name} tool
Tool Input:
{
"key": "email",
"value": "john@gmail.com"
}
Tool Result:
{
"id": "1213210",
"name": "John Doe",
"email": "john@gmail.com",
"phone": "123-456-7890",
"username": "johndoe"
}
In [19]:
messagesOut [19]:
[{'role': 'user',
'content': [{'text': 'Can you look up my orders? My email is john@gmail.com'}]},
{'role': 'assistant',
'content': [{'text': "I'll help you look up your orders. Let me first find your user information using your email, and then I can retrieve your orders.\n\nFirst, let's look up your user details:"},
{'toolUse': {'toolUseId': 'tooluse_fJ7fxaWMQmqlI8W3tRXfTw',
'name': 'get_user',
'input': {'key': 'email', 'value': 'john@gmail.com'}}}]},
{'role': 'user',
'content': [{'toolResult': {'toolUseId': 'tooluse_fJ7fxaWMQmqlI8W3tRXfTw',
'content': [{'text': '{"id": "1213210", "name": "John Doe", "email": "john@gmail.com", "phone": "123-456-7890", "username": "johndoe"}'}]}}]}]In [20]:
response2 = bedrock_client.converse(
modelId=model_id,
messages=messages,
inferenceConfig=inference_config,
toolConfig=tool_config,
)In [21]:
response2Out [21]:
{'ResponseMetadata': {'RequestId': 'c3ae3ff2-0715-43e7-a1a0-553e4dada84b',
'HTTPStatusCode': 200,
'HTTPHeaders': {'date': 'Thu, 14 Nov 2024 19:24:00 GMT',
'content-type': 'application/json',
'content-length': '360',
'connection': 'keep-alive',
'x-amzn-requestid': 'c3ae3ff2-0715-43e7-a1a0-553e4dada84b'},
'RetryAttempts': 0},
'output': {'message': {'role': 'assistant',
'content': [{'text': "Now, I'll retrieve your orders using your customer ID:"},
{'toolUse': {'toolUseId': 'tooluse_Nb553Vc3SSOwD86cJID1SQ',
'name': 'get_customer_orders',
'input': {'customer_id': '1213210'}}}]}},
'stopReason': 'tool_use',
'usage': {'inputTokens': 898, 'outputTokens': 73, 'totalTokens': 971},
'metrics': {'latencyMs': 1787}}In [22]:
import boto3
bedrock_client = boto3.client(service_name='bedrock-runtime', region_name="us-west-2")
model_id = "anthropic.claude-3-5-sonnet-20241022-v2:0"
class FakeDatabase:
def __init__(self):
self.customers = [
{"id": "1213210", "name": "John Doe", "email": "john@gmail.com", "phone": "123-456-7890", "username": "johndoe"},
{"id": "2837622", "name": "Priya Patel", "email": "priya@candy.com", "phone": "987-654-3210", "username": "priya123"},
{"id": "3924156", "name": "Liam Nguyen", "email": "lnguyen@yahoo.com", "phone": "555-123-4567", "username": "liamn"},
{"id": "4782901", "name": "Aaliyah Davis", "email": "aaliyahd@hotmail.com", "phone": "111-222-3333", "username": "adavis"},
{"id": "5190753", "name": "Hiroshi Nakamura", "email": "hiroshi@gmail.com", "phone": "444-555-6666", "username": "hiroshin"},
{"id": "6824095", "name": "Fatima Ahmed", "email": "fatimaa@outlook.com", "phone": "777-888-9999", "username": "fatimaahmed"},
{"id": "7135680", "name": "Alejandro Rodriguez", "email": "arodriguez@protonmail.com", "phone": "222-333-4444", "username": "alexr"},
{"id": "8259147", "name": "Megan Anderson", "email": "megana@gmail.com", "phone": "666-777-8888", "username": "manderson"},
{"id": "9603481", "name": "Kwame Osei", "email": "kwameo@yahoo.com", "phone": "999-000-1111", "username": "kwameo"},
{"id": "1057426", "name": "Mei Lin", "email": "meilin@gmail.com", "phone": "333-444-5555", "username": "mlin"}
]
self.orders = [
{"id": "24601", "customer_id": "1213210", "product": "Wireless Headphones", "quantity": 1, "price": 79.99, "status": "Shipped"},
{"id": "13579", "customer_id": "1213210", "product": "Smartphone Case", "quantity": 2, "price": 19.99, "status": "Processing"},
{"id": "97531", "customer_id": "2837622", "product": "Bluetooth Speaker", "quantity": 1, "price": "49.99", "status": "Shipped"},
{"id": "86420", "customer_id": "3924156", "product": "Fitness Tracker", "quantity": 1, "price": 129.99, "status": "Delivered"},
{"id": "54321", "customer_id": "4782901", "product": "Laptop Sleeve", "quantity": 3, "price": 24.99, "status": "Shipped"},
{"id": "19283", "customer_id": "5190753", "product": "Wireless Mouse", "quantity": 1, "price": 34.99, "status": "Processing"},
{"id": "74651", "customer_id": "6824095", "product": "Gaming Keyboard", "quantity": 1, "price": 89.99, "status": "Delivered"},
{"id": "30298", "customer_id": "7135680", "product": "Portable Charger", "quantity": 2, "price": 29.99, "status": "Shipped"},
{"id": "47652", "customer_id": "8259147", "product": "Smartwatch", "quantity": 1, "price": 199.99, "status": "Processing"},
{"id": "61984", "customer_id": "9603481", "product": "Noise-Cancelling Headphones", "quantity": 1, "price": 149.99, "status": "Shipped"},
{"id": "58243", "customer_id": "1057426", "product": "Wireless Earbuds", "quantity": 2, "price": 99.99, "status": "Delivered"},
{"id": "90357", "customer_id": "1213210", "product": "Smartphone Case", "quantity": 1, "price": 19.99, "status": "Shipped"},
{"id": "28164", "customer_id": "2837622", "product": "Wireless Headphones", "quantity": 2, "price": 79.99, "status": "Processing"}
]
def get_user(self, key, value):
if key in {"email", "phone", "username"}:
for customer in self.customers:
if customer[key] == value:
return customer
return f"Couldn't find a user with {key} of {value}"
else:
raise ValueError(f"Invalid key: {key}")
def get_order_by_id(self, order_id):
for order in self.orders:
if order["id"] == order_id:
return order
return None
def get_customer_orders(self, customer_id):
return [order for order in self.orders if order["customer_id"] == customer_id]
def cancel_order(self, order_id):
order = self.get_order_by_id(order_id)
if order:
if order["status"] == "Processing":
order["status"] = "Cancelled"
return "Cancelled the order"
else:
return "Order has already shipped. Can't cancel it."
return "Can't find that order!"
db = FakeDatabase()
def process_tool_call(tool_name, tool_input):
if tool_name == "get_user":
return db.get_user(tool_input["key"], tool_input["value"])
elif tool_name == "get_order_by_id":
return db.get_order_by_id(tool_input["order_id"])
elif tool_name == "get_customer_orders":
return db.get_customer_orders(tool_input["customer_id"])
elif tool_name == "cancel_order":
return db.cancel_order(tool_input["order_id"])
def simple_chat():
user_message = input("\nUser: ")
messages = [{"role": "user", "content": [{"text": user_message}]}]
while True:
#If the last message is from the assistant, get another input from the user
if messages[-1].get("role") == "assistant":
user_message = input("\nUser: ")
messages.append({"role": "user", "content": [{"text": user_message}]})
#Send a request to Claude
response = bedrock_client.converse(
modelId=model_id,
messages=messages,
toolConfig={"tools": tools},
)
# Update messages to include Claude's response
messages.append(
response["output"]["message"]
)
#If Claude stops because it wants to use a tool:
if response["stopReason"] == "tool_use":
tool_use = response["output"]["message"]["content"][-1]["toolUse"] #Naive approach assumes only 1 tool is called at a time
tool_name = tool_use["name"]
tool_input = tool_use["input"]
print("Claude wants to use the {tool_name} tool")
print(f"Tool Input:")
print(json.dumps(tool_input, indent=2))
#Actually run the underlying tool functionality on our db
tool_result = process_tool_call(tool_name, tool_input)
print(f"\nTool Result:")
print(json.dumps(tool_result, indent=2))
#Add our tool_result message:
tool_response = {
"role": "user",
"content": [
{
"toolResult": {
"toolUseId": tool_use['toolUseId'],
"content": [
{
"text": json.dumps(tool_result)
}
]
}
}
]
}
messages.append(tool_response)
else:
#If Claude does NOT want to use a tool, just print out the text reponse
print("\nTechNova Support:" + f"{response['output']['message']['content'][0]['text']}")
# Start the chat!!
simple_chat()[0;31m---------------------------------------------------------------------------[0m
[0;31mValidationException[0m Traceback (most recent call last)
Cell [0;32mIn[22], line 135[0m
[1;32m 132[0m [38;5;28mprint[39m([38;5;124m"[39m[38;5;130;01m\n[39;00m[38;5;124mTechNova Support:[39m[38;5;124m"[39m [38;5;241m+[39m [38;5;124mf[39m[38;5;124m"[39m[38;5;132;01m{[39;00mresponse[[38;5;124m'[39m[38;5;124moutput[39m[38;5;124m'[39m][[38;5;124m'[39m[38;5;124mmessage[39m[38;5;124m'[39m][[38;5;124m'[39m[38;5;124mcontent[39m[38;5;124m'[39m][[38;5;241m0[39m][[38;5;124m'[39m[38;5;124mtext[39m[38;5;124m'[39m][38;5;132;01m}[39;00m[38;5;124m"[39m)
[1;32m 134[0m [38;5;66;03m# Start the chat!![39;00m
[0;32m--> 135[0m [43msimple_chat[49m[43m([49m[43m)[49m
Cell [0;32mIn[22], line 87[0m, in [0;36msimple_chat[0;34m()[0m
[1;32m 84[0m messages[38;5;241m.[39mappend({[38;5;124m"[39m[38;5;124mrole[39m[38;5;124m"[39m: [38;5;124m"[39m[38;5;124muser[39m[38;5;124m"[39m, [38;5;124m"[39m[38;5;124mcontent[39m[38;5;124m"[39m: [{[38;5;124m"[39m[38;5;124mtext[39m[38;5;124m"[39m: user_message}]})
[1;32m 86[0m [38;5;66;03m#Send a request to Claude[39;00m
[0;32m---> 87[0m response [38;5;241m=[39m [43mbedrock_client[49m[38;5;241;43m.[39;49m[43mconverse[49m[43m([49m
[1;32m 88[0m [43m [49m[43mmodelId[49m[38;5;241;43m=[39;49m[43mmodel_id[49m[43m,[49m
[1;32m 89[0m [43m [49m[43mmessages[49m[38;5;241;43m=[39;49m[43mmessages[49m[43m,[49m
[1;32m 90[0m [43m [49m[43mtoolConfig[49m[38;5;241;43m=[39;49m[43m{[49m[38;5;124;43m"[39;49m[38;5;124;43mtools[39;49m[38;5;124;43m"[39;49m[43m:[49m[43m [49m[43mtools[49m[43m}[49m[43m,[49m
[1;32m 91[0m [43m[49m[43m)[49m
[1;32m 92[0m [38;5;66;03m# Update messages to include Claude's response[39;00m
[1;32m 93[0m messages[38;5;241m.[39mappend(
[1;32m 94[0m response[[38;5;124m"[39m[38;5;124moutput[39m[38;5;124m"[39m][[38;5;124m"[39m[38;5;124mmessage[39m[38;5;124m"[39m]
[1;32m 95[0m )
File [0;32m/opt/homebrew/Caskroom/miniforge/base/envs/py311/lib/python3.11/site-packages/botocore/client.py:569[0m, in [0;36mClientCreator._create_api_method.<locals>._api_call[0;34m(self, *args, **kwargs)[0m
[1;32m 565[0m [38;5;28;01mraise[39;00m [38;5;167;01mTypeError[39;00m(
[1;32m 566[0m [38;5;124mf[39m[38;5;124m"[39m[38;5;132;01m{[39;00mpy_operation_name[38;5;132;01m}[39;00m[38;5;124m() only accepts keyword arguments.[39m[38;5;124m"[39m
[1;32m 567[0m )
[1;32m 568[0m [38;5;66;03m# The "self" in this scope is referring to the BaseClient.[39;00m
[0;32m--> 569[0m [38;5;28;01mreturn[39;00m [38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43m_make_api_call[49m[43m([49m[43moperation_name[49m[43m,[49m[43m [49m[43mkwargs[49m[43m)[49m
File [0;32m/opt/homebrew/Caskroom/miniforge/base/envs/py311/lib/python3.11/site-packages/botocore/client.py:1023[0m, in [0;36mBaseClient._make_api_call[0;34m(self, operation_name, api_params)[0m
[1;32m 1019[0m error_code [38;5;241m=[39m error_info[38;5;241m.[39mget([38;5;124m"[39m[38;5;124mQueryErrorCode[39m[38;5;124m"[39m) [38;5;129;01mor[39;00m error_info[38;5;241m.[39mget(
[1;32m 1020[0m [38;5;124m"[39m[38;5;124mCode[39m[38;5;124m"[39m
[1;32m 1021[0m )
[1;32m 1022[0m error_class [38;5;241m=[39m [38;5;28mself[39m[38;5;241m.[39mexceptions[38;5;241m.[39mfrom_code(error_code)
[0;32m-> 1023[0m [38;5;28;01mraise[39;00m error_class(parsed_response, operation_name)
[1;32m 1024[0m [38;5;28;01melse[39;00m:
[1;32m 1025[0m [38;5;28;01mreturn[39;00m parsed_response
[0;31mValidationException[0m: An error occurred (ValidationException) when calling the Converse operation: The text field in the ContentBlock object at messages.0.content.0 is blank. Add text to the text field, and try again.In [ ]:
system_prompt = """
You are a customer support chat bot for an online retailer called TechNova.
Your job is to help users look up their account, orders, and cancel orders.
Be helpful and brief in your responses.
"""In [ ]:
system_prompt = """
You are a customer support chat bot for an online retailer called TechNova.
Your job is to help users look up their account, orders, and cancel orders.
Be helpful and brief in your responses.
You have access to a set of tools, but only use them when needed.
If you do not have enough information to use a tool correctly, ask a user follow up questions to get the required inputs.
Do not call any of the tools unless you have the required data from a user.
"""






