janus-llm 4.2.0__py3-none-any.whl → 4.3.5__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. janus/__init__.py +1 -1
  2. janus/__main__.py +1 -1
  3. janus/_tests/evaluator_tests/EvalReadMe.md +85 -0
  4. janus/_tests/evaluator_tests/incose_tests/incose_large_test.json +39 -0
  5. janus/_tests/evaluator_tests/incose_tests/incose_small_test.json +17 -0
  6. janus/_tests/evaluator_tests/inline_comment_tests/mumps_inline_comment_test.m +71 -0
  7. janus/_tests/test_cli.py +3 -2
  8. janus/cli/aggregate.py +135 -0
  9. janus/cli/cli.py +111 -0
  10. janus/cli/constants.py +43 -0
  11. janus/cli/database.py +289 -0
  12. janus/cli/diagram.py +178 -0
  13. janus/cli/document.py +174 -0
  14. janus/cli/embedding.py +122 -0
  15. janus/cli/llm.py +187 -0
  16. janus/cli/partition.py +125 -0
  17. janus/cli/self_eval.py +149 -0
  18. janus/cli/translate.py +183 -0
  19. janus/converter/__init__.py +1 -1
  20. janus/converter/_tests/test_translate.py +2 -0
  21. janus/converter/converter.py +129 -92
  22. janus/converter/document.py +21 -14
  23. janus/converter/evaluate.py +237 -4
  24. janus/converter/translate.py +3 -3
  25. janus/embedding/collections.py +1 -1
  26. janus/language/alc/_tests/alc.asm +3779 -0
  27. janus/language/alc/_tests/test_alc.py +1 -1
  28. janus/language/alc/alc.py +9 -4
  29. janus/language/binary/_tests/hello.bin +0 -0
  30. janus/language/block.py +47 -12
  31. janus/language/file.py +1 -1
  32. janus/language/mumps/_tests/mumps.m +235 -0
  33. janus/language/splitter.py +31 -23
  34. janus/language/treesitter/_tests/languages/fortran.f90 +416 -0
  35. janus/language/treesitter/_tests/languages/ibmhlasm.asm +16 -0
  36. janus/language/treesitter/_tests/languages/matlab.m +225 -0
  37. janus/language/treesitter/treesitter.py +9 -1
  38. janus/llm/models_info.py +26 -13
  39. janus/metrics/_tests/asm_test_file.asm +10 -0
  40. janus/metrics/_tests/mumps_test_file.m +6 -0
  41. janus/metrics/_tests/test_treesitter_metrics.py +1 -1
  42. janus/metrics/prompts/clarity.txt +8 -0
  43. janus/metrics/prompts/completeness.txt +16 -0
  44. janus/metrics/prompts/faithfulness.txt +10 -0
  45. janus/metrics/prompts/hallucination.txt +16 -0
  46. janus/metrics/prompts/quality.txt +8 -0
  47. janus/metrics/prompts/readability.txt +16 -0
  48. janus/metrics/prompts/usefulness.txt +16 -0
  49. janus/parsers/code_parser.py +4 -4
  50. janus/parsers/doc_parser.py +12 -9
  51. janus/parsers/eval_parsers/incose_parser.py +134 -0
  52. janus/parsers/eval_parsers/inline_comment_parser.py +112 -0
  53. janus/parsers/parser.py +7 -0
  54. janus/parsers/partition_parser.py +47 -13
  55. janus/parsers/reqs_parser.py +8 -5
  56. janus/parsers/uml.py +5 -4
  57. janus/prompts/prompt.py +2 -2
  58. janus/prompts/templates/README.md +30 -0
  59. janus/prompts/templates/basic_aggregation/human.txt +6 -0
  60. janus/prompts/templates/basic_aggregation/system.txt +1 -0
  61. janus/prompts/templates/basic_refinement/human.txt +14 -0
  62. janus/prompts/templates/basic_refinement/system.txt +1 -0
  63. janus/prompts/templates/diagram/human.txt +9 -0
  64. janus/prompts/templates/diagram/system.txt +1 -0
  65. janus/prompts/templates/diagram_with_documentation/human.txt +15 -0
  66. janus/prompts/templates/diagram_with_documentation/system.txt +1 -0
  67. janus/prompts/templates/document/human.txt +10 -0
  68. janus/prompts/templates/document/system.txt +1 -0
  69. janus/prompts/templates/document_cloze/human.txt +11 -0
  70. janus/prompts/templates/document_cloze/system.txt +1 -0
  71. janus/prompts/templates/document_cloze/variables.json +4 -0
  72. janus/prompts/templates/document_cloze/variables_asm.json +4 -0
  73. janus/prompts/templates/document_inline/human.txt +13 -0
  74. janus/prompts/templates/eval_prompts/incose/human.txt +32 -0
  75. janus/prompts/templates/eval_prompts/incose/system.txt +1 -0
  76. janus/prompts/templates/eval_prompts/incose/variables.json +3 -0
  77. janus/prompts/templates/eval_prompts/inline_comments/human.txt +49 -0
  78. janus/prompts/templates/eval_prompts/inline_comments/system.txt +1 -0
  79. janus/prompts/templates/eval_prompts/inline_comments/variables.json +3 -0
  80. janus/prompts/templates/micromanaged_mumps_v1.0/human.txt +23 -0
  81. janus/prompts/templates/micromanaged_mumps_v1.0/system.txt +3 -0
  82. janus/prompts/templates/micromanaged_mumps_v2.0/human.txt +28 -0
  83. janus/prompts/templates/micromanaged_mumps_v2.0/system.txt +3 -0
  84. janus/prompts/templates/micromanaged_mumps_v2.1/human.txt +29 -0
  85. janus/prompts/templates/micromanaged_mumps_v2.1/system.txt +3 -0
  86. janus/prompts/templates/multidocument/human.txt +15 -0
  87. janus/prompts/templates/multidocument/system.txt +1 -0
  88. janus/prompts/templates/partition/human.txt +22 -0
  89. janus/prompts/templates/partition/system.txt +1 -0
  90. janus/prompts/templates/partition/variables.json +4 -0
  91. janus/prompts/templates/pseudocode/human.txt +7 -0
  92. janus/prompts/templates/pseudocode/system.txt +7 -0
  93. janus/prompts/templates/refinement/fix_exceptions/human.txt +19 -0
  94. janus/prompts/templates/refinement/fix_exceptions/system.txt +1 -0
  95. janus/prompts/templates/refinement/format/code_format/human.txt +12 -0
  96. janus/prompts/templates/refinement/format/code_format/system.txt +1 -0
  97. janus/prompts/templates/refinement/format/requirements_format/human.txt +14 -0
  98. janus/prompts/templates/refinement/format/requirements_format/system.txt +1 -0
  99. janus/prompts/templates/refinement/hallucination/human.txt +13 -0
  100. janus/prompts/templates/refinement/hallucination/system.txt +1 -0
  101. janus/prompts/templates/refinement/reflection/human.txt +15 -0
  102. janus/prompts/templates/refinement/reflection/incose/human.txt +26 -0
  103. janus/prompts/templates/refinement/reflection/incose/system.txt +1 -0
  104. janus/prompts/templates/refinement/reflection/incose_deduplicate/human.txt +16 -0
  105. janus/prompts/templates/refinement/reflection/incose_deduplicate/system.txt +1 -0
  106. janus/prompts/templates/refinement/reflection/system.txt +1 -0
  107. janus/prompts/templates/refinement/revision/human.txt +16 -0
  108. janus/prompts/templates/refinement/revision/incose/human.txt +16 -0
  109. janus/prompts/templates/refinement/revision/incose/system.txt +1 -0
  110. janus/prompts/templates/refinement/revision/incose_deduplicate/human.txt +17 -0
  111. janus/prompts/templates/refinement/revision/incose_deduplicate/system.txt +1 -0
  112. janus/prompts/templates/refinement/revision/system.txt +1 -0
  113. janus/prompts/templates/refinement/uml/alc_fix_variables/human.txt +15 -0
  114. janus/prompts/templates/refinement/uml/alc_fix_variables/system.txt +2 -0
  115. janus/prompts/templates/refinement/uml/fix_connections/human.txt +15 -0
  116. janus/prompts/templates/refinement/uml/fix_connections/system.txt +2 -0
  117. janus/prompts/templates/requirements/human.txt +13 -0
  118. janus/prompts/templates/requirements/system.txt +2 -0
  119. janus/prompts/templates/retrieval/language_docs/human.txt +10 -0
  120. janus/prompts/templates/retrieval/language_docs/system.txt +1 -0
  121. janus/prompts/templates/simple/human.txt +16 -0
  122. janus/prompts/templates/simple/system.txt +3 -0
  123. janus/refiners/format.py +49 -0
  124. janus/refiners/refiner.py +143 -4
  125. janus/utils/enums.py +140 -111
  126. janus/utils/logger.py +2 -0
  127. {janus_llm-4.2.0.dist-info → janus_llm-4.3.5.dist-info}/METADATA +7 -7
  128. janus_llm-4.3.5.dist-info/RECORD +210 -0
  129. {janus_llm-4.2.0.dist-info → janus_llm-4.3.5.dist-info}/WHEEL +1 -1
  130. janus_llm-4.3.5.dist-info/entry_points.txt +3 -0
  131. janus/cli.py +0 -1343
  132. janus_llm-4.2.0.dist-info/RECORD +0 -113
  133. janus_llm-4.2.0.dist-info/entry_points.txt +0 -3
  134. {janus_llm-4.2.0.dist-info → janus_llm-4.3.5.dist-info}/LICENSE +0 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "EXAMPLE_INPUT": "0d2f4f8d\tdef f(n):\ndef2a953\t return n * f_memo(n - 1)\n75315253\ne7f928da\tmemo = {0: 1, 1: 1}\n1781b2a9\tdef f_memo(n):\n2fe21e27\t if n in memo:\n9aef6179\t return memo[n]\n6061bd82\t memo[n] = f(n)\n22bd0c30\t return memo[n]\n5d85e19e\n06027969\tdef combinations(n, k):\n91b722fb\t return f_memo(n) // (f_memo(k) * f_memo(n - k))\n4b3f79be\nk57w964a\tdef prob_n_heads(n, k):\n51638s96\t return combinations(n, k) / (2 ** n)\n065o6q32\nj5q6p852\tprint(f\"Probability of 5/10 coin flips being heads: {prob_n_heads(10, 5)}.\")",
3
+ "EXAMPLE_OUTPUT": "[\n {\n \"reasoning\": \"The `combinations` function can be understood without the above implementation of factorials. However, the definitions of `f` and `f_memo` cannot be understood without one another, so there should be no partitions between 0d2f4f8d and 06027969.\",\n \"location\": \"06027969\"\n },\n {\n \"reasoning\": \"The specific implementation of `combinations` is not necessary to understand the functionality of `prob_n_heads` or the print statement\",\n \"location\": \"k57w964a\"\n }\n]"
4
+ }
@@ -0,0 +1,7 @@
1
+ Please convert all of the following code into pseudocode that can replicate its functionality.
2
+
3
+ Here is the code
4
+
5
+ ```
6
+ {SOURCE_CODE}
7
+ ```
@@ -0,0 +1,7 @@
1
+ Your purpose is to understand a source code file (or section of code) and generate easy-to-understand pseudocode for it.
2
+
3
+ This pseudocode should be written such that it is not tied to the programming language of the source code. For example, if the source code is written in Java, the pseudocode should not be written in Java. It should be written more abstract and should not focus on the syntax of the source code.
4
+
5
+ Do not leave sections of the source code unexplained.
6
+
7
+ Ensure the pseudocode that you produce lies within triple backticks (```).
@@ -0,0 +1,19 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ ERROR:
12
+ ```
13
+ {error}
14
+ ```
15
+ --------------------
16
+ Above, the COMPLETION did not satisfy the constraints given in the TASK, resulting in the ERROR.
17
+ Please update the COMPLETION such that it satisfies the constraints laid out in the TASK.
18
+ Do NOT make any changes to the COMPLETION other than are required to fix the ERROR.
19
+ Your response should contain a complete output. Do not provide any other commentary or followup questions.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with correcting invalid outputs from Large Language Models (LLMs). Given a task, an invalid output, and the parsing error, it is your job to write a new version of the output that resolves the error and meets the task requirements.
@@ -0,0 +1,12 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Above, the COMPLETION should be formatted to have its relevant output between tripple backticks.
12
+ Please extract the relevant output (e.g. any generated code) from the COMPLETION and output it between tripple backticks.
@@ -0,0 +1 @@
1
+ You are a helpful software engineer named John tasked with taking unformated code and putting it into a specific output format.
@@ -0,0 +1,14 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Above, the COMPLETION should be formatted to have its relevant output in json.
12
+ Extract all the generated requirements from the COMPLETION, and output a JSON-formatted string with the requirements text only a single key: "requirements".
13
+ The value of the requirements key should be a list of strings, with each requirement in a single string, and no further nesting in items in the list.
14
+ Ensure that the output string is properly formatted JSON.
@@ -0,0 +1 @@
1
+ You are a helpful software engineer named John tasked with taking unformated code and putting it into a specific output format.
@@ -0,0 +1,13 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Identify any hallucinations or factual errors in the provided COMPLETION of the above TASK. Return a numbered list of hallucinations, each with an explanation of the problem.
12
+
13
+ If no hallucinations are present, respond with LGTM. "LGTM" must be returned on its own without any further commentary.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with identifying hallucinations and factual errors in Large Language Models (LLMs). Given a task and an output, it is your job to identify any hallucinations in the output. If the output is hallucination-free, you may approve it with a simple "LGTM".
@@ -0,0 +1,15 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Generate critique and suggestions for the provided COMPLETION of the above TASK. Your suggestions can including requests for added detail, corrections of factual errors, improved style, etc.
12
+
13
+ Do not rewrite the output yourself, only provide critique that can be acted on. Provide no further commentary or questions other than your feedback.
14
+
15
+ If the output fully meets the requirements of the task and is of high quality, respond with LGTM. "LGTM" must be returned on its own without further commentary.
@@ -0,0 +1,26 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ REQUIREMENTS:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+
12
+ Generate critique and suggestions for the provided REQUIREMENTS based on the above TASK. Your suggestions can include requests for added detail, corrections of factual errors, improved style, etc. to ensure that each of the requirements meet INCOSE standards, described below.
13
+
14
+ Do not rewrite the output yourself, only provide critique that can be acted on. Provide no further commentary or questions other than your feedback.
15
+
16
+ If every single one of the requirements meets the following INCOSE standards, return LGTM. "LGTM" must be returned on its own without further commentary. Be especially strict in your grading!
17
+
18
+ C1 - Necessary: The need or requirement statement defines an essential capability, characteristic, constraint, or quality factor needed to satisfy a lifecycle concept, need, source, or parent requirement.
19
+ C2 - Appropriate: The specific intent and amount of detail of the need or requirement statement is appropriate to the level (the level of abstraction, organization, or system architecture) of the entity to which it refers.
20
+ C3 - Unambiguous: Need statements must be written such that the stakeholder intent is clear. Requirement statements must be stated such that the requirement can be interpreted in only one way by all the intended stakeholders.
21
+ C4 - Complete: The requirement statement sufficiently describes the necessary capability, characteristic, constraint, or quality factor to meet the need, source, or parent requirement from which it was transformed without needing other information to understand the requirement.
22
+ C5 - Singular: The stakeholder need or requirement statement should state a single capability, characteristic, constraint, or quality factor.
23
+ C6 - Feasible: The need or requirement can be realized within entity constraints (for example: cost, schedule, technical, legal, ethical, safety) with acceptable risk.
24
+ C7 - Verifiable: The requirement statement is structured and worded such that its realization can be verified to the approving authority’s satisfaction.
25
+ C8 - Correct: The need statement must be an accurate representation of the lifecycle concept or source from which it was transformed. The requirement statement must be an accurate representation of the need, source, or parent requirement from which it was transformed.
26
+ C9 - Conforming: Individual needs and requirements should conform to an approved standard pattern and style guide or standard for writing and managing needs and requirements.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with reviewing and critiquing outputs from Large Language Models (LLMs). Given a task and an output, it is your job to generate critique and suggestions to improve the output. If the output fully meets the requirements of the task and is of high quality, you may approve it with a simple "LGTM".
@@ -0,0 +1,16 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ REQUIREMENTS:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+
12
+ In order for software requirements to be useful for software modernization, they must be reasonably consise and not overly specific to the syntax of the legacy language of the code which they describe. With this in mind, for the provided TASK, suggest ways that the REQUIREMENTS could be less redundant. If the REQUIREMENTS include duplicated or unnecessary requirements, explain how some of them could be combined to reduce this number. If the REQUIREMENTS refer to specific aspects of the original coding language which would not be useful to a software developer porting the code to a new language, point it out.
13
+
14
+ Do not rewrite the output yourself, only provide critique that can be acted on. Provide no further commentary or questions other than your feedback.
15
+
16
+ If the requirements in the completion above are adequately consise, return LGTM. "LGTM" must be returned on its own without further commentary.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with reviewing and critiquing outputs from Large Language Models (LLMs). Given a task and an output, it is your job to generate critique and suggestions to improve the output. If the output fully meets the requirements of the task and is of high quality, you may approve it with a simple "LGTM".
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with reviewing and critiquing outputs from Large Language Models (LLMs). Given a task and an output, it is your job to generate critique and suggestions to improve the output. If the output fully meets the requirements of the task and is of high quality, you may approve it with a simple "LGTM".
@@ -0,0 +1,16 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ FEEDBACK:
12
+ ```
13
+ {reflection}
14
+ ```
15
+ --------------------
16
+ Improve the above COMPLETION of the given TASK by incorporating the provided FEEDBACK. Respond only with the revised output, following the format indicated in the original TASK description. Do not provide any additional commentary or questions about the critique.
@@ -0,0 +1,16 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ REQUIREMENTS:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ FEEDBACK:
12
+ ```
13
+ {reflection}
14
+ ```
15
+ --------------------
16
+ Improve the above REQUIREMENTS for the given TASK by incorporating the provided FEEDBACK. Respond only with the revised output, following the format indicated in the original TASK description. Do not provide any additional commentary or questions about the critique.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with improving outputs of Large Language Models according to human feedback. Given a task, a draft output, and some critique of that draft, it is your job to write a new version of the output that incorporates the provided suggestions and addresses any criticism.
@@ -0,0 +1,17 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ FEEDBACK:
12
+ ```
13
+ {reflection}
14
+ ```
15
+ --------------------
16
+ Improve the above COMPLETION of the given TASK by incorporating the provided FEEDBACK. Respond only with the revised output, following the format indicated in the original TASK description. Do not provide any additional commentary or questions about the critique.
17
+ g: Individual needs and requirements should conform to an approved standard pattern and style guide or standard for writing and managing needs and requirements.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with improving outputs of Large Language Models according to human feedback. Given a task, a draft output, and some critique of that draft, it is your job to write a new version of the output that incorporates the provided suggestions and addresses any criticism.
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with improving outputs of Large Language Models according to human feedback. Given a task, a draft output, and some critique of that draft, it is your job to write a new version of the output that incorporates the provided suggestions and addresses any criticism.
@@ -0,0 +1,15 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Find any instances of variables in the provided COMPLETION of the above TASK being referenced without their proper namespace. Variables should always be referenced as data_structure.variable. Data structures can include classes, DSECTS, files or other similar language features.
12
+
13
+ Do not rewrite the output yourself, only provide critique that can be acted on. Provide no further commentary or questions other than your feedback.
14
+
15
+ If the output fully meets the requirements of the task and no variables are referenced outside their appropriate class or DSECT, respond with LGTM. "LGTM" must be returned on its own without further commentary.
@@ -0,0 +1,2 @@
1
+ You are a software engineer and quality control professional tasked with reviewing and critiquing outputs from Large Language Models (LLMs). Given a task and an output, it is your job to generate critique and suggestions to improve the output.
2
+ You must detect any instances of variables being referenced in the UML without referencing their appropriate namespace (i.e. struct.var). If the output fully meets the requirements of the task and all variables are appropriately referenced, you may approve it with a simple "LGTM".
@@ -0,0 +1,15 @@
1
+ TASK:
2
+ ```
3
+ {prompt}
4
+ ```
5
+ --------------------
6
+ COMPLETION:
7
+ ```
8
+ {completion}
9
+ ```
10
+ --------------------
11
+ Find any instances of connections in the provided COMPLETION of the above TASK that do not accurately represent the control flow of the program. The COMPLETION should accurately capture the entire control flow of the original program in the TASK.
12
+
13
+ Do not rewrite the output yourself, only provide critique that can be acted on. Provide no further commentary or questions other than your feedback.
14
+
15
+ If the output fully meets the requirements of the task and the control flow of the program in the TASK is accurately reflected, respond with LGTM. "LGTM" must be returned on its own without further commentary.
@@ -0,0 +1,2 @@
1
+ You are a software engineer and quality control professional tasked with reviewing and critiquing outputs from Large Language Models (LLMs). Given a task and an output, it is your job to generate critique and suggestions to improve the output.
2
+ You must detect any connections in the UML that do not accurately represent the control flow. If the output fully meets the requirements of the task and the control flow is correctly represented, you may approve it with a simple "LGTM".
@@ -0,0 +1,13 @@
1
+ We are modernizing the following code so we need to extract software requirements to document its functionality.
2
+
3
+ These requirements are intended for developers to refactor and port this code to a modern programming language, so they should focus on functionality rather than specifics of its current legacy language.
4
+
5
+ Write the requirements in the style of an INCOSE software requirements specification document.
6
+
7
+ Here is the code:
8
+
9
+ ```
10
+ {SOURCE_CODE}
11
+ ```
12
+
13
+ {context}
@@ -0,0 +1,2 @@
1
+ Your purpose is to understand a source code file
2
+ and generate a software requirements specification document for it.
@@ -0,0 +1,10 @@
1
+ Are there any references in the following {SOURCE_LANGUAGE} source code to uncommon or obscure built-in language functionality e.g. stand library calls, opcode, etc. that you do not understand and may be present in a language reference manual?
2
+
3
+ If so, return a short, comma-separated list of functions or opcodes to reference the manual for. Do not return any basic language functionality.
4
+
5
+ If not, return 'NODOCS'. 'NODOCS' must be returned on its own without further commentary.
6
+
7
+ Here is the code:
8
+ ```
9
+ {SOURCE_CODE}
10
+ ```
@@ -0,0 +1 @@
1
+ You are a software engineer and quality control professional tasked with providing context to source code by suggesting aspects of the code which could be made more clear by referencing a language manual. Given some source code, it is your job to pick out standard library calls or instructions which could be clarified with a reference. If there are no such code features, you may skip with process with the response "NODOCS".
@@ -0,0 +1,16 @@
1
+ Please convert the following {SOURCE_LANGUAGE} .{FILE_SUFFIX} code found in between triple backticks
2
+ into {TARGET_LANGUAGE} code.
3
+
4
+ If the given code is incomplete, assume it is translated elsewhere.
5
+ If the given code is missing variable definitions, assume they are assigned elsewhere.
6
+ If there are incomplete statements that haven't been closed out, assume they are closed out in other translations.
7
+ If the code has comments, keep ALL of them.
8
+ If it only consists of ONLY comments, assume the code that is represented by those comments is translated elsewhere.
9
+
10
+ Some more things to remember:
11
+ (1) follow standard styling practice for the target language
12
+ (2) make sure the language is typed correctly
13
+
14
+ ```
15
+ {SOURCE_CODE}
16
+ ```
@@ -0,0 +1,3 @@
1
+ Your purpose is to convert {SOURCE_LANGUAGE} {FILE_SUFFIX} code
2
+ into runnable {TARGET_LANGUAGE} code ({TARGET_LANGUAGE} version
3
+ {TARGET_LANGUAGE_VERSION}).
@@ -0,0 +1,49 @@
1
+ from typing import Any
2
+
3
+ from langchain_core.output_parsers import StrOutputParser
4
+ from langchain_core.prompt_values import PromptValue
5
+ from langchain_core.runnables import RunnableSerializable
6
+
7
+ from janus.llm.models_info import MODEL_PROMPT_ENGINES, JanusModel
8
+ from janus.parsers.parser import JanusParser
9
+ from janus.refiners.refiner import JanusRefiner
10
+
11
+
12
+ class FormatRefiner(JanusRefiner):
13
+ format_chain: RunnableSerializable
14
+
15
+ def __init__(
16
+ self,
17
+ llm: JanusModel,
18
+ parser: JanusParser,
19
+ max_retries: int,
20
+ prompt_template_name: str,
21
+ ):
22
+ format_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
23
+ source_language="text",
24
+ prompt_template=prompt_template_name,
25
+ ).prompt
26
+ format_chain = format_prompt | llm | StrOutputParser()
27
+ super().__init__(
28
+ format_chain=format_chain, parser=parser, max_retries=max_retries
29
+ )
30
+
31
+ def parse_completion(
32
+ self, completion: str, prompt_value: PromptValue, **kwargs
33
+ ) -> Any:
34
+ completion = self.format_chain.invoke(
35
+ dict(completion=completion, prompt=prompt_value.to_string())
36
+ )
37
+ return self.parser.parse(completion)
38
+
39
+
40
+ class CodeFormatRefiner(FormatRefiner):
41
+ def __init__(self, llm: JanusModel, parser: JanusParser, max_retries: int):
42
+ super().__init__(llm, parser, max_retries, "refinement/format/code_format")
43
+
44
+
45
+ class RequirementsFormatRefiner(FormatRefiner):
46
+ def __init__(self, llm: JanusModel, parser: JanusParser, max_retries: int):
47
+ super().__init__(
48
+ llm, parser, max_retries, "refinement/format/requirements_format"
49
+ )
janus/refiners/refiner.py CHANGED
@@ -2,6 +2,8 @@ import re
2
2
  from typing import Any
3
3
 
4
4
  from langchain.output_parsers import RetryWithErrorOutputParser
5
+ from langchain_core.exceptions import OutputParserException
6
+ from langchain_core.messages import AIMessage
5
7
  from langchain_core.output_parsers import StrOutputParser
6
8
  from langchain_core.prompt_values import PromptValue
7
9
  from langchain_core.runnables import RunnableSerializable
@@ -26,6 +28,35 @@ class JanusRefiner(JanusParser):
26
28
  raise NotImplementedError
27
29
 
28
30
 
31
+ class SimpleRetry(JanusRefiner):
32
+ max_retries: int
33
+ retry_chain: RunnableSerializable
34
+
35
+ def __init__(
36
+ self,
37
+ llm: JanusModel,
38
+ parser: JanusParser,
39
+ max_retries: int,
40
+ ):
41
+ retry_chain = llm | StrOutputParser()
42
+ super().__init__(
43
+ retry_chain=retry_chain,
44
+ parser=parser,
45
+ max_retries=max_retries,
46
+ )
47
+
48
+ def parse_completion(
49
+ self, completion: str, prompt_value: PromptValue, **kwargs
50
+ ) -> Any:
51
+ for retry_number in range(self.max_retries):
52
+ try:
53
+ return self.parser.parse(completion)
54
+ except OutputParserException:
55
+ completion = self.retry_chain.invoke(prompt_value)
56
+
57
+ return self.parser.parse(completion)
58
+
59
+
29
60
  class FixParserExceptions(JanusRefiner, RetryWithErrorOutputParser):
30
61
  def __init__(self, llm: JanusModel, parser: JanusParser, max_retries: int):
31
62
  retry_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
@@ -78,7 +109,7 @@ class ReflectionRefiner(JanusRefiner):
78
109
  def parse_completion(
79
110
  self, completion: str, prompt_value: PromptValue, **kwargs
80
111
  ) -> Any:
81
- log.info(f"Reflection Prompt: {self.reflection_prompt_name}")
112
+ log.debug(f"Reflection Prompt: {self.reflection_prompt_name}")
82
113
  for retry_number in range(self.max_retries):
83
114
  reflection = self.reflection_chain.invoke(
84
115
  dict(
@@ -89,8 +120,117 @@ class ReflectionRefiner(JanusRefiner):
89
120
  if re.search(r"\bLGTM\b", reflection) is not None:
90
121
  return self.parser.parse(completion)
91
122
  if not retry_number:
92
- log.info(f"Completion:\n{completion}")
93
- log.info(f"Reflection:\n{reflection}")
123
+ log.debug(f"Completion:\n{completion}")
124
+ log.debug(f"Reflection:\n{reflection}")
125
+ completion = self.revision_chain.invoke(
126
+ dict(
127
+ prompt=prompt_value.to_string(),
128
+ completion=completion,
129
+ reflection=reflection,
130
+ )
131
+ )
132
+ log.debug(f"Revision:\n{completion}")
133
+
134
+ return self.parser.parse(completion)
135
+
136
+
137
+ class RequirementsReflectionRefiner(JanusRefiner):
138
+ """
139
+ This requirements-specific refiner is intended to address a common issue with
140
+ requirements reflection, where over the course of several reflection loops,
141
+ requirements lists grow increasingly verbose, eventually becoming too wordy
142
+ to be useful. To reduce this, this refiner interlaces an additional reflection
143
+ -> revision loop which de-duplicates requirements.
144
+ """
145
+
146
+ max_retries: int
147
+ reflection_chain: RunnableSerializable
148
+ revision_chain: RunnableSerializable
149
+ reflect_duplication_chain: RunnableSerializable
150
+ revise_duplication_chain: RunnableSerializable
151
+ reflection_prompt_name: str
152
+
153
+ def __init__(
154
+ self,
155
+ llm: JanusModel,
156
+ parser: JanusParser,
157
+ max_retries: int,
158
+ prompt_template_name: str = "refinement/reflection/incose",
159
+ ):
160
+ # Main reflection loop
161
+ reflection_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
162
+ source_language="text",
163
+ prompt_template="refinement/reflection/incose",
164
+ ).prompt
165
+ revision_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
166
+ source_language="text",
167
+ prompt_template="refinement/revision/incose",
168
+ ).prompt
169
+ # De-duplication loop
170
+ reflect_duplication_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
171
+ source_language="text",
172
+ prompt_template="refinement/reflection/incose_deduplicate",
173
+ ).prompt
174
+ revise_duplication_prompt = MODEL_PROMPT_ENGINES[llm.short_model_id](
175
+ source_language="text",
176
+ prompt_template="refinement/revision/incose_deduplicate",
177
+ ).prompt
178
+
179
+ reflection_chain = reflection_prompt | llm | StrOutputParser()
180
+ revision_chain = revision_prompt | llm | StrOutputParser()
181
+ reflect_duplication_chain = reflect_duplication_prompt | llm | StrOutputParser()
182
+ revise_duplication_chain = revise_duplication_prompt | llm | StrOutputParser()
183
+ super().__init__(
184
+ reflection_prompt_name=prompt_template_name,
185
+ reflection_chain=reflection_chain,
186
+ revision_chain=revision_chain,
187
+ reflect_duplication_chain=reflect_duplication_chain,
188
+ revise_duplication_chain=revise_duplication_chain,
189
+ parser=parser,
190
+ max_retries=max_retries,
191
+ )
192
+
193
+ def parse_completion(
194
+ self, completion: str, prompt_value: PromptValue, **kwargs
195
+ ) -> Any:
196
+ log.debug(f"Reflection Prompt: {self.reflection_prompt_name}")
197
+ if isinstance(completion, AIMessage):
198
+ completion = completion.content
199
+ for retry_number in range(self.max_retries):
200
+ # First, check if the generated requirements are redundant or too specific
201
+ duplication_reflection = self.reflect_duplication_chain.invoke(
202
+ dict(
203
+ prompt=prompt_value.to_string(),
204
+ completion=completion,
205
+ )
206
+ )
207
+ if re.search(r"\bLGTM\b", duplication_reflection) is not None:
208
+ log.debug(
209
+ "No de-duplication suggested in reflection, "
210
+ "passing to next reflection step"
211
+ )
212
+ else:
213
+ completion = self.revise_duplication_chain.invoke(
214
+ dict(
215
+ prompt=prompt_value.to_string(),
216
+ completion=completion,
217
+ reflection=duplication_reflection,
218
+ )
219
+ )
220
+
221
+ # Once we're happy with the results or trimmed them down,
222
+ # continue with the typical reflection process,
223
+ # except with specific INCOSE-focused prompts
224
+ reflection = self.reflection_chain.invoke(
225
+ dict(
226
+ prompt=prompt_value.to_string(),
227
+ completion=completion,
228
+ )
229
+ )
230
+ if re.search(r"\bLGTM\b", reflection) is not None:
231
+ return self.parser.parse(completion)
232
+ if not retry_number:
233
+ log.debug(f"Completion:\n{completion}")
94
234
  completion = self.revision_chain.invoke(
95
235
  dict(
96
236
  prompt=prompt_value.to_string(),
@@ -98,7 +238,6 @@ class ReflectionRefiner(JanusRefiner):
98
238
  reflection=reflection,
99
239
  )
100
240
  )
101
- log.info(f"Revision:\n{completion}")
102
241
 
103
242
  return self.parser.parse(completion)
104
243