Skip to content

feat: support language and instructions for mind maps#263

Open
voidborne-d wants to merge 6 commits intoteng-lin:mainfrom
voidborne-d:feat/mind-map-language-instructions
Open

feat: support language and instructions for mind maps#263
voidborne-d wants to merge 6 commits intoteng-lin:mainfrom
voidborne-d:feat/mind-map-language-instructions

Conversation

@voidborne-d
Copy link
Copy Markdown
Contributor

@voidborne-d voidborne-d commented Apr 9, 2026

Summary

  • add language and instructions support to generate_mind_map() and encode both into the RPC payload
  • expose --language and --instructions on notebooklm generate mind-map
  • add unit coverage for both API payload encoding and CLI forwarding

Testing

Summary by CodeRabbit

  • New Features

    • Mind map generation accepts a configurable language (default: English) and optional instructions via the Python API and CLI (--language, --instructions).
  • Documentation

    • README and RPC reference updated to show language/instructions usage; README example now passes the returned artifact_id when downloading.
  • Tests

    • Added/updated unit tests verifying language and instructions are forwarded end-to-end.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added optional language and instructions parameters for mind-map generation across docs, CLI, API, and tests; those values are forwarded into the RPC payload instead of hardcoded empty values.

Changes

Cohort / File(s) Summary
Documentation
README.md, docs/rpc-reference.md
Updated examples and RPC reference to show language and instructions being supplied for mind-map generation.
API Implementation
src/notebooklm/_artifacts.py
ArtifactsAPI.generate_mind_map signature now accepts language: str = "en" and `instructions: str
CLI
src/notebooklm/cli/generate.py
mind-map CLI command adds --language and --instructions; callback signature updated and generate_kwargs (including resolved language and instructions) forwarded to client.artifacts.generate_mind_map.
Tests
tests/unit/cli/test_generate.py, tests/unit/test_source_selection.py
Updated CLI unit test to assert language/instructions are forwarded; added tests verifying RPC params embed interactive_mindmap with context and language per inputs.

Sequence Diagram

sequenceDiagram
    participant User as User/CLI
    participant CLI as CLI Handler
    participant API as ArtifactsAPI
    participant RPC as RPC Layer

    User->>CLI: invoke generate mind-map (--language, --instructions)
    CLI->>CLI: resolve_language() -> language
    CLI->>CLI: build generate_kwargs {source_ids, language, instructions}
    CLI->>API: generate_mind_map(notebook_id, **generate_kwargs)
    API->>RPC: GENERATE_MIND_MAP(..., ["interactive_mindmap", [["[CONTEXT]", instructions or ""]], language])
    RPC-->>API: returns mind map result
    API-->>CLI: returns result dict
    CLI->>User: outputs result (JSON or stdout)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble flags and whisper "ja" with cheer,
I tuck instructions where the RPCs hear,
From CLI hop to API's bright seam,
The mind map wakes from a tiny dream,
Hooray — now maps can think and speak so clear!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding language and instructions support to mind map generation, which is the primary objective of the PR.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #250: adds language and instructions parameters to generate_mind_map() [#250], exposes --language and --instructions CLI flags [#250], includes them in the RPC payload correctly [#250], and adds comprehensive unit test coverage [#250].
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing language and instructions support for mind maps across the API, CLI, documentation, and tests as specified in issue #250. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/test_source_selection.py (1)

512-534: Consider adding a fallback-case assertion for instructions=None.

This test is strong for explicit values; adding one more case for default instructions=None → context "" would lock in the backward-compatible payload behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_source_selection.py` around lines 512 - 534, Add a case in
test_generate_mind_map_language_and_instructions_encoding to exercise
ArtifactsAPI.generate_mind_map with instructions=None and assert the RPC payload
uses an empty context string; specifically call generate_mind_map with
instructions=None (or omit the instructions arg), capture
mock_core.rpc_call.call_args.args[1] and assert params[5] equals
["interactive_mindmap", [["[CONTEXT]", ""]], "ja"] (referencing
mock_core.rpc_call and params[5] to locate the assertion).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/cli/test_generate.py`:
- Around line 434-437: Patch the test to stub get_language so
resolve_language(None) doesn't read local config: in the test, before invoking
the code that calls mock_client.artifacts.generate_mind_map, monkeypatch (or
unittest.mock.patch) the get_language function used by the CLI to a small stub
that returns "en" when called with None (and delegates for other inputs if
needed); this forces the deterministic default-path so the later assertions on
kwargs["language"] == "en" and kwargs["instructions"] is None are stable. Ensure
you patch the same get_language symbol the CLI code imports (the one that
resolve_language uses) and unpatch/let the fixture cleanup handle restoration.

---

Nitpick comments:
In `@tests/unit/test_source_selection.py`:
- Around line 512-534: Add a case in
test_generate_mind_map_language_and_instructions_encoding to exercise
ArtifactsAPI.generate_mind_map with instructions=None and assert the RPC payload
uses an empty context string; specifically call generate_mind_map with
instructions=None (or omit the instructions arg), capture
mock_core.rpc_call.call_args.args[1] and assert params[5] equals
["interactive_mindmap", [["[CONTEXT]", ""]], "ja"] (referencing
mock_core.rpc_call and params[5] to locate the assertion).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c638f80e-c9c9-4fb7-958a-73c3b52fc6dc

📥 Commits

Reviewing files that changed from the base of the PR and between a997718 and b618790.

📒 Files selected for processing (6)
  • README.md
  • docs/rpc-reference.md
  • src/notebooklm/_artifacts.py
  • src/notebooklm/cli/generate.py
  • tests/unit/cli/test_generate.py
  • tests/unit/test_source_selection.py

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for specifying a language and custom instructions when generating mind maps. These changes span the core API, the CLI, documentation, and unit tests. The feedback suggests improving the README example by using the returned note_id to ensure the correct mind map is downloaded, making the demonstration more robust.

README.md Outdated
Comment on lines 198 to 203
result = await client.artifacts.generate_mind_map(
nb.id,
language="ja",
instructions="Focus on chronology and causal links",
)
await client.artifacts.download_mind_map(nb.id, "mindmap.json")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the example more robust and better demonstrate the API, consider using the note_id from the result to download the specific mind map that was just generated. Currently, download_mind_map without an artifact_id will download the first mind map it finds, which may not be the one just created if others exist.

Suggested change
result = await client.artifacts.generate_mind_map(
nb.id,
language="ja",
instructions="Focus on chronology and causal links",
)
await client.artifacts.download_mind_map(nb.id, "mindmap.json")
result = await client.artifacts.generate_mind_map(
nb.id,
language="ja",
instructions="Focus on chronology and causal links",
)
if result and result.get("note_id"):
await client.artifacts.download_mind_map(nb.id, "mindmap.json", artifact_id=result["note_id"])
else:
# Fallback for safety, though generate_mind_map should return a note_id
await client.artifacts.download_mind_map(nb.id, "mindmap.json")

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.

2 participants