The Hacker News Analyzer example uses GenSX to fetch, analyze, and extract trends from the top Hacker News posts. It shows how to combine data fetching, parallel analysis, and content generation in a single workflow to create two outputs: a detailed report and a tweet of the trends.
The Hacker News Analyzer workflow is composed of the following steps:
text
posts (FetchHNPosts
)AnalyzeHNPosts
)
SummarizePost
)AnalyzeComments
)GenerateReport
)EditReport
)WriteTweet
)# Navigate to the example directory
cd examples/hacker-news-analyzer
# Install dependencies
pnpm install
# Set your OpenAI API key
export OPENAI_API_KEY=<your_api_key>
# Run the example
pnpm run dev
The workflow will create two files:
hn_analysis_report.md
: A detailed analysis reporthn_analysis_tweet.txt
: A tweet-sized summary of the analysisThe AnalyzeHNPosts
component processes each post in parallel and does two types of analysis in parallel as well. This is achieved using Promise.all
to concurrently process multiple posts, with each post’s analysis being handled by separate components.
const AnalyzeHNPosts = gensx.Component(
"AnalyzeHNPosts",
async ({ stories }: AnalyzeHNPostsProps) => {
const analyses = await Promise.all(
stories.map(async (story) => {
const [summary, commentAnalysis] = await Promise.all([
SummarizePost({ story }),
AnalyzeComments({
postId: story.id,
comments: story.comments,
}),
]);
return { summary, commentAnalysis };
}),
);
return { analyses };
},
);
The component returns an array of analyses
that looks like this:
{
analyses: [
{ summary: "...", commentAnalysis: "..." },
{ summary: "...", commentAnalysis: "..." },
// ...
];
}
Check out the other examples in the GenSX Github Repo .