Skip to content

Commit 965a2ac

Browse files
authored
Merge pull request #252 from teng-lin/fix/mind-map-language-instructions
feat(artifacts): add language and instructions to generate_mind_map
2 parents 3f864c8 + afb13c1 commit 965a2ac

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

src/notebooklm/_artifacts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ async def generate_mind_map(
988988
self,
989989
notebook_id: str,
990990
source_ids: builtins.list[str] | None = None,
991+
language: str = "en",
992+
instructions: str | None = None,
991993
) -> dict[str, Any]:
992994
"""Generate an interactive mind map.
993995
@@ -997,6 +999,8 @@ async def generate_mind_map(
997999
Args:
9981000
notebook_id: The notebook ID.
9991001
source_ids: Source IDs to include. If None, uses all sources.
1002+
language: Language code (default: "en").
1003+
instructions: Custom instructions for the mind map.
10001004
10011005
Returns:
10021006
Dictionary with 'mind_map' (JSON data) and 'note_id'.
@@ -1014,7 +1018,7 @@ async def generate_mind_map(
10141018
None,
10151019
None,
10161020
None,
1017-
["interactive_mindmap", [["[CONTEXT]", ""]], ""],
1021+
["interactive_mindmap", [["[CONTEXT]", instructions or ""]], language],
10181022
None,
10191023
[2, None, [1]],
10201024
]

src/notebooklm/cli/generate.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,13 @@ async def _generate():
995995
help="Notebook ID (uses current if not set)",
996996
)
997997
@click.option("--source", "-s", "source_ids", multiple=True, help="Limit to specific source IDs")
998+
@click.option("--language", default=None, help="Output language (default: from config or 'en')")
999+
@click.option("--instructions", default=None, help="Custom instructions for the mind map")
9981000
@json_option
9991001
@with_client
1000-
def generate_mind_map(ctx, notebook_id, source_ids, json_output, client_auth):
1002+
def generate_mind_map(
1003+
ctx, notebook_id, source_ids, language, instructions, json_output, client_auth
1004+
):
10011005
"""Generate mind map.
10021006
10031007
\b
@@ -1010,16 +1014,19 @@ async def _run():
10101014
nb_id_resolved = await resolve_notebook_id(client, nb_id)
10111015
sources = await resolve_source_ids(client, nb_id_resolved, source_ids)
10121016

1013-
# Show status spinner only for console output
1014-
if json_output:
1015-
result = await client.artifacts.generate_mind_map(
1016-
nb_id_resolved, source_ids=sources
1017+
async def _generate():
1018+
return await client.artifacts.generate_mind_map(
1019+
nb_id_resolved,
1020+
source_ids=sources,
1021+
language=resolve_language(language),
1022+
instructions=instructions,
10171023
)
1024+
1025+
if json_output:
1026+
result = await _generate()
10181027
else:
10191028
with console.status("Generating mind map..."):
1020-
result = await client.artifacts.generate_mind_map(
1021-
nb_id_resolved, source_ids=sources
1022-
)
1029+
result = await _generate()
10231030

10241031
_output_mind_map_result(result, json_output)
10251032

tests/unit/test_source_selection.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,31 @@ async def test_generate_mind_map_source_encoding(self, mock_core, mock_notes_api
509509

510510
assert source_ids_nested == [[["src_mm_1"]], [["src_mm_2"]]]
511511

512+
@pytest.mark.asyncio
513+
async def test_generate_mind_map_passes_language_and_instructions(
514+
self, mock_core, mock_notes_api
515+
):
516+
"""Test generate_mind_map passes language and instructions to RPC payload."""
517+
api = ArtifactsAPI(mock_core, mock_notes_api)
518+
519+
mock_core.get_source_ids.return_value = ["src_1"]
520+
mock_core.rpc_call.return_value = [['{"name": "Mind Map", "children": []}']]
521+
522+
await api.generate_mind_map(
523+
notebook_id="nb_123",
524+
source_ids=["src_1"],
525+
language="ja",
526+
instructions="Focus on key themes",
527+
)
528+
529+
call_args = mock_core.rpc_call.call_args
530+
params = call_args.args[1]
531+
532+
# params[5] should contain the mind map config with language and instructions
533+
mind_map_config = params[5]
534+
assert mind_map_config[1][0][1] == "Focus on key themes"
535+
assert mind_map_config[2] == "ja"
536+
512537
@pytest.mark.asyncio
513538
async def test_suggest_reports_uses_get_suggested_reports(self, mock_core, mock_notes_api):
514539
"""Test suggest_reports uses GET_SUGGESTED_REPORTS RPC."""

0 commit comments

Comments
 (0)