Summarization
Run the dev server and navigate to the /summarization
route:
You should see a list of comments. This list is populated with data from messages.json
, containing 20 messages from team members discussing project updates, client feedback, timelines, and preparation for an upcoming client call.
Wouldn't it be great to get a summary of all the comments so we didn't have to read through everything. Let's build this with the generateObject
function.
Create a new file called actions.ts
in the summarization
directory. This will be our server-side environment where we will interact with the model. This action will take in an array of comments.
Pass in a model and a prompt. In this case, we want the model to summarize the comments, which we will stringify and pass alongside the prompt.
Let's define a Zod schema for the information that we want the model to generate.
Import the newly created Server Action. Create a new state variable to hold the comment summary.
Update the page.tsx
with the following code:
Call the generateSummary
function and set the result to the summary
state variable.
Import the SummaryCard component and render the summary.
Head back to the browser and click generate! You should see a summary of the comments. This is great. But the format of the text isn't great. Let's use the describe function to improve the generation.
Update the actions.ts
file with the following code:
In this updated code, we are using the describe
function to provide more context to the model about the expected output. This will help the model generate more accurate summaries. We are also constraining the output to be within certain character limits to ensure that the output is concise and relevant.
Head back to the browser and click generate! You should see a more structured summary of the comments.