| 408 | |
| 409 | |
| 410 | class OrderChapters(Node): |
| 411 | def prep(self, shared): |
| 412 | abstractions = shared["abstractions"] # Name/description might be translated |
| 413 | relationships = shared["relationships"] # Summary/label might be translated |
| 414 | project_name = shared["project_name"] # Get project name |
| 415 | language = shared.get("language", "english") # Get language |
| 416 | use_cache = shared.get("use_cache", True) # Get use_cache flag, default to True |
| 417 | |
| 418 | # Prepare context for the LLM |
| 419 | abstraction_info_for_prompt = [] |
| 420 | for i, a in enumerate(abstractions): |
| 421 | abstraction_info_for_prompt.append( |
| 422 | f"- {i} # {a['name']}" |
| 423 | ) # Use potentially translated name |
| 424 | abstraction_listing = "\n".join(abstraction_info_for_prompt) |
| 425 | |
| 426 | # Use potentially translated summary and labels |
| 427 | summary_note = "" |
| 428 | if language.lower() != "english": |
| 429 | summary_note = ( |
| 430 | f" (Note: Project Summary might be in {language.capitalize()})" |
| 431 | ) |
| 432 | |
| 433 | context = f"Project Summary{summary_note}:\n{relationships['summary']}\n\n" |
| 434 | context += "Relationships (Indices refer to abstractions above):\n" |
| 435 | for rel in relationships["details"]: |
| 436 | from_name = abstractions[rel["from"]]["name"] |
| 437 | to_name = abstractions[rel["to"]]["name"] |
| 438 | # Use potentially translated 'label' |
| 439 | context += f"- From {rel['from']} ({from_name}) to {rel['to']} ({to_name}): {rel['label']}\n" # Label might be translated |
| 440 | |
| 441 | list_lang_note = "" |
| 442 | if language.lower() != "english": |
| 443 | list_lang_note = f" (Names might be in {language.capitalize()})" |
| 444 | |
| 445 | return ( |
| 446 | abstraction_listing, |
| 447 | context, |
| 448 | len(abstractions), |
| 449 | project_name, |
| 450 | list_lang_note, |
| 451 | use_cache, |
| 452 | ) # Return use_cache |
| 453 | |
| 454 | def exec(self, prep_res): |
| 455 | ( |
| 456 | abstraction_listing, |
| 457 | context, |
| 458 | num_abstractions, |
| 459 | project_name, |
| 460 | list_lang_note, |
| 461 | use_cache, |
| 462 | ) = prep_res # Unpack use_cache |
| 463 | print("Determining chapter order using LLM...") |
| 464 | # No language variation needed here in prompt instructions, just ordering based on structure |
| 465 | # The input names might be translated, hence the note. |
| 466 | prompt = f""" |
| 467 | Given the following project abstractions and their relationships for the project ```` {project_name} ````: |
no outgoing calls
no test coverage detected