HyperbookLM Documentation

repository·main·Indexed 19 days ago

https://github.com/hyperbrowserai/hyperbooklm

A research assistant built with Next.js 15 and Hyperbrowser that aggregates web URLs and PDFs to generate AI-powered summaries, interactive mindmaps, audio overviews via ElevenLabs, and presentation slides using Google Gemini. It features multi-source ingestion, streaming chat completions with OpenAI, and video generation capabilities via the Veo API.

Tokens
4.7K
Snippets
18
Records
21
Agent score
65%

What's inside HyperbookLM

  1. Overview of HyperbookLM features and capabilities

    main

    HyperbookLM is a research assistant that aggregates diverse sources to provide deep insights. Key capabilities include:

    • Multi-Source Ingestion: Scrape web URLs using Hyperbrowser or upload and parse PDF documents client-side.
    • Deep Research Analysis:
      • AI Research Summary: Comprehensive summaries with key insights.
      • Interactive Mindmap: Visualizes concept relationships using React Flow.
      • Audio Overview: Podcast-style audio summaries via ElevenLabs.
      • Presentation Slides: Auto-generated slide decks using Google Gemini.
    • Interactive Chat: Streaming AI responses for querying your ingested sources.
  2. Explore the HyperbookLM project structure

    main

    The project is built with Next.js 15 (App Router). Key directories include:

    • app/api/: Contains Next.js API Routes for server-side logic:
      • audio/: ElevenLabs integration
      • chat/: OpenAI Chat integration
      • gemini/slides/: Google Gemini Slides generation
      • gpt/mindmap/: OpenAI Mindmap generation
      • scrape/: Hyperbrowser Scraping
      • summary/: Research Summary generation
      • upload/: PDF/TXT File processing
    • components/: UI components including ChatInterface.tsx, MindMap.tsx, Navbar.tsx, OutputsPanel.tsx, and SourcesPanel.tsx.
    • lib/: Contains api/ (API clients) and types.ts (TypeScript interfaces).
    hyperbooklm/
    ├── app/
    │   ├── api/                # Next.js API Routes (Server-side)
    │   │   ├── audio/          # ElevenLabs integration
    │   │   ├── chat/           # OpenAI Chat integration
    │   │   ├── gemini/slides/  # Google Gemini Slides generation
    │   │   ├── gpt/mindmap/    # OpenAI Mindmap generation
    │   │   ├── scrape/         # Hyperbrowser Scraping
    │   │   ├── summary/        # Research Summary generation
    │   │   └── upload/         # PDF/TXT File processing
    │   ├── page.tsx            # Main application logic
    │   └── globals.css         # Global styles
    ├── components/
    │   ├── ChatInterface.tsx   # Chat UI
    │   ├── MindMap.tsx         # React Flow visualization
    │   ├── Navbar.tsx         # Navigation & Branding
    │   ├── OutputsPanel.tsx    # Right-side results panel
    │   └── SourcesPanel.tsx    # Left-side source management
    ├── lib/
    │   ├── api/                # API clients
    │   └── types.ts            # TypeScript interfaces
  3. Install HyperbookLM

    main

    Follow these steps to set up the HyperbookLM development environment locally:

    1. Clone the repository:

      git clone https://github.com/hyperbrowserai/hyperbooklm.git
      cd hyperbooklm
    2. Install dependencies using yarn or npm:

      yarn
      # or
      npm install
    3. Configure environment variables: Copy the example environment file to create your local configuration:

      cp .env.local.example .env.local
    4. Start the development server:

      yarn dev
    5. Access the app: Open http://localhost:3000 in your browser.

    git clone https://github.com/hyperbrowserai/hyperbooklm.git
    cd hyperbooklm
    yarn
    cp .env.local.example .env.local
    yarn dev
  4. Configure environment variables for HyperbookLM

    main

    HyperbookLM requires several API keys to function. Add the following keys to your .env.local file:

    VariableServiceRequirementPurpose
    HYPERBROWSER_API_KEYHyperbrowserRequiredWeb scraping via Hyperbrowser SDK
    OPENAI_API_KEYOpenAIRequiredChat, Research Summary, and Mindmap generation
    GEMINI_API_KEYGoogle GeminiRequiredPresentation Slides generation
    ELEVENLABS_API_KEYElevenLabsOptionalAudio Overview (podcast-style) generation
    # Hyperbrowser API Key
    HYPERBROWSER_API_KEY=your_hyperbrowser_key
    
    # OpenAI API Key
    OPENAI_API_KEY=your_openai_key
    
    # Google Gemini API Key
    GEMINI_API_KEY=your_gemini_key
    
    # ElevenLabs API Key (Optional)
    ELEVENLABS_API_KEY=your_elevenlabs_key
  5. Troubleshoot OpenAI API errors in `streamChatCompletion`

    main

    If streamChatCompletion fails, it typically throws an error or triggers the onError callback with one of the following issues:

    1. Missing API Key: If OPENAI_API_KEY is not set in your environment (e.g., .env.local), the function throws: "OpenAI API key is missing. Please set OPENAI_API_KEY in your .env.local file."
    2. API Request Failure: If the OpenAI server returns a non-OK status, the error message will contain the specific error from the OpenAI response (e.g., invalid model, rate limits, or authentication issues).
    3. Stream Reader Failure: If the response body cannot be read as a stream, it throws: "Failed to get response reader".
  6. Generate presentation slides with generateSlides()

    main

    Use the generateSlides function to trigger the generation of a SlideDeck based on a specific notebook and a set of sources. This function makes a POST request to the /api/gemini/slides endpoint.

    If the request fails, it throws an error containing the error message returned by the server, or a default message "Failed to generate slides" if no error details are provided.

    import { generateSlides } from "./lib/api/gemini";
    import { Source } from "./lib/types";
    
    const sources: Source[] = [
      // ... your source objects
    ];
    
    try {
      const slideDeck = await generateSlides("your-notebook-id", sources);
      console.log("Generated SlideDeck:", slideDeck);
    } catch (error) {
      console.error("Error generating slides:", error.message);
    }
  7. Generate a notebook overview

    main

    Use generateOverview to create a NotebookSummary for a specific notebook based on a set of provided sources. This function makes a POST request to /api/gpt/overview.

    Parameters:

    • notebookId: The unique identifier for the notebook.
    • sources: An array of Source objects to be used in the generation process.

    Returns: A Promise that resolves to a NotebookSummary object.

    Errors: Throws an error if the response is not OK, using the error message provided by the API or defaulting to "Failed to generate overview".

    import { generateOverview } from "../lib/api/gpt";
    
    const summary = await generateOverview("my-notebook-id", sourcesArray);
  8. Scrape a webpage using scrapeWebpage()

    main

    The scrapeWebpage function performs a POST request to the /api/scrape endpoint to extract structured data from a given URL. It returns an object containing the page's title, main content, plain text, and the original URL.

    If the request fails, it throws an error containing the error message returned by the server or a fallback status text.

    const data = await scrapeWebpage('https://example.com');
    // Returns: { title: string; content: string; text: string; url: string; }
  9. Generate a mindmap

    main

    Use generateMindmap to create a Mindmap structure for a specific notebook based on a set of provided sources. This function makes a POST request to /api/gpt/mindmap.

    Parameters:

    • notebookId: The unique identifier for the notebook.
    • sources: An array of Source objects to be used in the generation process.

    Returns: A Promise that resolves to a Mindmap object.

    Errors: Throws an error if the response is not OK, using the error message provided by the API or defaulting to "Failed to generate mindmap".

    import { generateMindmap } from "../lib/api/gpt";
    
    const mindmap = await generateMindmap("my-notebook-id", sourcesArray);
  10. Build a video prompt from a summary

    main

    Use buildVideoPrompt to construct a VideoPrompt object derived from an existing NotebookSummary. This is useful for preparing data for video generation workflows.

    Parameters:

    • notebookId: The unique identifier for the notebook.
    • summary: The NotebookSummary object containing the bullets to be used.
    • durationSec: The desired video duration in seconds. Accepts 30 or 60. Defaults to 30.

    Returns: A VideoPrompt object containing the notebook ID, timestamp, duration, the first 5 bullets from the summary as beats, an "informative" style, and voiceOver: false.

    import { buildVideoPrompt } from "../lib/api/gpt";
    
    const videoPrompt = buildVideoPrompt(notebookId, summary, 60);
  11. Build an audio script from a summary

    main

    Use buildAudioScript to construct an AudioScript object from a NotebookSummary. This prepares the text for text-to-speech (TTS) services.

    Parameters:

    • notebookId: The unique identifier for the notebook.
    • summary: The NotebookSummary object containing the bullets to be converted to text.
    • voiceId: The identifier for the target voice (e.g., from ElevenLabs).

    Returns: An AudioScript object. The text is generated by joining all bullets in the summary with spaces. If the resulting text exceeds 2200 characters, it is truncated to the first 2200 characters.

    import { buildAudioScript } from "../lib/api/gpt";
    
    const audioScript = buildAudioScript(notebookId, summary, "voice-id-123");
  12. Stream chat completions with `streamChatCompletion`

    main

    The streamChatCompletion function provides a streaming interface for generating AI responses based on provided source documents. It automatically constructs a system prompt that instructs the model to use the provided sources and include inline citations in the format (Source N).

    To use this function, you must provide a user message, an array of Source objects, and a StreamCallbacks object to handle the lifecycle of the stream.

    Required Environment Variables:

    • OPENAI_API_KEY: Your OpenAI API key.
    • OPENAI_SUMMARY_MODEL (Optional): The model to use for summarization. Defaults to gpt-5-nano if not set.
    import { streamChatCompletion } from './lib/api/claude';
    
    await streamChatCompletion(
      "What are the main findings in these documents?",
      [
        { title: "Doc 1", url: "https://example.com/1", content: "Content of doc 1" },
        { title: "Doc 2", url: "https://example.com/2", text: "Text of doc 2" }
      ],
      {
        onStart: () => console.log("Stream started"),
        onToken: (token) => process.stdout.write(token),
        onComplete: (fullText) => console.log("\n\nFull text received:", fullText),
        onError: (err) => console.error("Error:", err)
      }
    );