4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

最速(?)最短(?) 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?