Skip to content

Commit b8d4d27

Browse files
authored
Example bedrock script
1 parent cb17b1e commit b8d4d27

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Demonstrate the utility of CLAUDE.md
3+
"""
4+
5+
import boto3
6+
from botocore.config import Config
7+
8+
config = Config(
9+
connect_timeout=15,
10+
read_timeout=3600,
11+
retries={"max_attempts": 4},
12+
)
13+
14+
bedrock_client = boto3.client("bedrock-runtime", config=config)
15+
16+
MODEL_ID = "amazon.nova-premier-v1:0"
17+
MAX_TOKENS = 100
18+
TEMPERATURE = 0.1
19+
20+
SYSTEM_PROMPT = """You are a helpful, harmless assistant.
21+
Your task is to assist customers with any questions they may have.
22+
"""
23+
24+
25+
def query_llm(prompt: str) -> str:
26+
system = [
27+
{"text": SYSTEM_PROMPT},
28+
]
29+
30+
messages = [{"role": "user", "content": [{"text": prompt}]}]
31+
inf_params = {"maxTokens": MAX_TOKENS, "temperature": TEMPERATURE}
32+
33+
response = bedrock_client.converse(
34+
modelId=MODEL_ID,
35+
system=system,
36+
messages=messages,
37+
inferenceConfig=inf_params,
38+
)
39+
40+
response_text = response["output"]["message"]["content"][0]["text"]
41+
return response_text
42+
43+
44+
if __name__ == "__main__":
45+
query = input("Ask a question!\n>")
46+
response = query_llm(query)
47+
print(response)

0 commit comments

Comments
 (0)