Skip to content

Commit ad9573a

Browse files
authored
Add language parameter for multi-language support
1 parent 449bf18 commit ad9573a

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

nodes.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import yaml
33
from pocketflow import Node, BatchNode
44
from utils.crawl_github_files import crawl_github_files
5-
from utils.call_llm import call_llm
5+
from utils.call_llm import call_llm
66
from utils.crawl_local_files import crawl_local_files
77

88
# Helper to get content for specific file indices
@@ -19,7 +19,7 @@ def prep(self, shared):
1919
repo_url = shared.get("repo_url")
2020
local_dir = shared.get("local_dir")
2121
project_name = shared.get("project_name")
22-
22+
2323
if not project_name:
2424
# Basic name derivation from URL or directory
2525
if repo_url:
@@ -63,7 +63,7 @@ def exec(self, prep_res):
6363
max_file_size=prep_res["max_file_size"],
6464
use_relative_paths=prep_res["use_relative_paths"]
6565
)
66-
66+
6767
# Convert dict to list of tuples: [(path, content), ...]
6868
files_list = list(result.get("files", {}).items())
6969
print(f"Fetched {len(files_list)} files.")
@@ -76,7 +76,7 @@ class IdentifyAbstractions(Node):
7676
def prep(self, shared):
7777
files_data = shared["files"]
7878
project_name = shared["project_name"] # Get project name
79-
79+
8080
# Helper to create context from files, respecting limits (basic example)
8181
def create_llm_context(files_data):
8282
context = ""
@@ -117,7 +117,7 @@ def exec(self, prep_res):
117117
118118
```yaml
119119
- name: Query Processing
120-
description: |
120+
description: |
121121
Explains what the abstraction does.
122122
It's like a central dispatcher routing requests.
123123
file_indices:
@@ -286,7 +286,7 @@ def exec(self, prep_res):
286286
validated_relationships.append({
287287
"from": from_idx,
288288
"to": to_idx,
289-
"label": rel["label"]
289+
"label": rel["label"]
290290
})
291291
except (ValueError, TypeError):
292292
raise ValueError(f"Could not parse indices from relationship: {rel}")
@@ -416,7 +416,7 @@ def prep(self, shared):
416416
all_chapters.append(f"{chapter_num}. [{chapter_name}]({filename})")
417417
# Store mapping of chapter index to filename for linking
418418
chapter_filenames[abstraction_index] = {"num": chapter_num, "name": chapter_name, "filename": filename}
419-
419+
420420
# Create a formatted string with all chapters
421421
full_chapter_listing = "\n".join(all_chapters)
422422

@@ -428,19 +428,22 @@ def prep(self, shared):
428428
related_file_indices = abstraction_details.get("files", [])
429429
# Get content using helper, passing indices
430430
related_files_content_map = get_content_for_indices(files_data, related_file_indices)
431-
431+
432432
# Get previous chapter info for transitions
433433
prev_chapter = None
434434
if i > 0:
435435
prev_idx = chapter_order[i-1]
436436
prev_chapter = chapter_filenames[prev_idx]
437-
437+
438438
# Get next chapter info for transitions
439439
next_chapter = None
440440
if i < len(chapter_order) - 1:
441441
next_idx = chapter_order[i+1]
442442
next_chapter = chapter_filenames[next_idx]
443443

444+
# Get language from shared store, default to English
445+
language = shared.get("language", "english")
446+
444447
items_to_process.append({
445448
"chapter_num": i + 1,
446449
"abstraction_index": abstraction_index,
@@ -451,6 +454,7 @@ def prep(self, shared):
451454
"chapter_filenames": chapter_filenames, # Add chapter filenames mapping
452455
"prev_chapter": prev_chapter, # Add previous chapter info
453456
"next_chapter": next_chapter, # Add next chapter info
457+
"language": language, # Add language for multi-language support
454458
# previous_chapters_summary will be added dynamically in exec
455459
})
456460
else:
@@ -476,8 +480,16 @@ def exec(self, item):
476480
# Use the temporary instance variable
477481
previous_chapters_summary = "\n---\n".join(self.chapters_written_so_far)
478482

483+
# Get language from item, default to English
484+
language = item.get("language", "english")
485+
486+
# Add language instruction if not English
487+
language_instruction = ""
488+
if language.lower() != "english":
489+
language_instruction = f"Write this tutorial chapter in {language}. Ensure all explanations, examples, and comments are in {language}.\n\n"
479490

480491
prompt = f"""
492+
{language_instruction}
481493
Write a very beginner-friendly tutorial chapter (in Markdown format) for the project `{project_name}` about the concept: "{abstraction_name}". This is Chapter {chapter_num}.
482494
483495
Concept Details:
@@ -502,11 +514,11 @@ def exec(self, item):
502514
503515
- If the abstraction is complex, break it down into key concepts. Explain each concept one-by-one in a very beginner-friendly way.
504516
505-
- Explain how to use this abstraction to solve the use case. Give example inputs and outputs for code snippets (if the output isn't values, describe at a high level what will happen).
517+
- Explain how to use this abstraction to solve the use case. Give example inputs and outputs for code snippets (if the output isn't values, describe at a high level what will happen).
506518
507519
- Each code block should be BELOW 20 lines! If longer code blocks are needed, break them down into smaller pieces and walk through them one-by-one. Aggresively simplify the code to make it minimal. Use comments to skip non-important implementation details. Each code block should have a beginner friendly explanation right after it.
508520
509-
- Describe the internal implementation to help understand what's under the hood. First provide a non-code or code-light walkthrough on what happens step-by-step when the abstraction is called. It's recommended to use a simple sequenceDiagram with a dummy example - keep it minimal with at most 5 participants to ensure clarity. If participant name has space, use:
521+
- Describe the internal implementation to help understand what's under the hood. First provide a non-code or code-light walkthrough on what happens step-by-step when the abstraction is called. It's recommended to use a simple sequenceDiagram with a dummy example - keep it minimal with at most 5 participants to ensure clarity. If participant name has space, use:
510522
`participant QP as Query Processing`
511523
512524
- Then dive deeper into code for the internal implementation with references to files. Provide example code blocks, but make them similarly simple and beginner-friendly.
@@ -610,13 +622,13 @@ def prep(self, shared):
610622
# Use chapter number (i+1) for ordering filename
611623
filename = f"{i+1:02d}_{safe_name}.md"
612624
index_content += f"{i+1}. [{abstraction_name}]({filename})\n"
613-
625+
614626
# Add attribution to chapter content
615627
chapter_content = chapters_content[i]
616628
if not chapter_content.endswith("\n\n"):
617629
chapter_content += "\n\n"
618630
chapter_content += "---\n\nGenerated by [AI Codebase Knowledge Builder](https://github.com/The-Pocket/Tutorial-Codebase-Knowledge)"
619-
631+
620632
# Store filename and corresponding content
621633
chapter_files.append({"filename": filename, "content": chapter_content})
622634
else:
@@ -658,4 +670,4 @@ def exec(self, prep_res):
658670

659671
def post(self, shared, prep_res, exec_res):
660672
shared["final_output_dir"] = exec_res # Store the output path
661-
print(f"\nTutorial generation complete! Files are in: {exec_res}")
673+
print(f"\nTutorial generation complete! Files are in: {exec_res}")

0 commit comments

Comments
 (0)