Text summarization
Want to turn a poem into a quick summary? Let’s make it happen! You have the full text of a poem stored as a string variable called raven_text, which you will hand off to a Chat AI model and ask it to summarize the poem in a set number of words.
This exercise is part of the course
Databricks with the Python SDK
Exercise instructions
- Ask the AI agent to summarize the poem "The Raven" by Edgar Allan Poe.
- Define the model name as Meta Llama 3, already saved as
ai_model. - Create the message you want to send to the AI model, including the
raven_textvariable. - Use the chat message role used to query the AI model.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
w = WorkspaceClient()
ai_model = "databricks-meta-llama-3-3-70b-instruct"
# Ask the AI agent to summarize the poem "The Raven" by Edgar Allan Poe
response = w.serving_endpoints.____(
name=____, # Define the model name as meta llama 3
messages=[ # # Create the message you want to send to the AI agent
____( # Use the chat message role used to query the AI agent
role=ChatMessageRole.____, content=f"Summarize this poem by Edgar Allan Poe: {raven_text} in 3 bullet points"
),
],
max_tokens=200)
print(f"RESPONSE:\n{response.choices[0].message.content}")