janus-llm 4.3.1__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.
- janus/__init__.py +1 -1
- janus/__main__.py +1 -1
- janus/_tests/evaluator_tests/EvalReadMe.md +85 -0
- janus/_tests/evaluator_tests/incose_tests/incose_large_test.json +39 -0
- janus/_tests/evaluator_tests/incose_tests/incose_small_test.json +17 -0
- janus/_tests/evaluator_tests/inline_comment_tests/mumps_inline_comment_test.m +71 -0
- janus/_tests/test_cli.py +3 -2
- janus/cli/aggregate.py +135 -0
- janus/cli/cli.py +111 -0
- janus/cli/constants.py +43 -0
- janus/cli/database.py +289 -0
- janus/cli/diagram.py +178 -0
- janus/cli/document.py +174 -0
- janus/cli/embedding.py +122 -0
- janus/cli/llm.py +187 -0
- janus/cli/partition.py +125 -0
- janus/cli/self_eval.py +149 -0
- janus/cli/translate.py +183 -0
- janus/converter/__init__.py +1 -1
- janus/converter/_tests/test_translate.py +2 -0
- janus/converter/converter.py +129 -93
- janus/converter/document.py +21 -14
- janus/converter/evaluate.py +20 -13
- janus/converter/translate.py +3 -3
- janus/embedding/collections.py +1 -1
- janus/language/alc/_tests/alc.asm +3779 -0
- janus/language/binary/_tests/hello.bin +0 -0
- janus/language/block.py +47 -12
- janus/language/file.py +1 -1
- janus/language/mumps/_tests/mumps.m +235 -0
- janus/language/treesitter/_tests/languages/fortran.f90 +416 -0
- janus/language/treesitter/_tests/languages/ibmhlasm.asm +16 -0
- janus/language/treesitter/_tests/languages/matlab.m +225 -0
- janus/llm/models_info.py +9 -1
- janus/metrics/_tests/asm_test_file.asm +10 -0
- janus/metrics/_tests/mumps_test_file.m +6 -0
- janus/metrics/_tests/test_treesitter_metrics.py +1 -1
- janus/metrics/prompts/clarity.txt +8 -0
- janus/metrics/prompts/completeness.txt +16 -0
- janus/metrics/prompts/faithfulness.txt +10 -0
- janus/metrics/prompts/hallucination.txt +16 -0
- janus/metrics/prompts/quality.txt +8 -0
- janus/metrics/prompts/readability.txt +16 -0
- janus/metrics/prompts/usefulness.txt +16 -0
- janus/parsers/code_parser.py +4 -4
- janus/parsers/doc_parser.py +12 -9
- janus/parsers/parser.py +7 -0
- janus/parsers/partition_parser.py +6 -4
- janus/parsers/reqs_parser.py +8 -5
- janus/parsers/uml.py +5 -4
- janus/prompts/prompt.py +2 -2
- janus/prompts/templates/README.md +30 -0
- janus/prompts/templates/basic_aggregation/human.txt +6 -0
- janus/prompts/templates/basic_aggregation/system.txt +1 -0
- janus/prompts/templates/basic_refinement/human.txt +14 -0
- janus/prompts/templates/basic_refinement/system.txt +1 -0
- janus/prompts/templates/diagram/human.txt +9 -0
- janus/prompts/templates/diagram/system.txt +1 -0
- janus/prompts/templates/diagram_with_documentation/human.txt +15 -0
- janus/prompts/templates/diagram_with_documentation/system.txt +1 -0
- janus/prompts/templates/document/human.txt +10 -0
- janus/prompts/templates/document/system.txt +1 -0
- janus/prompts/templates/document_cloze/human.txt +11 -0
- janus/prompts/templates/document_cloze/system.txt +1 -0
- janus/prompts/templates/document_cloze/variables.json +4 -0
- janus/prompts/templates/document_cloze/variables_asm.json +4 -0
- janus/prompts/templates/document_inline/human.txt +13 -0
- janus/prompts/templates/eval_prompts/incose/human.txt +32 -0
- janus/prompts/templates/eval_prompts/incose/system.txt +1 -0
- janus/prompts/templates/eval_prompts/incose/variables.json +3 -0
- janus/prompts/templates/eval_prompts/inline_comments/human.txt +49 -0
- janus/prompts/templates/eval_prompts/inline_comments/system.txt +1 -0
- janus/prompts/templates/eval_prompts/inline_comments/variables.json +3 -0
- janus/prompts/templates/micromanaged_mumps_v1.0/human.txt +23 -0
- janus/prompts/templates/micromanaged_mumps_v1.0/system.txt +3 -0
- janus/prompts/templates/micromanaged_mumps_v2.0/human.txt +28 -0
- janus/prompts/templates/micromanaged_mumps_v2.0/system.txt +3 -0
- janus/prompts/templates/micromanaged_mumps_v2.1/human.txt +29 -0
- janus/prompts/templates/micromanaged_mumps_v2.1/system.txt +3 -0
- janus/prompts/templates/multidocument/human.txt +15 -0
- janus/prompts/templates/multidocument/system.txt +1 -0
- janus/prompts/templates/partition/human.txt +22 -0
- janus/prompts/templates/partition/system.txt +1 -0
- janus/prompts/templates/partition/variables.json +4 -0
- janus/prompts/templates/pseudocode/human.txt +7 -0
- janus/prompts/templates/pseudocode/system.txt +7 -0
- janus/prompts/templates/refinement/fix_exceptions/human.txt +19 -0
- janus/prompts/templates/refinement/fix_exceptions/system.txt +1 -0
- janus/prompts/templates/refinement/format/code_format/human.txt +12 -0
- janus/prompts/templates/refinement/format/code_format/system.txt +1 -0
- janus/prompts/templates/refinement/format/requirements_format/human.txt +14 -0
- janus/prompts/templates/refinement/format/requirements_format/system.txt +1 -0
- janus/prompts/templates/refinement/hallucination/human.txt +13 -0
- janus/prompts/templates/refinement/hallucination/system.txt +1 -0
- janus/prompts/templates/refinement/reflection/human.txt +15 -0
- janus/prompts/templates/refinement/reflection/incose/human.txt +26 -0
- janus/prompts/templates/refinement/reflection/incose/system.txt +1 -0
- janus/prompts/templates/refinement/reflection/incose_deduplicate/human.txt +16 -0
- janus/prompts/templates/refinement/reflection/incose_deduplicate/system.txt +1 -0
- janus/prompts/templates/refinement/reflection/system.txt +1 -0
- janus/prompts/templates/refinement/revision/human.txt +16 -0
- janus/prompts/templates/refinement/revision/incose/human.txt +16 -0
- janus/prompts/templates/refinement/revision/incose/system.txt +1 -0
- janus/prompts/templates/refinement/revision/incose_deduplicate/human.txt +17 -0
- janus/prompts/templates/refinement/revision/incose_deduplicate/system.txt +1 -0
- janus/prompts/templates/refinement/revision/system.txt +1 -0
- janus/prompts/templates/refinement/uml/alc_fix_variables/human.txt +15 -0
- janus/prompts/templates/refinement/uml/alc_fix_variables/system.txt +2 -0
- janus/prompts/templates/refinement/uml/fix_connections/human.txt +15 -0
- janus/prompts/templates/refinement/uml/fix_connections/system.txt +2 -0
- janus/prompts/templates/requirements/human.txt +13 -0
- janus/prompts/templates/requirements/system.txt +2 -0
- janus/prompts/templates/retrieval/language_docs/human.txt +10 -0
- janus/prompts/templates/retrieval/language_docs/system.txt +1 -0
- janus/prompts/templates/simple/human.txt +16 -0
- janus/prompts/templates/simple/system.txt +3 -0
- janus/refiners/format.py +49 -0
- janus/refiners/refiner.py +113 -4
- janus/utils/enums.py +127 -112
- janus/utils/logger.py +2 -0
- {janus_llm-4.3.1.dist-info → janus_llm-4.3.5.dist-info}/METADATA +7 -7
- janus_llm-4.3.5.dist-info/RECORD +210 -0
- {janus_llm-4.3.1.dist-info → janus_llm-4.3.5.dist-info}/WHEEL +1 -1
- janus_llm-4.3.5.dist-info/entry_points.txt +3 -0
- janus/cli.py +0 -1488
- janus_llm-4.3.1.dist-info/RECORD +0 -115
- janus_llm-4.3.1.dist-info/entry_points.txt +0 -3
- {janus_llm-4.3.1.dist-info → janus_llm-4.3.5.dist-info}/LICENSE +0 -0
janus/llm/models_info.py
CHANGED
@@ -50,6 +50,7 @@ except ImportError:
|
|
50
50
|
ModelType = TypeVar(
|
51
51
|
"ModelType",
|
52
52
|
AzureChatOpenAI,
|
53
|
+
ChatOpenAI,
|
53
54
|
HuggingFaceTextGenInference,
|
54
55
|
Bedrock,
|
55
56
|
BedrockChat,
|
@@ -247,6 +248,7 @@ def load_model(model_id) -> JanusModel:
|
|
247
248
|
token_limit = model_config["token_limit"]
|
248
249
|
input_token_cost = model_config["model_cost"]["input"]
|
249
250
|
output_token_cost = model_config["model_cost"]["output"]
|
251
|
+
input_token_proportion = model_config["input_token_proportion"]
|
250
252
|
|
251
253
|
elif model_id in DEFAULT_MODELS:
|
252
254
|
model_id = model_id
|
@@ -257,6 +259,7 @@ def load_model(model_id) -> JanusModel:
|
|
257
259
|
token_limit = 0
|
258
260
|
input_token_cost = 0.0
|
259
261
|
output_token_cost = 0.0
|
262
|
+
input_token_proportion = 0.4
|
260
263
|
if model_long_id in TOKEN_LIMITS:
|
261
264
|
token_limit = TOKEN_LIMITS[model_long_id]
|
262
265
|
if model_long_id in COST_PER_1K_TOKENS:
|
@@ -286,7 +289,6 @@ def load_model(model_id) -> JanusModel:
|
|
286
289
|
elif model_type_name == "OpenAI":
|
287
290
|
model_args.update(
|
288
291
|
openai_api_key=str(os.getenv("OPENAI_API_KEY")),
|
289
|
-
openai_organization=str(os.getenv("OPENAI_ORG_ID")),
|
290
292
|
)
|
291
293
|
# log.warning("Do NOT use this model in sensitive environments!")
|
292
294
|
# log.warning("If you would like to cancel, please press Ctrl+C.")
|
@@ -310,15 +312,20 @@ def load_model(model_id) -> JanusModel:
|
|
310
312
|
|
311
313
|
class JanusModel(model_type):
|
312
314
|
model_id: str
|
315
|
+
# model_name is for LangChain compatibility
|
316
|
+
# It searches for `self.model_name` when counting tokens
|
317
|
+
model_name: str
|
313
318
|
short_model_id: str
|
314
319
|
model_type_name: str
|
315
320
|
token_limit: int
|
321
|
+
input_token_proportion: float
|
316
322
|
input_token_cost: float
|
317
323
|
output_token_cost: float
|
318
324
|
prompt_engine: type[PromptEngine]
|
319
325
|
|
320
326
|
model_args.update(
|
321
327
|
model_id=MODEL_ID_TO_LONG_ID[model_id],
|
328
|
+
model_name=model_id, # This is for LangChain compatibility
|
322
329
|
short_model_id=model_id,
|
323
330
|
)
|
324
331
|
|
@@ -327,6 +334,7 @@ def load_model(model_id) -> JanusModel:
|
|
327
334
|
token_limit=token_limit,
|
328
335
|
input_token_cost=input_token_cost,
|
329
336
|
output_token_cost=output_token_cost,
|
337
|
+
input_token_proportion=input_token_proportion,
|
330
338
|
prompt_engine=prompt_engine,
|
331
339
|
**model_args,
|
332
340
|
)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Based on the following target written in the {language} programming language, how would you rate the code clarity of the target on a scale of integers from 1 to 10? Higher is better.
|
2
|
+
|
3
|
+
Think through your answer before selecting a rating with the following format:
|
4
|
+
|
5
|
+
Target: the target code
|
6
|
+
{format_instructions}
|
7
|
+
|
8
|
+
Target: {target}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Use the following rubric to evaluate the target written in the {language} programming language:
|
2
|
+
|
3
|
+
Rubric:
|
4
|
+
Does the comment address all capabilities of the relevant source code?
|
5
|
+
|
6
|
+
10 - All essential functionality is documented.
|
7
|
+
6-9 - Most essential functionality is documented.
|
8
|
+
2-5 - Little essential functionality is documented.
|
9
|
+
1 - No essential functionality is documented.
|
10
|
+
|
11
|
+
Think through your answer before selecting a rating with the following format:
|
12
|
+
|
13
|
+
Target: the target code
|
14
|
+
{format_instructions}
|
15
|
+
|
16
|
+
Target: {target}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Based on the following target and reference written in the {language} programming language, how would you rate the faithfulness of the target to the original reference on a scale of integers from 1 to 10? Higher is better.
|
2
|
+
|
3
|
+
Think through your answer before selecting a rating with the following format:
|
4
|
+
|
5
|
+
Target: the target code
|
6
|
+
Reference: the reference code that we are judging the target against
|
7
|
+
{format_instructions}
|
8
|
+
|
9
|
+
Target: {target}
|
10
|
+
Reference: {reference}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Use the following rubric to evaluate the target written in the {language} programming language:
|
2
|
+
|
3
|
+
Rubric:
|
4
|
+
Does the comment provide true information?
|
5
|
+
|
6
|
+
10 - The comment provides only true information.
|
7
|
+
6-9 - The comment provides mostly true information.
|
8
|
+
2-5 - The comment provides mostly untrue information.
|
9
|
+
1 - The comment is completely untrue.
|
10
|
+
|
11
|
+
Think through your answer before selecting a rating with the following format:
|
12
|
+
|
13
|
+
Target: the target code
|
14
|
+
{format_instructions}
|
15
|
+
|
16
|
+
Target: {target}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Based on the following target written in the {language} programming language, how would you rate the code quality of the target on a scale of integers from 1 to 10? Higher is better.
|
2
|
+
|
3
|
+
Think through your answer before selecting a rating with the following format:
|
4
|
+
|
5
|
+
Target: the target code
|
6
|
+
{format_instructions}
|
7
|
+
|
8
|
+
Target: {target}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Use the following rubric to evaluate the target written in the {language} programming language:
|
2
|
+
|
3
|
+
Rubric:
|
4
|
+
Is the comment clear to read?
|
5
|
+
|
6
|
+
10 - The comment is well-written.
|
7
|
+
6-9 - The comment has few problems.
|
8
|
+
2-5 - The comment has many problems.
|
9
|
+
1 - The comment is unreadable.
|
10
|
+
|
11
|
+
Think through your answer before selecting a rating with the following format:
|
12
|
+
|
13
|
+
Target: the target code
|
14
|
+
{format_instructions}
|
15
|
+
|
16
|
+
Target: {target}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Use the following rubric to evaluate the target written in the {language} programming language:
|
2
|
+
|
3
|
+
Rubric:
|
4
|
+
Is the comment useful?
|
5
|
+
|
6
|
+
10 - The comment helps an expert programmer understand the code better.
|
7
|
+
6-9 - The comment helps an average programmer understand the code better.
|
8
|
+
2-5 - The comment documents only trivial functionality.
|
9
|
+
1 - The comment is not useful at any level.
|
10
|
+
|
11
|
+
Think through your answer before selecting a rating with the following format:
|
12
|
+
|
13
|
+
Target: the target code
|
14
|
+
{format_instructions}
|
15
|
+
|
16
|
+
Target: {target}
|
janus/parsers/code_parser.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import re
|
2
2
|
|
3
|
-
from langchain_core.exceptions import OutputParserException
|
4
3
|
from langchain_core.messages import BaseMessage
|
5
4
|
|
6
|
-
from janus.parsers.parser import JanusParser
|
5
|
+
from janus.parsers.parser import JanusParser, JanusParserException
|
7
6
|
from janus.utils.logger import create_logger
|
8
7
|
|
9
8
|
log = create_logger(__name__)
|
@@ -18,8 +17,9 @@ class CodeParser(JanusParser):
|
|
18
17
|
pattern = rf"```[^\S\r\n]*(?:{self.language}[^\S\r\n]*)?\n?(.*?)\n*```"
|
19
18
|
code = re.search(pattern, text, re.DOTALL)
|
20
19
|
if code is None:
|
21
|
-
raise
|
22
|
-
|
20
|
+
raise JanusParserException(
|
21
|
+
text,
|
22
|
+
"Code not find code between triple square brackets",
|
23
23
|
)
|
24
24
|
return str(code.group(1))
|
25
25
|
|
janus/parsers/doc_parser.py
CHANGED
@@ -8,7 +8,7 @@ from langchain_core.messages import BaseMessage
|
|
8
8
|
from langchain_core.pydantic_v1 import BaseModel, Field
|
9
9
|
|
10
10
|
from janus.language.block import CodeBlock
|
11
|
-
from janus.parsers.parser import JanusParser
|
11
|
+
from janus.parsers.parser import JanusParser, JanusParserException
|
12
12
|
from janus.utils.logger import create_logger
|
13
13
|
|
14
14
|
log = create_logger(__name__)
|
@@ -86,7 +86,7 @@ class MultiDocumentationParser(JanusParser, PydanticOutputParser):
|
|
86
86
|
return str(self.__class__.name)
|
87
87
|
|
88
88
|
|
89
|
-
class
|
89
|
+
class ClozeDocumentationParser(JanusParser):
|
90
90
|
expected_keys: set[str]
|
91
91
|
|
92
92
|
def __init__(self):
|
@@ -107,11 +107,12 @@ class MadlibsDocumentationParser(JanusParser):
|
|
107
107
|
obj = parse_json_markdown(text)
|
108
108
|
except json.JSONDecodeError as e:
|
109
109
|
log.debug(f"Invalid JSON object. Output:\n{text}")
|
110
|
-
raise
|
110
|
+
raise JanusParserException(text, f"Got invalid JSON object. Error: {e}")
|
111
111
|
|
112
112
|
if not isinstance(obj, dict):
|
113
|
-
raise
|
114
|
-
|
113
|
+
raise JanusParserException(
|
114
|
+
text,
|
115
|
+
f"Got invalid return object. Expected a dictionary, but got {type(obj)}",
|
115
116
|
)
|
116
117
|
|
117
118
|
seen_keys = set(obj.keys())
|
@@ -122,9 +123,10 @@ class MadlibsDocumentationParser(JanusParser):
|
|
122
123
|
if invalid_keys:
|
123
124
|
log.debug(f"Invalid keys: {invalid_keys}")
|
124
125
|
log.debug(f"Missing keys: {missing_keys}")
|
125
|
-
raise
|
126
|
+
raise JanusParserException(
|
127
|
+
text,
|
126
128
|
f"Got invalid return object. Missing the following expected "
|
127
|
-
f"keys: {missing_keys}"
|
129
|
+
f"keys: {missing_keys}",
|
128
130
|
)
|
129
131
|
|
130
132
|
for key in invalid_keys:
|
@@ -132,9 +134,10 @@ class MadlibsDocumentationParser(JanusParser):
|
|
132
134
|
|
133
135
|
for value in obj.values():
|
134
136
|
if not isinstance(value, str):
|
135
|
-
raise
|
137
|
+
raise JanusParserException(
|
138
|
+
text,
|
136
139
|
f"Got invalid return object. Expected all string values,"
|
137
|
-
f' but got type "{type(value)}"'
|
140
|
+
f' but got type "{type(value)}"',
|
138
141
|
)
|
139
142
|
|
140
143
|
return json.dumps(obj)
|
janus/parsers/parser.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
from langchain.schema.output_parser import BaseOutputParser
|
2
|
+
from langchain_core.exceptions import OutputParserException
|
2
3
|
from langchain_core.messages import BaseMessage
|
3
4
|
from langchain_core.output_parsers import StrOutputParser
|
4
5
|
|
@@ -49,3 +50,9 @@ class GenericParser(JanusParser, StrOutputParser):
|
|
49
50
|
|
50
51
|
def get_format_instructions(self) -> str:
|
51
52
|
return "Output should be a string"
|
53
|
+
|
54
|
+
|
55
|
+
class JanusParserException(OutputParserException):
|
56
|
+
def __init__(self, unparsed_output, *args, **kwargs):
|
57
|
+
self.unparsed_output = unparsed_output
|
58
|
+
super().__init__(*args, **kwargs)
|
@@ -9,7 +9,7 @@ from langchain_core.messages import BaseMessage
|
|
9
9
|
from langchain_core.pydantic_v1 import BaseModel, Field
|
10
10
|
|
11
11
|
from janus.language.block import CodeBlock
|
12
|
-
from janus.parsers.parser import JanusParser
|
12
|
+
from janus.parsers.parser import JanusParser, JanusParserException
|
13
13
|
from janus.utils.logger import create_logger
|
14
14
|
|
15
15
|
log = create_logger(__name__)
|
@@ -97,6 +97,7 @@ class PartitionParser(JanusParser, PydanticOutputParser):
|
|
97
97
|
def parse(self, text: str | BaseMessage) -> str:
|
98
98
|
if isinstance(text, BaseMessage):
|
99
99
|
text = str(text.content)
|
100
|
+
original_text = text
|
100
101
|
|
101
102
|
# Strip everything outside the JSON object
|
102
103
|
begin, end = text.find("["), text.rfind("]")
|
@@ -122,7 +123,7 @@ class PartitionParser(JanusParser, PydanticOutputParser):
|
|
122
123
|
+ ", ".join(invalid_splits)
|
123
124
|
)
|
124
125
|
log.warning(err_msg)
|
125
|
-
raise
|
126
|
+
raise JanusParserException(original_text, err_msg)
|
126
127
|
|
127
128
|
# Map line IDs to indices (so they can be sorted and lines indexed)
|
128
129
|
index_to_line_id = {0: "START", None: "END"}
|
@@ -160,9 +161,10 @@ class PartitionParser(JanusParser, PydanticOutputParser):
|
|
160
161
|
"Oversized chunks:\n"
|
161
162
|
+ "\n#############\n".join(chunk for _, chunk, _ in data)
|
162
163
|
)
|
163
|
-
raise
|
164
|
+
raise JanusParserException(
|
165
|
+
original_text,
|
164
166
|
f"The following segments are too long and must be "
|
165
|
-
f"further subdivided:\n{problem_points}"
|
167
|
+
f"further subdivided:\n{problem_points}",
|
166
168
|
)
|
167
169
|
|
168
170
|
return "\n<JANUS_PARTITION>\n".join(chunks)
|
janus/parsers/reqs_parser.py
CHANGED
@@ -2,10 +2,9 @@ import json
|
|
2
2
|
import re
|
3
3
|
|
4
4
|
from langchain.output_parsers.json import parse_json_markdown
|
5
|
-
from langchain_core.exceptions import OutputParserException
|
6
5
|
from langchain_core.messages import BaseMessage
|
7
6
|
|
8
|
-
from janus.parsers.parser import JanusParser
|
7
|
+
from janus.parsers.parser import JanusParser, JanusParserException
|
9
8
|
from janus.utils.logger import create_logger
|
10
9
|
|
11
10
|
log = create_logger(__name__)
|
@@ -20,6 +19,7 @@ class RequirementsParser(JanusParser):
|
|
20
19
|
def parse(self, text: str | BaseMessage) -> str:
|
21
20
|
if isinstance(text, BaseMessage):
|
22
21
|
text = str(text.content)
|
22
|
+
original_text = text
|
23
23
|
|
24
24
|
# TODO: This is an incorrect implementation (lstrip and rstrip take character
|
25
25
|
# lists and strip any instances of those characters, not the full str)
|
@@ -30,11 +30,14 @@ class RequirementsParser(JanusParser):
|
|
30
30
|
obj = parse_json_markdown(text)
|
31
31
|
except json.JSONDecodeError as e:
|
32
32
|
log.debug(f"Invalid JSON object. Output:\n{text}")
|
33
|
-
raise
|
33
|
+
raise JanusParserException(
|
34
|
+
original_text, f"Got invalid JSON object. Error: {e}"
|
35
|
+
)
|
34
36
|
|
35
37
|
if not isinstance(obj, dict):
|
36
|
-
raise
|
37
|
-
|
38
|
+
raise JanusParserException(
|
39
|
+
original_text,
|
40
|
+
f"Got invalid return object. Expected a dictionary, but got {type(obj)}",
|
38
41
|
)
|
39
42
|
return json.dumps(obj)
|
40
43
|
|
janus/parsers/uml.py
CHANGED
@@ -3,10 +3,10 @@ import subprocess # nosec
|
|
3
3
|
from pathlib import Path
|
4
4
|
from tempfile import NamedTemporaryFile
|
5
5
|
|
6
|
-
from langchain_core.exceptions import OutputParserException
|
7
6
|
from langchain_core.messages import BaseMessage
|
8
7
|
|
9
8
|
from janus.parsers.code_parser import CodeParser
|
9
|
+
from janus.parsers.parser import JanusParserException
|
10
10
|
from janus.utils.logger import create_logger
|
11
11
|
|
12
12
|
log = create_logger(__name__)
|
@@ -14,6 +14,7 @@ log = create_logger(__name__)
|
|
14
14
|
|
15
15
|
class UMLSyntaxParser(CodeParser):
|
16
16
|
def _check_plantuml(self, text: str) -> None:
|
17
|
+
original_text = text
|
17
18
|
# Leading newlines can break the parser, remove them
|
18
19
|
text = text.replace("\\n", "\n").strip()
|
19
20
|
|
@@ -43,7 +44,7 @@ class UMLSyntaxParser(CodeParser):
|
|
43
44
|
log.error(err_txt)
|
44
45
|
raise Exception(err_txt)
|
45
46
|
|
46
|
-
# Check for bad outputs, raise
|
47
|
+
# Check for bad outputs, raise JanusParserExceptions if so
|
47
48
|
if "Error" in stderr or "Error" in stdout:
|
48
49
|
err_txt = "Recieved UML parsing error(s)."
|
49
50
|
|
@@ -64,7 +65,7 @@ class UMLSyntaxParser(CodeParser):
|
|
64
65
|
err_txt += f"\nError located at line {i} must be fixed:\n"
|
65
66
|
err_txt += "\n".join(err_lines)
|
66
67
|
log.warning(err_txt)
|
67
|
-
raise
|
68
|
+
raise JanusParserException(original_text, err_txt)
|
68
69
|
|
69
70
|
if "Warning" in stdout or "Warning" in stderr:
|
70
71
|
err_txt = "Recieved UML parsing warning (often due to missing PLANTUML)."
|
@@ -74,7 +75,7 @@ class UMLSyntaxParser(CodeParser):
|
|
74
75
|
err_txt += f"\nSTDOUT:\n```\n{stdout.strip()}\n```\n"
|
75
76
|
|
76
77
|
log.warning(err_txt)
|
77
|
-
raise
|
78
|
+
raise JanusParserException(original_text, err_txt)
|
78
79
|
|
79
80
|
def _get_error_lines(self, s: str) -> list[int]:
|
80
81
|
return [int(x.group(1)) for x in re.finditer(r"Error line (\d+) in file:", s)]
|
janus/prompts/prompt.py
CHANGED
@@ -23,7 +23,7 @@ TEXT_OUTPUT = []
|
|
23
23
|
# same language as the input, regardless of the `output-lang` argument.
|
24
24
|
SAME_OUTPUT = ["document_inline"]
|
25
25
|
|
26
|
-
JSON_OUTPUT = ["evaluate", "document", "
|
26
|
+
JSON_OUTPUT = ["evaluate", "document", "document_cloze", "requirements"]
|
27
27
|
|
28
28
|
# Directory containing Janus prompt template directories and files
|
29
29
|
JANUS_PROMPT_TEMPLATES_DIR = Path(__file__).parent / "templates"
|
@@ -109,7 +109,7 @@ class PromptEngine(ABC):
|
|
109
109
|
source_language = source_language.lower()
|
110
110
|
self.variables = dict(
|
111
111
|
SOURCE_LANGUAGE=source_language,
|
112
|
-
FILE_SUFFIX=LANGUAGES[source_language]["
|
112
|
+
FILE_SUFFIX=LANGUAGES[source_language]["suffixes"],
|
113
113
|
SOURCE_CODE_EXAMPLE=LANGUAGES[source_language]["example"],
|
114
114
|
)
|
115
115
|
if target_language is not None:
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Prompt Template Files
|
2
|
+
|
3
|
+
Janus supports defining custom prompts in text files.
|
4
|
+
|
5
|
+
```
|
6
|
+
directory_name/
|
7
|
+
system.txt
|
8
|
+
human.txt
|
9
|
+
variables.json (optional)
|
10
|
+
```
|
11
|
+
|
12
|
+
## Prompt templates
|
13
|
+
- `system.txt` contains text representing the system prompt template,
|
14
|
+
+ Ex. "Your purpose is to understand {SOURCE_LANGUAGE} code."
|
15
|
+
- `human.txt` contains text representing the human prompt template.
|
16
|
+
+ Ex. "Summarize the contents of the following {SOURCE_LANGUAGE} code in {written_language} sentences.
|
17
|
+
|
18
|
+
Both prompt templates can make use of f-string-style arguments, i.e. `{VARIABLE}`. Multiple lines are supported.
|
19
|
+
|
20
|
+
To reuse a prompt, say for the same system directive with differing output styles, create a symbolic link to the original file. For example:
|
21
|
+
`ln -s ../document/system.txt system.txt`
|
22
|
+
|
23
|
+
## Variables
|
24
|
+
- (Optional) `variables.json` contains a JSON object representing additional variables and their values used in the templates above, beyond what is provided to Janus via command-line arguments.
|
25
|
+
+ Ex.
|
26
|
+
```
|
27
|
+
{
|
28
|
+
"written_language": "Spanish"
|
29
|
+
}
|
30
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer named John and tasked with combining representations of code into a single representation.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Please fix the following output generated by a large language model.
|
2
|
+
Provide your corrected output in the same format as the original.
|
3
|
+
The large language model was given the following prompt in triple backticks:
|
4
|
+
```
|
5
|
+
{ORIGINAL_PROMPT}
|
6
|
+
```
|
7
|
+
and produced the following output:
|
8
|
+
```
|
9
|
+
{OUTPUT}
|
10
|
+
```
|
11
|
+
but received the following errors:
|
12
|
+
```
|
13
|
+
{ERRORS}
|
14
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer named John and tasked with fixing the output created by a large language model.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Generate a UML {DIAGRAM_TYPE} diagram using PLANTUML syntax that improves the readability of the following {SOURCE_LANGUAGE} code for a programmer.
|
2
|
+
In your output, make sure to reformat any {SOURCE_LANGUAGE} code that would break PLANTUML syntax rules.
|
3
|
+
Do not output any {SOURCE_LANGUAGE} code in the diagram.
|
4
|
+
Make sure to capture all relevant syntax, functions and branching in the source code.
|
5
|
+
Make sure to document all functions in the code
|
6
|
+
Here is the source code:
|
7
|
+
```
|
8
|
+
{SOURCE_CODE}
|
9
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer named John and tasked with creating PLANTUML documentation of {SOURCE_LANGUAGE} code.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Generate a UML {DIAGRAM_TYPE} diagram using PLANTUML syntax that improves the readability of the following {SOURCE_LANGUAGE} code for a programmer.
|
2
|
+
You are also provided with documentation for this code.
|
3
|
+
In your output, make sure to reformat any {SOURCE_LANGUAGE} code that would break PLANTUML syntax rules.
|
4
|
+
Do not output any {SOURCE_LANGUAGE} code in the diagram.
|
5
|
+
Make sure to capture all relevant syntax, functions and branching in the source code.
|
6
|
+
Make sure to document all functions in the code
|
7
|
+
Make sure to put the resultant PLANTUML code within triple backticks.
|
8
|
+
Here is the code documentation:
|
9
|
+
```
|
10
|
+
{DOCUMENTATION}
|
11
|
+
```
|
12
|
+
Here is the source code:
|
13
|
+
```
|
14
|
+
{SOURCE_CODE}
|
15
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer named John and tasked with creating PLANTUML documentation of {SOURCE_LANGUAGE} code.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Please explain the {SOURCE_LANGUAGE} code section below. Your response should be in plain text with no delimiters. It should contain a natural language description of the code's intended functionality; do not describe the execution step-by-step, simply explain the overall purpose. This description should be roughly one paragraph in length; multiple paragraphs may be used if and only if the code is particularly complex or has multiple independent functions.
|
2
|
+
After this description, describe the expected initial state and/or inputs, the expected terminal state and/or outputs, and any potential exceptions that might arise in the code's execution.
|
3
|
+
|
4
|
+
It is vital that you do not include any other context, questions, or text of any kind, other than the documentation for this piece of code. You should include all of the fields described above, and those fields only.
|
5
|
+
|
6
|
+
Here is the code:
|
7
|
+
|
8
|
+
```
|
9
|
+
{SOURCE_CODE}
|
10
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer tasked with documenting {SOURCE_LANGUAGE} code.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
The {SOURCE_LANGUAGE} code provided below has had its comments replaced by either `<INLINE_COMMENT #>` (for single-line comments) or `<BLOCK_COMMENT #>` (for multiple consecutive lines of comments), where `#` takes the place of an 8-character alphanumeric ID. You are to write replacement comments based on the source code.
|
2
|
+
|
3
|
+
Return a JSON-formatted string where the keys are the alphanumeric IDs and the values are the comments that should be inserted in the code. Be sure to include comments for all placeholders present in the input. Do not provide any other commentary, do not write any code or additional comments.
|
4
|
+
|
5
|
+
Example input: ```{EXAMPLE_INPUT}```
|
6
|
+
Example output: ```{EXAMPLE_OUTPUT}```
|
7
|
+
|
8
|
+
Please provide comments for the following code:
|
9
|
+
```
|
10
|
+
{SOURCE_CODE}
|
11
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a senior software engineer tasked with documenting {SOURCE_LANGUAGE} code.
|
@@ -0,0 +1,4 @@
|
|
1
|
+
{
|
2
|
+
"EXAMPLE_INPUT": " I '$D(CATLIST) Q\n ; <INLINE_COMMENT 14c59f05>\n S CAT=\"\"\n F S CAT=$O(CATLIST(CAT)) Q:CAT=\"\" D\n . S LDATE=$O(CATLIST(CAT,\"\"),-1)\n .; <INLINE_COMMENT 97a39adf>\n . S DATE=\"\"\n . F S DATE=$O(CATLIST(CAT,DATE)) Q:DATE=LDATE D\n .. S WCR=\"\"\n .. F S WCR=$O(CATLIST(CAT,DATE,WCR)) Q:WCR=\"\" D\n ... S FI=\"\"\n ... F S FI=$O(CATLIST(CAT,DATE,WCR,FI)) Q:FI=\"\" D\n .... S FIEVAL(FI)=0\n ....; <INLINE_COMMENT 4fd34837>\n .... S IND=0\n .... F S IND=+$O(FIEVAL(FI,IND)) Q:IND=0 S FIEVAL(FI,IND)=0\n .; <BLOCK_COMMENT 997ec49a>\n . S (NTRUE,WCR)=0\n . F S WCR=$O(CATLIST(CAT,LDATE,WCR)) Q:WCR=\"\" D\n .. S FI=\"\"\n .. F S FI=$O(CATLIST(CAT,LDATE,WCR,FI)) Q:FI=\"\" D\n ... I NTRUE=0 D Q\n ....; <INLINE_COMMENT 3ac32fb5>\n .... S (IND,NTRUE)=1\n .... F S IND=+$O(FIEVAL(FI,IND)) Q:IND=0 S FIEVAL(FI,IND)=0\n ... S FIEVAL(FI)=0\n ...; <INLINE_COMMENT d04a8fdf>\n ... S IND=0\n ... F S IND=+$O(FIEVAL(FI,IND)) Q:IND=0 S FIEVAL(FI,IND)=0\n Q\n",
|
3
|
+
"EXAMPLE_OUTPUT": "{\n \"14c59f05\": \";Only the most recent HF in a category can be true.\",\n \"97a39adf\": \";For each category set all but the most recent HF false.\",\n \"4fd34837\": \";If there are multiple occurrences set them all false.\",\n \"997ec49a\": \" .;\\n .;If there is more than on HF on the most recent date then only the\\n .;one with the highest WCR can be true. The highest possible WCR is 1.\\n .;Set all with lower WCRs false.\\n .;If the most recent health factor has multiple occurrences only\\n .;the first occurrence can be true.\",\n \"3ac32fb5\": \";If there are multiple sub-occurrences set them all false.\"\n}"
|
4
|
+
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
{
|
2
|
+
"EXAMPLE_INPUT": "***********************************************************************\n* <BLOCK_COMMENT d8453f99>\n***********************************************************************\nZUIDSTCK AMODE 31\nZUIDSTCK RMODE 31\nZUIDSTCK CSECT\n STM R14,R12,12(R13) <INLINE_COMMENT b2cc1643>\n L R1,0(R1) <INLINE_COMMENT a315e5ca>\n USING DSA,R1 <INLINE_COMMENT 3155f463>\n STCKE EISTOD <INLINE_COMMENT d84b5ebf>\n\n LM R14,R12,12(R13) <INLINE_COMMENT a79a8e65>\n XR R15,R15 <INLINE_COMMENT 47ad1b4d>\n BR R14 <INLINE_COMMENT eb971719>\n",
|
3
|
+
"EXAMPLE_OUTPUT": "{\n \"d8453f99\": \"Control Section\",\n \"b2cc1643\": \"Save registers\",\n \"a315e5ca\": \"Load parameter address\",\n \"3155f463\": \"... tell assembler\",\n \"d84b5ebf\": \"Save STCKE TOD\",\n \"a79a8e65\": \"Load Registers\",\n \"47ad1b4d\": \"Clear R15 (RC)\",\n \"eb971719\": \"Return to calling program\"\n}"
|
4
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Please add inline comments to the {SOURCE_LANGUAGE} code
|
2
|
+
provided below in triple backticks.
|
3
|
+
|
4
|
+
```
|
5
|
+
{SOURCE_CODE}
|
6
|
+
```
|
7
|
+
|
8
|
+
Keep all source code in the output.
|
9
|
+
|
10
|
+
Please add a comment at the top of the file which summarizes
|
11
|
+
the purpose of the code.
|
12
|
+
|
13
|
+
Please add comments to functions which summarize their functionality.
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Below is a snippet of {SOURCE_LANGUAGE} code to use as reference for the following task:
|
2
|
+
```
|
3
|
+
{SOURCE_CODE}
|
4
|
+
```
|
5
|
+
|
6
|
+
Given the above code and the list of requirements I will soon supply, please evaluate each requirement individually based on the following criteria:
|
7
|
+
|
8
|
+
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.
|
9
|
+
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.
|
10
|
+
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.
|
11
|
+
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.
|
12
|
+
C5 - Singular: The stakeholder need or requirement statement should state a single capability, characteristic, constraint, or quality factor.
|
13
|
+
C6 - Feasible: The need or requirement can be realized within entity constraints (for example: cost, schedule, technical, legal, ethical, safety) with acceptable risk.
|
14
|
+
C7 - Verifiable: The requirement statement is structured and worded such that its realization can be verified to the approving authority’s satisfaction.
|
15
|
+
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.
|
16
|
+
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.
|
17
|
+
|
18
|
+
For each and every requirement below, you must indicate whether they "pass" or "fail" each of the above criteria. Briefly explain your reasoning before providing each pass/fail.
|
19
|
+
|
20
|
+
Your response should be formatted as a list of JSON objects, with each object corresponding to one requirement. Each object should include 10 keys: `requirement_id`, `C1`, `C2`, ..., `C9`. `requirement_id` should have a string value that holds the 8-character UUID associated with the requirement. The other four values should each be a JSON object with two keys: `reasoning` (a clear explanation of why the criterion is passed or failed) and a `score` (the literal string "pass" or "fail").
|
21
|
+
|
22
|
+
Be discerning in your evaluation; only very high-quality requirements should pass all criteria. Be a hard grader. If a requirement fails a criterion, be thorough and detailed in your explanation of why.
|
23
|
+
|
24
|
+
Below is an example output for a snippet of code with three labeled requirements:
|
25
|
+
```
|
26
|
+
{EXAMPLE_OUTPUT}
|
27
|
+
```
|
28
|
+
|
29
|
+
Here are the requirements that you are to evaluate:
|
30
|
+
{REQUIREMENTS}
|
31
|
+
|
32
|
+
Don't forget to include your final scores in JSON format!
|
@@ -0,0 +1 @@
|
|
1
|
+
You are a software quality engineer, your job is to evaluate requirments according to a rubric.
|
@@ -0,0 +1,3 @@
|
|
1
|
+
{
|
2
|
+
"EXAMPLE_OUTPUT": "[\n {\n \"requirement_id\": \"c3caa172\",\n \"requirement\": \"The UserID field must be followed by a comma (,) as a field separator.\",\n \"C1\": {\n \"reasoning\": \"This defines an essential characteristic of the data structure.\",\n \"score\": \"pass\"\n },\n \"C2\": {\n \"reasoning\": \"The detail provided is appropriate for the software's data structure level.\",\n \"score\": \"pass\"\n },\n \"C3\": {\n \"reasoning\": \"The statement is clear and unambiguous.\",\n \"score\": \"pass\"\n },\n \"C4\": {\n \"reasoning\": \"The requirement sufficiently describes the separator without needing additional information.\",\n \"score\": \"pass\"\n },\n \"C5\": {\n \"reasoning\": \"The requirement states a single characteristic.\",\n \"score\": \"pass\"\n },\n \"C6\": {\n \"reasoning\": \"Including a field separator is feasible.\",\n \"score\": \"pass\"\n },\n \"C7\": {\n \"reasoning\": \"The requirement can be verified by checking the data structure.\",\n \"score\": \"pass\"\n },\n \"C8\": {\n \"reasoning\": \"The requirement accurately represents the need for a separator.\",\n \"score\": \"pass\"\n },\n \"C9\": {\n \"reasoning\": \"The requirement conforms to standard pattern and style.\",\n \"score\": \"pass\"\n }\n },\n {\n \"requirement_id\": \"fab48ab9\",\n \"requirement\": \"The software must handle web communication parameters, including buffer addresses and lengths for web receive operations, query string management, and basic and query mode service program identifiers.\",\n \"C1\": {\n \"reasoning\": \"Defines essential capabilities for handling web communication parameters.\",\n \"score\": \"pass\"\n },\n \"C2\": {\n \"reasoning\": \"Appropriate detail for software handling web communication.\",\n \"score\": \"pass\"\n },\n \"C3\": {\n \"reasoning\": \"Clear and unambiguous about what the software must handle.\",\n \"score\": \"pass\"\n },\n \"C4\": {\n \"reasoning\": \"Sufficiently describes the necessary capabilities without needing additional information.\",\n \"score\": \"pass\"\n },\n \"C5\": {\n \"reasoning\": \"States multiple capabilities related to web communication parameters.\",\n \"score\": \"fail\"\n },\n \"C6\": {\n \"reasoning\": \"Feasible to implement within typical software constraints.\",\n \"score\": \"pass\"\n },\n \"C7\": {\n \"reasoning\": \"Verification can be done through testing the software's handling of these parameters.\",\n \"score\": \"pass\"\n },\n \"C8\": {\n \"reasoning\": \"Accurately represents the need for handling web communication parameters.\",\n \"score\": \"pass\"\n },\n \"C9\": {\n \"reasoning\": \"Conforms to standard requirement style and structure.\",\n \"score\": \"pass\"\n }\n }\n]"
|
3
|
+
}
|