LoginSignup
4
2

最速(?)最短(?) Amazon Bedrockの動かし方はこれだ

Posted at

boto3は1.28.57でBedrockに対応しました。

pip install -q -U boto3

bedrockbedrock-runtime があるので注意。invoke_modelはbedrock-runtime

import boto3
import json

client = boto3.client('bedrock-runtime')

prompt = '''
Human: こんにちは!
Assistant:
'''

body = {
    'prompt': prompt,
    'max_tokens_to_sample': 300,
}

response = client.invoke_model(
    modelId="anthropic.claude-v2",
    body=json.dumps(body)
)

body = response['body'].readlines()

completion = json.loads(body[0].decode('utf-8'))['completion']

print(completion)

回答

 はい、こんにちは。よろしくお願いします。
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2