janus-llm 3.5.3__py3-none-any.whl → 4.0.0__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/cli.py +66 -47
- janus/converter/converter.py +111 -142
- janus/converter/diagram.py +21 -109
- janus/converter/translate.py +1 -1
- janus/language/alc/_tests/test_alc.py +1 -1
- janus/language/alc/alc.py +15 -10
- janus/language/binary/_tests/test_binary.py +1 -1
- janus/language/binary/binary.py +2 -2
- janus/language/mumps/_tests/test_mumps.py +1 -1
- janus/language/mumps/mumps.py +2 -3
- janus/language/splitter.py +2 -2
- janus/language/treesitter/_tests/test_treesitter.py +1 -1
- janus/language/treesitter/treesitter.py +2 -2
- janus/llm/model_callbacks.py +13 -0
- janus/llm/models_info.py +111 -71
- janus/metrics/metric.py +15 -14
- janus/parsers/uml.py +60 -23
- janus/refiners/refiner.py +106 -64
- janus/retrievers/retriever.py +42 -0
- {janus_llm-3.5.3.dist-info → janus_llm-4.0.0.dist-info}/METADATA +1 -1
- {janus_llm-3.5.3.dist-info → janus_llm-4.0.0.dist-info}/RECORD +25 -25
- janus/parsers/refiner_parser.py +0 -46
- {janus_llm-3.5.3.dist-info → janus_llm-4.0.0.dist-info}/LICENSE +0 -0
- {janus_llm-3.5.3.dist-info → janus_llm-4.0.0.dist-info}/WHEEL +0 -0
- {janus_llm-3.5.3.dist-info → janus_llm-4.0.0.dist-info}/entry_points.txt +0 -0
janus/metrics/metric.py
CHANGED
@@ -8,6 +8,7 @@ import typer
|
|
8
8
|
from typing_extensions import Annotated
|
9
9
|
|
10
10
|
from janus.llm import load_model
|
11
|
+
from janus.llm.model_callbacks import COST_PER_1K_TOKENS
|
11
12
|
from janus.metrics.cli import evaluate
|
12
13
|
from janus.metrics.file_pairing import FILE_PAIRING_METHODS
|
13
14
|
from janus.metrics.splitting import SPLITTING_METHODS
|
@@ -135,7 +136,7 @@ def metric(
|
|
135
136
|
**kwargs,
|
136
137
|
):
|
137
138
|
out = []
|
138
|
-
llm
|
139
|
+
llm = load_model(llm_name)
|
139
140
|
if json_file_name is not None:
|
140
141
|
with open(json_file_name, "r") as f:
|
141
142
|
json_obj = json.load(f)
|
@@ -171,8 +172,8 @@ def metric(
|
|
171
172
|
out_file=out_file,
|
172
173
|
lang=language,
|
173
174
|
llm=llm,
|
174
|
-
token_limit=token_limit,
|
175
|
-
model_cost=
|
175
|
+
token_limit=llm.token_limit,
|
176
|
+
model_cost=COST_PER_1K_TOKENS[llm.model_id],
|
176
177
|
)
|
177
178
|
else:
|
178
179
|
raise ValueError(
|
@@ -187,8 +188,8 @@ def metric(
|
|
187
188
|
progress,
|
188
189
|
language,
|
189
190
|
llm,
|
190
|
-
token_limit,
|
191
|
-
|
191
|
+
llm.token_limit,
|
192
|
+
COST_PER_1K_TOKENS[llm.model_id],
|
192
193
|
*args,
|
193
194
|
**kwargs,
|
194
195
|
)
|
@@ -199,8 +200,8 @@ def metric(
|
|
199
200
|
progress,
|
200
201
|
language,
|
201
202
|
llm,
|
202
|
-
token_limit,
|
203
|
-
|
203
|
+
llm.token_limit,
|
204
|
+
COST_PER_1K_TOKENS[llm.model_id],
|
204
205
|
*args,
|
205
206
|
**kwargs,
|
206
207
|
)
|
@@ -296,7 +297,7 @@ def metric(
|
|
296
297
|
*args,
|
297
298
|
**kwargs,
|
298
299
|
):
|
299
|
-
llm
|
300
|
+
llm = load_model(llm_name)
|
300
301
|
if json_file_name is not None:
|
301
302
|
with open(json_file_name, "r") as f:
|
302
303
|
json_obj = json.load(f)
|
@@ -328,8 +329,8 @@ def metric(
|
|
328
329
|
out_file=out_file,
|
329
330
|
lang=language,
|
330
331
|
llm=llm,
|
331
|
-
token_limit=token_limit,
|
332
|
-
model_cost=
|
332
|
+
token_limit=llm.token_limit,
|
333
|
+
model_cost=COST_PER_1K_TOKENS[llm.model_id],
|
333
334
|
)
|
334
335
|
else:
|
335
336
|
raise ValueError(
|
@@ -344,8 +345,8 @@ def metric(
|
|
344
345
|
progress,
|
345
346
|
language,
|
346
347
|
llm,
|
347
|
-
token_limit,
|
348
|
-
|
348
|
+
llm.token_limit,
|
349
|
+
COST_PER_1K_TOKENS[llm.model_id],
|
349
350
|
*args,
|
350
351
|
**kwargs,
|
351
352
|
)
|
@@ -356,8 +357,8 @@ def metric(
|
|
356
357
|
progress,
|
357
358
|
language,
|
358
359
|
llm,
|
359
|
-
token_limit,
|
360
|
-
|
360
|
+
llm.token_limit,
|
361
|
+
COST_PER_1K_TOKENS[llm.model_id],
|
361
362
|
*args,
|
362
363
|
**kwargs,
|
363
364
|
)
|
janus/parsers/uml.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import re
|
2
2
|
import subprocess # nosec
|
3
3
|
from pathlib import Path
|
4
|
-
from
|
4
|
+
from tempfile import NamedTemporaryFile
|
5
5
|
|
6
6
|
from langchain_core.exceptions import OutputParserException
|
7
7
|
from langchain_core.messages import BaseMessage
|
@@ -13,39 +13,76 @@ log = create_logger(__name__)
|
|
13
13
|
|
14
14
|
|
15
15
|
class UMLSyntaxParser(CodeParser):
|
16
|
-
def
|
17
|
-
#
|
18
|
-
|
16
|
+
def _check_plantuml(self, text: str) -> None:
|
17
|
+
# Leading newlines can break the parser, remove them
|
18
|
+
text = text.replace("\\n", "\n").strip()
|
19
|
+
|
20
|
+
# Write the text to a temporary file (automatically deleted)
|
21
|
+
file = NamedTemporaryFile()
|
22
|
+
fname = file.name
|
23
|
+
with open(fname, "w") as fin:
|
24
|
+
fin.write(text)
|
25
|
+
|
19
26
|
try:
|
20
27
|
plantuml_path = Path.home().expanduser() / ".janus/lib/plantuml.jar"
|
28
|
+
# NOTE: running subprocess with shell=False, added nosec to
|
29
|
+
# label that we know risk exists
|
21
30
|
res = subprocess.run(
|
22
|
-
["java", "-jar", plantuml_path,
|
31
|
+
["java", "-jar", plantuml_path, fname],
|
23
32
|
stdout=subprocess.PIPE,
|
24
33
|
stderr=subprocess.PIPE,
|
25
34
|
) # nosec
|
26
35
|
stdout = res.stdout.decode("utf-8")
|
27
36
|
stderr = res.stderr.decode("utf-8")
|
28
37
|
except FileNotFoundError:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
err_txt = (
|
39
|
+
"Plant UML executable not found. Either choose a different parser"
|
40
|
+
" or install with `bash scripts/install_plantuml.sh`. Java and"
|
41
|
+
" graphviz are dependencies for the tool, they must also be installed."
|
42
|
+
)
|
43
|
+
log.error(err_txt)
|
44
|
+
raise Exception(err_txt)
|
45
|
+
|
46
|
+
# Check for bad outputs, raise OutputParserExceptions if so
|
47
|
+
if "Error" in stderr or "Error" in stdout:
|
48
|
+
err_txt = "Recieved UML parsing error(s)."
|
49
|
+
|
50
|
+
line_nos = self._get_error_lines(stderr) + self._get_error_lines(stdout)
|
51
|
+
lines = text.split("\n")
|
52
|
+
for i in line_nos:
|
53
|
+
i0 = max(0, i - 3)
|
54
|
+
i1 = min(len(lines) - 1, i + 2)
|
55
|
+
err_lines = [
|
56
|
+
f"> {lines[j]}" if j == i - 1 else f" {lines[j]}"
|
57
|
+
for j in range(i0, i1)
|
58
|
+
]
|
59
|
+
if i0:
|
60
|
+
err_lines.insert(0, " ...")
|
61
|
+
if i1 < (len(lines) - 1):
|
62
|
+
err_lines.append(" ...")
|
33
63
|
|
34
|
-
|
35
|
-
|
64
|
+
err_txt += f"\nError located at line {i} must be fixed:\n"
|
65
|
+
err_txt += "\n".join(err_lines)
|
66
|
+
log.warning(err_txt)
|
67
|
+
raise OutputParserException(err_txt)
|
68
|
+
|
69
|
+
if "Warning" in stdout or "Warning" in stderr:
|
70
|
+
err_txt = "Recieved UML parsing warning (often due to missing PLANTUML)."
|
71
|
+
if stderr:
|
72
|
+
err_txt += f"\nSTDERR:\n```\n{stderr.strip()}\n```\n"
|
73
|
+
if stdout:
|
74
|
+
err_txt += f"\nSTDOUT:\n```\n{stdout.strip()}\n```\n"
|
75
|
+
|
76
|
+
log.warning(err_txt)
|
77
|
+
raise OutputParserException(err_txt)
|
78
|
+
|
79
|
+
def _get_error_lines(self, s: str) -> list[int]:
|
80
|
+
return [int(x.group(1)) for x in re.finditer(r"Error line (\d+) in file:", s)]
|
81
|
+
|
82
|
+
def _get_warns(self, s: str) -> list[str]:
|
83
|
+
return [x.group() for x in re.finditer(r"Warning: (.*)\n", s)]
|
36
84
|
|
37
85
|
def parse(self, text: str | BaseMessage) -> str:
|
38
86
|
text = super().parse(text)
|
39
|
-
|
40
|
-
if not janus_path.exists():
|
41
|
-
janus_path.mkdir()
|
42
|
-
temp_file_path = janus_path / "tmp.txt"
|
43
|
-
with open(temp_file_path, "w") as f:
|
44
|
-
f.write(text)
|
45
|
-
uml_std_out, uml_std_err = self._get_uml_output(temp_file_path)
|
46
|
-
uml_errs = self._get_errs(uml_std_out) + self._get_errs(uml_std_err)
|
47
|
-
if len(uml_errs) > 0:
|
48
|
-
raise OutputParserException(
|
49
|
-
"Error: Received UML Errors:\n" + "\n".join(uml_errs)
|
50
|
-
)
|
87
|
+
self._check_plantuml(text)
|
51
88
|
return text
|
janus/refiners/refiner.py
CHANGED
@@ -1,73 +1,115 @@
|
|
1
|
-
from
|
1
|
+
from typing import Any
|
2
2
|
|
3
|
-
from
|
3
|
+
from langchain.output_parsers import RetryWithErrorOutputParser
|
4
|
+
from langchain_core.output_parsers import StrOutputParser
|
5
|
+
from langchain_core.prompt_values import PromptValue
|
6
|
+
from langchain_core.runnables import RunnableSerializable
|
4
7
|
|
8
|
+
from janus.llm.models_info import MODEL_PROMPT_ENGINES, JanusModel
|
9
|
+
from janus.parsers.parser import JanusParser
|
10
|
+
from janus.utils.logger import create_logger
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
**
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
original_output: origial output of llm
|
20
|
-
errors: list of errors detected by parser
|
21
|
-
|
22
|
-
Returns:
|
23
|
-
Tuple of new prompt and prompt arguments
|
24
|
-
"""
|
12
|
+
log = create_logger(__name__)
|
13
|
+
|
14
|
+
|
15
|
+
class JanusRefiner(JanusParser):
|
16
|
+
parser: JanusParser
|
17
|
+
|
18
|
+
def parse_runnable(self, input: dict[str, Any]) -> Any:
|
19
|
+
return self.parse_completion(**input)
|
20
|
+
|
21
|
+
def parse_completion(self, completion: str, **kwargs) -> Any:
|
22
|
+
return self.parser.parse(completion)
|
23
|
+
|
24
|
+
def parse(self, text: str) -> str:
|
25
25
|
raise NotImplementedError
|
26
26
|
|
27
27
|
|
28
|
-
class
|
28
|
+
class FixParserExceptions(JanusRefiner, RetryWithErrorOutputParser):
|
29
|
+
def __init__(self, llm: JanusModel, parser: JanusParser, max_retries: int):
|
30
|
+
retry_prompt = MODEL_PROMPT_ENGINES[llm.model_id](
|
31
|
+
source_language="text",
|
32
|
+
prompt_template="refinement/fix_exceptions",
|
33
|
+
).prompt
|
34
|
+
chain = retry_prompt | llm | StrOutputParser()
|
35
|
+
RetryWithErrorOutputParser.__init__(
|
36
|
+
self, parser=parser, retry_chain=chain, max_retries=max_retries
|
37
|
+
)
|
38
|
+
|
39
|
+
def parse_completion(
|
40
|
+
self, completion: str, prompt_value: PromptValue, **kwargs
|
41
|
+
) -> Any:
|
42
|
+
return self.parse_with_prompt(completion, prompt_value=prompt_value)
|
43
|
+
|
44
|
+
|
45
|
+
class ReflectionRefiner(JanusRefiner):
|
46
|
+
max_retries: int
|
47
|
+
reflection_chain: RunnableSerializable
|
48
|
+
revision_chain: RunnableSerializable
|
49
|
+
|
29
50
|
def __init__(
|
30
51
|
self,
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
llm: JanusModel,
|
53
|
+
parser: JanusParser,
|
54
|
+
max_retries: int,
|
55
|
+
prompt_template_name: str = "refinement/reflection",
|
56
|
+
):
|
57
|
+
reflection_prompt = MODEL_PROMPT_ENGINES[llm.model_id](
|
58
|
+
source_language="text",
|
59
|
+
prompt_template=prompt_template_name,
|
60
|
+
).prompt
|
61
|
+
revision_prompt = MODEL_PROMPT_ENGINES[llm.model_id](
|
62
|
+
source_language="text",
|
63
|
+
prompt_template="refinement/revision",
|
64
|
+
).prompt
|
65
|
+
|
66
|
+
reflection_chain = reflection_prompt | llm | StrOutputParser()
|
67
|
+
revision_chain = revision_prompt | llm | StrOutputParser()
|
68
|
+
super().__init__(
|
69
|
+
reflection_chain=reflection_chain,
|
70
|
+
revision_chain=revision_chain,
|
71
|
+
parser=parser,
|
72
|
+
max_retries=max_retries,
|
73
|
+
)
|
74
|
+
|
75
|
+
def parse_completion(
|
76
|
+
self, completion: str, prompt_value: PromptValue, **kwargs
|
77
|
+
) -> Any:
|
78
|
+
for retry_number in range(self.max_retries):
|
79
|
+
reflection = self.reflection_chain.invoke(
|
80
|
+
dict(
|
81
|
+
prompt=prompt_value.to_string(),
|
82
|
+
completion=completion,
|
83
|
+
)
|
84
|
+
)
|
85
|
+
if reflection.strip() == "LGTM":
|
86
|
+
return self.parser.parse(completion)
|
87
|
+
if not retry_number:
|
88
|
+
log.info(f"Completion:\n{completion}")
|
89
|
+
log.info(f"Reflection:\n{reflection}")
|
90
|
+
completion = self.revision_chain.invoke(
|
91
|
+
dict(
|
92
|
+
prompt=prompt_value.to_string(),
|
93
|
+
completion=completion,
|
94
|
+
reflection=reflection,
|
95
|
+
)
|
96
|
+
)
|
97
|
+
log.info(f"Revision:\n{completion}")
|
98
|
+
|
99
|
+
return self.parser.parse(completion)
|
100
|
+
|
101
|
+
|
102
|
+
class HallucinationRefiner(ReflectionRefiner):
|
103
|
+
def __init__(self, **kwargs):
|
104
|
+
super().__init__(
|
105
|
+
prompt_template_name="refinement/hallucination",
|
106
|
+
**kwargs,
|
67
107
|
)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
108
|
+
|
109
|
+
|
110
|
+
REFINERS = dict(
|
111
|
+
none=JanusRefiner,
|
112
|
+
parser=FixParserExceptions,
|
113
|
+
reflection=ReflectionRefiner,
|
114
|
+
hallucination=HallucinationRefiner,
|
115
|
+
)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
from langchain_core.retrievers import BaseRetriever
|
2
|
+
from langchain_core.runnables import Runnable, RunnableConfig
|
3
|
+
|
4
|
+
from janus.language.block import CodeBlock
|
5
|
+
|
6
|
+
|
7
|
+
class JanusRetriever(Runnable):
|
8
|
+
def __init__(self) -> None:
|
9
|
+
super().__init__()
|
10
|
+
|
11
|
+
def invoke(
|
12
|
+
self, input: CodeBlock, config: RunnableConfig | None = None, **kwargs
|
13
|
+
) -> dict:
|
14
|
+
kwargs.update(context=self.get_context(input))
|
15
|
+
return kwargs
|
16
|
+
|
17
|
+
def get_context(self, code_block: CodeBlock) -> str:
|
18
|
+
return ""
|
19
|
+
|
20
|
+
|
21
|
+
class ActiveUsingsRetriever(JanusRetriever):
|
22
|
+
def get_context(self, code_block: CodeBlock) -> str:
|
23
|
+
context = "\n".join(
|
24
|
+
f"{context_tag}: {context}"
|
25
|
+
for context_tag, context in code_block.context_tags.items()
|
26
|
+
)
|
27
|
+
return f"You may use the following additional context: {context}"
|
28
|
+
|
29
|
+
|
30
|
+
class TextSearchRetriever(JanusRetriever):
|
31
|
+
retriever: BaseRetriever
|
32
|
+
|
33
|
+
def __init__(self, retriever: BaseRetriever):
|
34
|
+
super().__init__()
|
35
|
+
self.retriever = retriever
|
36
|
+
|
37
|
+
def get_context(self, code_block: CodeBlock) -> str:
|
38
|
+
if code_block.text is None:
|
39
|
+
return ""
|
40
|
+
docs = self.retriever.invoke(code_block.text)
|
41
|
+
context = "\n\n".join(doc.page_content for doc in docs)
|
42
|
+
return f"You may use the following additional context: {context}"
|
@@ -1,19 +1,19 @@
|
|
1
|
-
janus/__init__.py,sha256=
|
1
|
+
janus/__init__.py,sha256=gL7W9Io7zembI938nQAbVjAY107vRS0acvWfDDrEVyg,361
|
2
2
|
janus/__main__.py,sha256=lEkpNtLVPtFo8ySDZeXJ_NXDHb0GVdZFPWB4gD4RPS8,64
|
3
3
|
janus/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
janus/_tests/conftest.py,sha256=V7uW-oq3YbFiRPvrq15YoVVrA1n_83pjgiyTZ-IUGW8,963
|
5
5
|
janus/_tests/test_cli.py,sha256=6ef7h11bg4i7Q6L1-r0ZdcY7YrH4n472kvDiA03T4c8,4275
|
6
|
-
janus/cli.py,sha256=
|
6
|
+
janus/cli.py,sha256=lX8GzLOXan8nqjy_dx-3EF4qaLOVTsyDqp0OLBZctw0,38177
|
7
7
|
janus/converter/__init__.py,sha256=U2EOMcCykiC0ZqhorNefOP_04hOF18qhYoPKrVp1Vrk,345
|
8
8
|
janus/converter/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
janus/converter/_tests/test_translate.py,sha256=yzcFEGc_z8QmBBBmC9dZnfL9tT8CD1rkpc8Hz44Jp4c,5631
|
10
10
|
janus/converter/aggregator.py,sha256=MuAXMKmq6PuUo_w6ljyiuDn81Gk2dN-Ci7FVeLc6vhs,1966
|
11
|
-
janus/converter/converter.py,sha256=
|
12
|
-
janus/converter/diagram.py,sha256
|
11
|
+
janus/converter/converter.py,sha256=HWw-a4j-Qq0AWDyyk6cMVOwYjJeXxa3bvs9OOlKo_KI,25965
|
12
|
+
janus/converter/diagram.py,sha256=-wktVBPrSBgNIQfHIfa2bJNg6L9CYJQgrr9-xU8DFPw,1646
|
13
13
|
janus/converter/document.py,sha256=qNt2UncMheUBadXCFHGq74tqCrvZub5DCgZpd3Qa54o,4564
|
14
14
|
janus/converter/evaluate.py,sha256=APWQUY3gjAXqkJkPzvj0UA4wPK3Cv9QSJLM-YK9t-ng,476
|
15
15
|
janus/converter/requirements.py,sha256=9tvQ40FZJtG8niIFn45gPQCgKKHVPPoFLinBv6RAqO4,2027
|
16
|
-
janus/converter/translate.py,sha256=
|
16
|
+
janus/converter/translate.py,sha256=S1DPZdmX9Vrn_sJPcobvXmhmS8U53yl5cRXjsmXPtas,4246
|
17
17
|
janus/embedding/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
18
|
janus/embedding/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
janus/embedding/_tests/test_collections.py,sha256=llg-JSuRRFhKkHFiWWSHEWV3iaT6Lwue0lp2tEml9io,2668
|
@@ -29,20 +29,20 @@ janus/language/_tests/test_combine.py,sha256=sjVVPUg4LYkAmazXGUw_S1xPrzWm67_0tCx
|
|
29
29
|
janus/language/_tests/test_splitter.py,sha256=Hqexa39LLEXlK3ZUw7Zot4PUIACvye2vkq0Jaox0T10,373
|
30
30
|
janus/language/alc/__init__.py,sha256=j7vOMGhT1Vri6p8dsjSaY-fkO5uFn0sJ0nrNGGvcizM,42
|
31
31
|
janus/language/alc/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
32
|
-
janus/language/alc/_tests/test_alc.py,sha256=
|
33
|
-
janus/language/alc/alc.py,sha256=
|
32
|
+
janus/language/alc/_tests/test_alc.py,sha256=jrvZCsz3uvbq6pqTKmymWNDgb20HHs69tj9TRbx69aM,1018
|
33
|
+
janus/language/alc/alc.py,sha256=fKZDtbeLXiJ2e8t-eWSjeAW6WCMCTn2Fw7_jxvMPdNc,6863
|
34
34
|
janus/language/binary/__init__.py,sha256=AlNAe12ZA366kcGSrQ1FJyOdbwxFqGBFkYR2K6yL818,51
|
35
35
|
janus/language/binary/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
36
|
-
janus/language/binary/_tests/test_binary.py,sha256=
|
37
|
-
janus/language/binary/binary.py,sha256=
|
36
|
+
janus/language/binary/_tests/test_binary.py,sha256=cIKIxjj6kIY3rcxLwqUPESP9bxWrHqMHx9TNuICgfeQ,1724
|
37
|
+
janus/language/binary/binary.py,sha256=PHsVa8jcM7sW9aTboGRWXj6ewQznz0kVPNWtP4B9YPU,6555
|
38
38
|
janus/language/binary/reveng/decompile_script.py,sha256=veW51oJzuO-4UD3Er062jXZ_FYtTFo9OCkl82Z2xr6A,2182
|
39
39
|
janus/language/block.py,sha256=2rjAYUosHFfWRgLnzf50uAgTMST4Md9Kx6JrlUfEfX4,9398
|
40
40
|
janus/language/combine.py,sha256=Wtve06fa-_Wjv_V5RIf1Nfmg0UxcOEtFNj4vVHpSNbo,2940
|
41
41
|
janus/language/file.py,sha256=jy-cReAoI6F97TXR5bbhPyt8XyUZCdFYnVboubDA_y4,571
|
42
42
|
janus/language/mumps/__init__.py,sha256=-Ou_wJ-JgHezfp1dub2_qCYNiK9wO-zo2MlqxM9qiwE,48
|
43
43
|
janus/language/mumps/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
|
-
janus/language/mumps/_tests/test_mumps.py,sha256=
|
45
|
-
janus/language/mumps/mumps.py,sha256
|
44
|
+
janus/language/mumps/_tests/test_mumps.py,sha256=YxnQkobM9VR_Zow2oLaZxZs8bPipvbFWSza4zlWbMi8,1010
|
45
|
+
janus/language/mumps/mumps.py,sha256=-eyafFN9IeUQMU7yEsICJDrDb5tkYV_EydqFCjcuM_o,7381
|
46
46
|
janus/language/mumps/patterns.py,sha256=fLbgEnPYYggfqTnBwXf0XbnlU3g_bM4tsmO1YHYv5Jw,2313
|
47
47
|
janus/language/naive/__init__.py,sha256=_Gq4inONyVYxe8WLB59d_69kqGbtF40BGKoJPnK4tZ0,258
|
48
48
|
janus/language/naive/basic_splitter.py,sha256=RM9pJK2YkHfb6_EFEV-dh_rLqkjS6v0cn3ASPf8A6Fg,459
|
@@ -51,14 +51,14 @@ janus/language/naive/registry.py,sha256=8YQX1q0IdAm7t69-oC_00I-vfkdRnHuX-OD3KEjE
|
|
51
51
|
janus/language/naive/simple_ast.py,sha256=YzeUJomVsnttJc8tI9eDROb2Hx9Vm9XKmOnLEp3TkzI,3112
|
52
52
|
janus/language/naive/tag_splitter.py,sha256=IXWMn9tBVUGAtzvQi89GhoZ6g7fPXk5MzO0kMCr2mb0,2045
|
53
53
|
janus/language/node.py,sha256=baoYFtapwBQqBtUN6EvHFYRkbR-EcEw1b3fQvH9zIAM,204
|
54
|
-
janus/language/splitter.py,sha256=
|
54
|
+
janus/language/splitter.py,sha256=pYvDhGAYDDP7E4CZeNn76I6zVnHMNj6gTFUegKXyRPk,17005
|
55
55
|
janus/language/treesitter/__init__.py,sha256=mUliw7ZJLZ8NkJKyUQMSoUV82hYXE0HvLHrEdGPJF4Q,43
|
56
56
|
janus/language/treesitter/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
57
|
-
janus/language/treesitter/_tests/test_treesitter.py,sha256=
|
58
|
-
janus/language/treesitter/treesitter.py,sha256=
|
57
|
+
janus/language/treesitter/_tests/test_treesitter.py,sha256=fmr_mFSja7vaCVu0TVyLDua3A94jMjY4AqSC5NqnOdQ,2179
|
58
|
+
janus/language/treesitter/treesitter.py,sha256=q7fqfFxt7QsqM6tE39uqutRMsOfEgBd3omv7zVZSEOc,7517
|
59
59
|
janus/llm/__init__.py,sha256=TKLYvnsWKWfxMucy-lCLQ-4bkN9ENotJZDywDEQmrKg,45
|
60
|
-
janus/llm/model_callbacks.py,sha256=
|
61
|
-
janus/llm/models_info.py,sha256=
|
60
|
+
janus/llm/model_callbacks.py,sha256=iaLsnHt2LcMgHPW4ouQdot9ahOHUOBCtydpVaag1Zak,7564
|
61
|
+
janus/llm/models_info.py,sha256=GxAr7iwjcvM7RWUe1I6AuOqiYA-Wnc4Mr8DEVBq91KA,9662
|
62
62
|
janus/metrics/__init__.py,sha256=AsxtZJUzZiXJPr2ehPPltuYP-ddechjg6X85WZUO7mA,241
|
63
63
|
janus/metrics/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
64
64
|
janus/metrics/_tests/reference.py,sha256=hiaJPP9CXkvFBV_wL-gOe_BzELTw0nvB6uCxhxtIiE8,13
|
@@ -77,7 +77,7 @@ janus/metrics/cli.py,sha256=Duuw2RF47Z-t1pal0cg3L_-N_91rx29krirqtIwjYLY,157
|
|
77
77
|
janus/metrics/complexity_metrics.py,sha256=9sHxa9tY9IgdFC4grCmDSuu8Nkphm_FWbTecxgW78go,6574
|
78
78
|
janus/metrics/file_pairing.py,sha256=b0848gbDTqKVge-uGiujtHdsgcbkpJ04nWF2ul_gbCw,3749
|
79
79
|
janus/metrics/llm_metrics.py,sha256=nzzJMSnoZfgtzzltjoCu1l4-Qwuycd-V3z17AtStYdY,5700
|
80
|
-
janus/metrics/metric.py,sha256=
|
80
|
+
janus/metrics/metric.py,sha256=ZQXz2LLXA3_WW6BluF8Q2LdJKYVWZLYmhO4Ai116ZPY,17168
|
81
81
|
janus/metrics/reading.py,sha256=RyOSebENWPGD1m_-QfKM9v2vfNAQVkiZ2Oyynb2HrVI,3253
|
82
82
|
janus/metrics/rouge_score.py,sha256=XnA2ABAceIzzA_9rIYDaMtyD4pphHxXVwxaYvMcqZWE,2878
|
83
83
|
janus/metrics/similarity.py,sha256=NKd-m8hMB27i1_1CQkG5o7HrAK2wTr89B21Y36kqHiE,1630
|
@@ -89,12 +89,12 @@ janus/parsers/code_parser.py,sha256=3l0HfzgrvJuiwk779s9ZsgUl3xbp1nE1qZxh8aDYRBI,
|
|
89
89
|
janus/parsers/doc_parser.py,sha256=0pUsNZ9hKQLjIi8L8BgkOBHQZ_EGoFLHrBQ4hoDkjSw,5862
|
90
90
|
janus/parsers/eval_parser.py,sha256=Gjh6aTZgpYd2ASJUEPMo4LpCL00cBmbOqc4KM3hy8x8,2922
|
91
91
|
janus/parsers/parser.py,sha256=y6VV64bgVidf-oEFla3I--_28tnJsPBc6QUD_SkbfSE,1614
|
92
|
-
janus/parsers/refiner_parser.py,sha256=W7ecDX7j6N-uWtRBYFD1EiEzDpDQws16nrVFzyArzf8,1632
|
93
92
|
janus/parsers/reqs_parser.py,sha256=uRQC41Iqp22GjIvakb5UKv70UWHkcOTbOVl_RDnipYw,2438
|
94
|
-
janus/parsers/uml.py,sha256=
|
93
|
+
janus/parsers/uml.py,sha256=SwaoG9QrHKQP8rSxlf3qu_rp7OMQqYSmLgDYBapOa9M,3379
|
95
94
|
janus/prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
96
95
|
janus/prompts/prompt.py,sha256=3796YXIzzIec9b0iUzd8VZlq-AdQbzq8qUGXLy4KH-0,10586
|
97
|
-
janus/refiners/refiner.py,sha256=
|
96
|
+
janus/refiners/refiner.py,sha256=lKAVS9Nszx8aO7hLB0xzdMmUNfhX7K5SaXwcit2QBHs,3774
|
97
|
+
janus/retrievers/retriever.py,sha256=WzsYn329GbyJfmJ9KyU9yiYdhLkuS6WPKTKoHx5fBYQ,1339
|
98
98
|
janus/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
99
99
|
janus/utils/_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
100
100
|
janus/utils/_tests/test_logger.py,sha256=jkkvrCTKwsFCsZtmyuvc-WJ0rC7LJi2Z91sIe4IiKzA,2209
|
@@ -102,8 +102,8 @@ janus/utils/_tests/test_progress.py,sha256=Rs_u5PiGjP-L-o6C1fhwfE1ig8jYu9Xo9s4p8
|
|
102
102
|
janus/utils/enums.py,sha256=AoilbdiYyMvY2Mp0AM4xlbLSELfut2XMwhIM1S_msP4,27610
|
103
103
|
janus/utils/logger.py,sha256=KZeuaMAnlSZCsj4yL0P6N-JzZwpxXygzACWfdZFeuek,2337
|
104
104
|
janus/utils/progress.py,sha256=PIpcQec7SrhsfqB25LHj2CDDkfm9umZx90d9LZnAx6k,1469
|
105
|
-
janus_llm-
|
106
|
-
janus_llm-
|
107
|
-
janus_llm-
|
108
|
-
janus_llm-
|
109
|
-
janus_llm-
|
105
|
+
janus_llm-4.0.0.dist-info/LICENSE,sha256=_j0st0a-HB6MRbP3_BW3PUqpS16v54luyy-1zVyl8NU,10789
|
106
|
+
janus_llm-4.0.0.dist-info/METADATA,sha256=LiMK2QiE9nzhufdK43eDYll_CbSThm2Wjit7bpG3XdE,4184
|
107
|
+
janus_llm-4.0.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
108
|
+
janus_llm-4.0.0.dist-info/entry_points.txt,sha256=OGhQwzj6pvXp79B0SaBD5apGekCu7Dwe9fZZT_TZ544,39
|
109
|
+
janus_llm-4.0.0.dist-info/RECORD,,
|
janus/parsers/refiner_parser.py
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
from langchain_core.exceptions import OutputParserException
|
2
|
-
from langchain_core.language_models import BaseLanguageModel
|
3
|
-
from langchain_core.messages import BaseMessage
|
4
|
-
from langchain_core.output_parsers import BaseOutputParser
|
5
|
-
|
6
|
-
from janus.parsers.parser import JanusParser
|
7
|
-
from janus.refiners.refiner import Refiner
|
8
|
-
|
9
|
-
|
10
|
-
class RefinerParser(JanusParser):
|
11
|
-
"""Parser for performing refinement with a refiner
|
12
|
-
|
13
|
-
Properties:
|
14
|
-
llm: the language model to use
|
15
|
-
parser: the parser to use for parsing llm output
|
16
|
-
initial_prompt: initial prompt used to generate output
|
17
|
-
refiner: refiner that gives new subsequent prompts
|
18
|
-
max_retires: maximum number of times to attempt refining
|
19
|
-
"""
|
20
|
-
|
21
|
-
class Config:
|
22
|
-
arbitrary_types_allowed = True
|
23
|
-
|
24
|
-
llm: BaseLanguageModel
|
25
|
-
parser: BaseOutputParser
|
26
|
-
initial_prompt: str
|
27
|
-
refiner: Refiner
|
28
|
-
max_retries: int
|
29
|
-
|
30
|
-
def parse(self, text: str | BaseMessage) -> str:
|
31
|
-
last_prompt = self.initial_prompt
|
32
|
-
for _ in range(self.max_retries):
|
33
|
-
try:
|
34
|
-
return self.parser.parse(text)
|
35
|
-
except OutputParserException as oe:
|
36
|
-
err = str(oe)
|
37
|
-
new_prompt, prompt_arguments = self.refiner.refine(
|
38
|
-
self.initial_prompt, last_prompt, text, err
|
39
|
-
)
|
40
|
-
new_chain = new_prompt | self.llm
|
41
|
-
text = new_chain.invoke(prompt_arguments)
|
42
|
-
last_prompt = new_prompt.format(**prompt_arguments)
|
43
|
-
|
44
|
-
raise OutputParserException(
|
45
|
-
f"Error: unable to correct output after {self.max_retries} attempts"
|
46
|
-
)
|
File without changes
|
File without changes
|
File without changes
|