文本摘要
想把一首诗快速变成精炼摘要吗?我们来试试!您已有整首诗的文本,保存在名为 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}")