文字摘要
想把一首詩快速變成重點摘要嗎?來試試看!你已有詩作全文,存在字串變數 raven_text。你將把它傳給聊天式 AI 模型,並要求用指定的字數為這首詩產生摘要。
本練習屬於課程
使用 Python SDK 的 Databricks
練習說明
- 請要求 AI 代理總結 Edgar Allan Poe 的詩作「The Raven」。
- 模型名稱為 Meta Llama 3,已儲存為
ai_model。 - 建立要送給 AI 模型的訊息,並包含變數
raven_text。 - 使用查詢 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}")