Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions how-to-write-claude-md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Demo Bedrock Script for CLAUDE.md How To Article
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually have a bit of minimal text here to give context to learners who download the folder, e.g.:

Suggested change
# Demo Bedrock Script for CLAUDE.md How To Article
# Demo Bedrock Script for CLAUDE.md How To Article
This folder contains sample code for the Real Python tutorial on [How to Write a CLAUDE.md File for Claude Code](https://realpython.com/python-claude-md/).
It's a single script, [bedrock_example.py](./bedrock_example.py), that you can use to follow-along the tutorial examples in your local Claude Code session.

47 changes: 47 additions & 0 deletions how-to-write-claude-md/bedrock_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Demonstrate the utility of CLAUDE.md
"""

import boto3
Comment on lines +4 to +5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a inline metadata block to make it easy to use for people working with uv:

Suggested change
import boto3
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "boto3==1.43.15",
# ]
# ///
import boto3

Should probably add a requirements.txt file as well.

from botocore.config import Config

config = Config(
connect_timeout=15,
read_timeout=3600,
retries={"max_attempts": 4},
)

bedrock_client = boto3.client("bedrock-runtime", config=config)

MODEL_ID = "amazon.nova-premier-v1:0"
MAX_TOKENS = 100
TEMPERATURE = 0.1

SYSTEM_PROMPT = """You are a helpful, harmless assistant.
Your task is to assist customers with any questions they may have.
"""


def query_llm(prompt: str) -> str:
system = [
{"text": SYSTEM_PROMPT},
]

messages = [{"role": "user", "content": [{"text": prompt}]}]
inf_params = {"maxTokens": MAX_TOKENS, "temperature": TEMPERATURE}

response = bedrock_client.converse(
modelId=MODEL_ID,
system=system,
messages=messages,
inferenceConfig=inf_params,
)

response_text = response["output"]["message"]["content"][0]["text"]
return response_text


if __name__ == "__main__":
query = input("Ask a question!\n>")
response = query_llm(query)
print(response)
Loading