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/refiners/refiner.py
CHANGED
@@ -3,6 +3,7 @@ from typing import Any
|
|
3
3
|
|
4
4
|
from langchain.output_parsers import RetryWithErrorOutputParser
|
5
5
|
from langchain_core.exceptions import OutputParserException
|
6
|
+
from langchain_core.messages import AIMessage
|
6
7
|
from langchain_core.output_parsers import StrOutputParser
|
7
8
|
from langchain_core.prompt_values import PromptValue
|
8
9
|
from langchain_core.runnables import RunnableSerializable
|
@@ -108,7 +109,7 @@ class ReflectionRefiner(JanusRefiner):
|
|
108
109
|
def parse_completion(
|
109
110
|
self, completion: str, prompt_value: PromptValue, **kwargs
|
110
111
|
) -> Any:
|
111
|
-
log.
|
112
|
+
log.debug(f"Reflection Prompt: {self.reflection_prompt_name}")
|
112
113
|
for retry_number in range(self.max_retries):
|
113
114
|
reflection = self.reflection_chain.invoke(
|
114
115
|
dict(
|
@@ -119,8 +120,117 @@ class ReflectionRefiner(JanusRefiner):
|
|
119
120
|
if re.search(r"\bLGTM\b", reflection) is not None:
|
120
121
|
return self.parser.parse(completion)
|
121
122
|
if not retry_number:
|
122
|
-
log.
|
123
|
-
log.
|
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}")
|
124
234
|
completion = self.revision_chain.invoke(
|
125
235
|
dict(
|
126
236
|
prompt=prompt_value.to_string(),
|
@@ -128,7 +238,6 @@ class ReflectionRefiner(JanusRefiner):
|
|
128
238
|
reflection=reflection,
|
129
239
|
)
|
130
240
|
)
|
131
|
-
log.info(f"Revision:\n{completion}")
|
132
241
|
|
133
242
|
return self.parser.parse(completion)
|
134
243
|
|