Created
February 25, 2025 00:09
-
-
Save mikegc-aws/2f463b3f5c2ce570bfe7fd7c50d92df3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import boto3, json" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"client = boto3.client('bedrock-runtime', region_name='us-west-2')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"model_id = \"us.anthropic.claude-3-7-sonnet-20250219-v1:0\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"system_message = [\n", | |
"\t{\n", | |
"\t\t\"text\": \"You are a helpful assistant.\"\n", | |
"\t}\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"messages = [\n", | |
"\t{\n", | |
"\t\t'role': 'user', \n", | |
"\t\t'content': [\n", | |
"\t\t\t{\n", | |
"\t\t\t\t'text': \"Think carefully and write a poem that will make me fall in love.\"\n", | |
"\t\t\t}\n", | |
"\t\t]\n", | |
"\t}\n", | |
"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"response = client.converse(\n", | |
"\tmodelId=model_id,\n", | |
"\tmessages=messages,\n", | |
"\tsystem=system_message,\n", | |
"\tinferenceConfig={\n", | |
"\t\t\"maxTokens\": 131072,\n", | |
"\t\t\"temperature\": 1, # must be 1\n", | |
"\t\t# \"topP\": 1, # must be unset\n", | |
"\t},\n", | |
"\tadditionalModelRequestFields={\n", | |
"\t\t'thinking': {\n", | |
"\t\t\t\"type\": \"enabled\",\n", | |
"\t\t\t\"budget_tokens\": 2000\n", | |
"\t\t}\n", | |
"\t}\n", | |
")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"print(json.dumps(response, indent=4))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "base", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.12.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment