-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_use_print_utils.py
85 lines (69 loc) · 2.28 KB
/
tool_use_print_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
def header():
"""
Logs the welcome message and usage guide for the tool use demo.
"""
print("\033[0m")
separator("=")
print("Welcome to the Amazon Bedrock Tool Use demo!")
separator("=")
print(
"This assistant provides multi-tool use capability."
)
print(
"You can talk to the bot to invoke tools."
)
print("")
print("Example queries:")
print("- What's the weather like in New York?")
print("- Is it warmer in Rome or Barcelona today?")
print("")
print("To exit the program, simply type 'x' and press Enter.")
print("")
print("Have fun and experiment with the app!")
def footer():
"""
Logs the footer information for the tool use demo.
"""
print("\033[0m")
separator("=")
print("Thank you for using Skerava's Bedrock Demo!The new feature will be added soon.")
print("learned something new, or got some inspiration for your own apps today!")
print("")
print(
"For more Bedrock examples in different programming languages, have a look at:"
)
print(
"https://docs.aws.amazon.com/bedrock/latest/userguide/service_code_examples.html"
)
separator("=")
def call_to_bedrock(conversation):
"""
Logs information about the call to Amazon Bedrock.
:param conversation: The conversation history.
"""
if "toolResult" in conversation[-1]["content"][0]:
print("\033[0;90mReturning the tool response(s) to the model...\033[0m")
else:
print("\033[0;90mSending the query to the model...\033[0m")
def tool_use(tool_name, input_data):
"""
Logs information about the tool use.
:param tool_name: The name of the tool being used.
:param input_data: The input data for the tool.
"""
print(f"\033[0;90mExecuting tool: {tool_name} with input: {input_data}...\033[0m")
def model_response(message):
"""
Logs the model's response.
:param message: The model's response message.
"""
print("\033[0;90mThe model's response:\033[0m")
print(message)
def separator(char="-"):
"""
Logs a separator line.
:param char: The character to use for the separator line.
"""
print(char * 80)