diff --git a/how-to-write-claude-md/README.md b/how-to-write-claude-md/README.md new file mode 100644 index 0000000000..b310fd04af --- /dev/null +++ b/how-to-write-claude-md/README.md @@ -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. diff --git a/how-to-write-claude-md/bedrock_example.py b/how-to-write-claude-md/bedrock_example.py new file mode 100644 index 0000000000..1da16a6496 --- /dev/null +++ b/how-to-write-claude-md/bedrock_example.py @@ -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) diff --git a/how-to-write-claude-md/requirements.txt b/how-to-write-claude-md/requirements.txt new file mode 100644 index 0000000000..620502e7ad --- /dev/null +++ b/how-to-write-claude-md/requirements.txt @@ -0,0 +1 @@ +boto3==1.43.15