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
5 changes: 5 additions & 0 deletions how-to-write-claude-md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Demo Bedrock Script for How to Write a CLAUDE.md File for Claude Code Tutorial

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.
50 changes: 50 additions & 0 deletions how-to-write-claude-md/bedrock_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "boto3==1.43.15",
# ]
# ///

import boto3
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)
1 change: 1 addition & 0 deletions how-to-write-claude-md/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3==1.43.15
Loading