
4
latest_response = response.content[0].text
print(latest_response)
ここでは、
response
オブジェクトから最新のアシスタントの応答を取得し、
latest_
response
変数に格納しています。そして、その内容を表示しています。
response
オブジェク
トの
content
プロパティは、応答のリストを保持しています。ここでは、リストの最初の要素
の
text
プロパティを取得しています。
このプログラムを実行すると、次のような応答が得られるはずです。
O U T
FORTRANは、IBMのチームによって開発されました
マルチモーダル
リスト 4.3.6 は、Anthropic API を使用して画像を含むマルチモーダルな質問応答を行う例
です。ここでも、図4.3.1 と同じ入力画像を用いて説明します。
リスト4.3.6
import sys
import base64
import anthropic
def explain_image(filename: str) -> str:
with open(filename, "rb") as image_file:
image_data = base64.b64encode(image_file.read()).decode("utf-8")
response = anthropic.Anthropic().messages.create( ...