テキストの要約
詩を短い要約に変換してみましょう。raven_text という文字列変数に詩の全文が格納されています。この変数をチャット AI モデルに渡して、指定した語数で詩を要約するように依頼します。
この演習はコースの一部です
Databricks と Python SDK
演習の手順
- エドガー・アラン・ポーの詩「大鴉(The Raven)」を要約するよう AI エージェントに指示します。
- モデル名として Meta Llama 3 を指定します。すでに
ai_modelとして保存されています。 raven_text変数を含めて、AI モデルに送信するメッセージを作成します。- AI モデルへのクエリに使用するチャットメッセージのロールを指定します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
w = WorkspaceClient()
ai_model = "databricks-meta-llama-3-3-70b-instruct"
# Summarize the poem
response = w.serving_endpoints.query(
# Set model name
name=____,
messages=[
# Create a chat message to send to the model
____(
# Specify the role for sending the query
role=ChatMessageRole.____, content=f"Summarize this poem by Edgar Allan Poe: {____} in 3 bullet points"
),
],
max_tokens=200)
print(f"RESPONSE:\n{response.choices[0].message.content}")