Ethosoft-Math 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ethosoft_math/__init__.py +30 -0
- ethosoft_math/__main__.py +3 -0
- ethosoft_math/cli.py +56 -0
- ethosoft_math/converter.py +1418 -0
- ethosoft_math/protocol.py +858 -0
- ethosoft_math-0.1.0.dist-info/METADATA +72 -0
- ethosoft_math-0.1.0.dist-info/RECORD +10 -0
- ethosoft_math-0.1.0.dist-info/WHEEL +5 -0
- ethosoft_math-0.1.0.dist-info/entry_points.txt +2 -0
- ethosoft_math-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Ethosoft-Math: matematik cozumlerini dogrulanmis tool-use izlerine ceviren kutuphane.
|
|
2
|
+
|
|
3
|
+
>>> import ethosoft_math as em
|
|
4
|
+
>>> em.convert("Toplam 3 + 4 = 7 elma.")
|
|
5
|
+
'Toplam <tool_call>add(3, 4)</tool_call><tool_result>7</tool_result> elma.'
|
|
6
|
+
>>> em.execute("add(3, 4)")
|
|
7
|
+
'7'
|
|
8
|
+
"""
|
|
9
|
+
from .protocol import ( # noqa: F401
|
|
10
|
+
CALL_OPEN, CALL_CLOSE, RES_OPEN, RES_CLOSE, REG, ToolError,
|
|
11
|
+
execute, parse_call, run, render_protocol_md,
|
|
12
|
+
)
|
|
13
|
+
from .converter import convert_text, verify_converted # noqa: F401
|
|
14
|
+
|
|
15
|
+
__version__ = "0.1.0"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def convert(text: str, aggressive: bool = False) -> str:
|
|
19
|
+
"""Metindeki dogrulanabilir hesaplari arac cagrilarina cevirir; sadece metni dondurur."""
|
|
20
|
+
return convert_text(text, aggressive=aggressive)[0]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def verify(text: str):
|
|
24
|
+
"""Metindeki her arac cagrisini yeniden calistirir; (toplam, hatali) dondurur."""
|
|
25
|
+
return verify_converted(text)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def functions():
|
|
29
|
+
"""Protokoldeki fonksiyonlar: {ad: {cat, sig, doc}}"""
|
|
30
|
+
return {k: {"cat": v["cat"], "sig": v["sig"], "doc": v["doc"]} for k, v in REG.items()}
|
ethosoft_math/cli.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from . import __version__, convert_text, execute, render_protocol_md, verify_converted
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _convert_file(args):
|
|
9
|
+
n = n_conv = n_calls = n_bad = 0
|
|
10
|
+
with open(args.input, encoding="utf-8") as fin, open(args.output, "w", encoding="utf-8") as fout:
|
|
11
|
+
for line in fin:
|
|
12
|
+
line = line.strip()
|
|
13
|
+
if not line:
|
|
14
|
+
continue
|
|
15
|
+
row = json.loads(line)
|
|
16
|
+
text = row.get(args.field)
|
|
17
|
+
if isinstance(text, str):
|
|
18
|
+
out, _ = convert_text(text, aggressive=args.aggressive)
|
|
19
|
+
calls, bad = verify_converted(out)
|
|
20
|
+
row[args.out_field or args.field] = out
|
|
21
|
+
row["tool_calls"] = calls
|
|
22
|
+
n_calls += calls
|
|
23
|
+
n_bad += bad
|
|
24
|
+
n_conv += calls > 0
|
|
25
|
+
n += 1
|
|
26
|
+
fout.write(json.dumps(row, ensure_ascii=False) + "\n")
|
|
27
|
+
print(f"satir={n} aracli={n_conv} ({100 * n_conv / max(1, n):.1f}%) cagri={n_calls} hatali={n_bad}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main(argv=None):
|
|
31
|
+
ap = argparse.ArgumentParser(prog="ethosoft-math", description="Matematik tool-use protokolu")
|
|
32
|
+
ap.add_argument("--version", action="version", version=__version__)
|
|
33
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
34
|
+
|
|
35
|
+
c = sub.add_parser("convert", help="jsonl dosyasindaki bir alani tool-use bicimine cevir")
|
|
36
|
+
c.add_argument("input")
|
|
37
|
+
c.add_argument("output")
|
|
38
|
+
c.add_argument("--field", default="solution")
|
|
39
|
+
c.add_argument("--out-field", default=None)
|
|
40
|
+
c.add_argument("--aggressive", action="store_true", help="'=' olmayan sayisal islemleri de cevir")
|
|
41
|
+
c.set_defaults(func=_convert_file)
|
|
42
|
+
|
|
43
|
+
p = sub.add_parser("protocol", help="protokol dokumanini yazdir (Markdown)")
|
|
44
|
+
p.set_defaults(func=lambda a: print(render_protocol_md()))
|
|
45
|
+
|
|
46
|
+
e = sub.add_parser("exec", help="tek bir arac cagrisini calistir, orn: add(3, 4)")
|
|
47
|
+
e.add_argument("call")
|
|
48
|
+
e.set_defaults(func=lambda a: print(execute(a.call)))
|
|
49
|
+
|
|
50
|
+
args = ap.parse_args(argv)
|
|
51
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
52
|
+
args.func(args)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
main()
|