Skip to content

Comments

Feat/thread summarizer#18

Merged
skkuwari-alt merged 16 commits intomainfrom
feat/thread-summarizer
Oct 10, 2025
Merged

Feat/thread summarizer#18
skkuwari-alt merged 16 commits intomainfrom
feat/thread-summarizer

Conversation

@skkuwari-alt
Copy link

@skkuwari-alt skkuwari-alt commented Oct 10, 2025

Screenshot 2025-10-10 at 3 56 38 PM

Solves Issue: #19

Summary
This PR introduces a fully functional Thread Summarizer plugin for NodeBB.

It provides an /api/thread-summarizer/v2/:tid REST route that generates concise summaries of forum topics using the OpenAI API.


Features Implemented

  • Adds new API route: /api/thread-summarizer/v2/:tid

  • Integrates OpenAI API (gpt-4o-mini) for summarization

  • Includes environment variable controls:

    • OPENAI_API_KEY – required for real summaries
      Each user must set their own OpenAI API key in the environment before running the server.
    • TS_STUB=1 – enables offline testing (returns fake summaries)
  • Adds an LRU cache (10-minute expiry) to avoid redundant API calls

  • Implements a per-user cooldown (30 seconds) to prevent spam

  • Handles permission checks via privileges.topics.can

  • Returns clean JSON responses for both cached and fresh summaries

  • Uses posts.getPostsByPids to gather thread content


How It Works

  1. The topic page includes a “Summarize this topic” button.
  2. The server collects up to 40 posts and constructs a summarization prompt.
  3. The OpenAI API generates 5–8 bullet points and a one-line TL;DR.
  4. The summary is cached and returned as JSON.

Testing

A. Stub Mode (no API key required)

export TS_STUB=1
curl -sS "http://localhost:4570/api/thread-summarizer/v2/1" | jq

B. Real Mode (requires OpenAI API key)

export OPENAI_API_KEY="your-api-key"
unset TS_STUB
curl -sS "http://localhost:4570/api/thread-summarizer/v2/1" | jq

Notes

  • Users must provide their own OPENAI_API_KEY to generate real summaries.
  • Without the key, the plugin runs safely in stub mode for testing.
  • Caching and cooldowns ensure consistent performance and prevent repeated API usage.

@skkuwari-alt
Copy link
Author

(I was committing to the class repo by accident, and I closed a PR there)

@skkuwari-alt skkuwari-alt merged commit 7e22397 into main Oct 10, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant