Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:666ghj BettaFish TopicExtractor extract keywords

From Leeroopedia
Knowledge Sources
Domains NLP, LLM_Prompting, Topic_Extraction
Last Updated 2026-10-08 00:00 GMT

Overview

Concrete class that uses an LLM to extract trending keywords and generate a news summary from a list of collected news items for the MindSpider crawler.

Description

The TopicExtractor class takes a list of collected news items and calls an LLM (default: DeepSeek) to extract keywords suitable for social media crawling and generate an analytical summary. The LLM is prompted to produce keywords that match social media search patterns (not academic terms) and a Chinese-language summary of the day's hot topics. If the LLM fails, it falls back to simple keyword extraction from news titles.

Usage

Import this class when you need to extract crawl keywords from collected news. It runs after NewsCollector in the MindSpider BroadTopicExtraction workflow.

Code Reference

Source Location

  • Repository: BettaFish
  • File: `MindSpider/BroadTopicExtraction/topic_extractor.py:L25-289`

Signature

class TopicExtractor:
    def __init__(self):
        """Initialize with OpenAI client using MINDSPIDER_* settings."""

    def extract_keywords_and_summary(
        self,
        news_list: List[Dict],
        max_keywords: int = 100
    ) -> Tuple[List[str], str]:
        """
        Extract keywords and generate summary from news list.

        Args:
            news_list: List of news item dicts
            max_keywords: Maximum keywords to extract

        Returns:
            Tuple of (keywords: List[str], summary: str)
        """

Import

from MindSpider.BroadTopicExtraction.topic_extractor import TopicExtractor

I/O Contract

Inputs

Name Type Required Description
news_list List[Dict] Yes Collected news items
max_keywords int No Max keywords (default: 100)

Outputs

Name Type Description
keywords List[str] Keywords for social media crawling
summary str News analysis summary

Usage Examples

Extract Topics from News

from MindSpider.BroadTopicExtraction.topic_extractor import TopicExtractor

extractor = TopicExtractor()
keywords, summary = extractor.extract_keywords_and_summary(
    news_list=collected_news,
    max_keywords=50
)
print(f"Extracted {len(keywords)} keywords: {keywords[:10]}")
print(f"Summary: {summary[:200]}...")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment