Author:ptrace Comitter:ptrace Date:2026-08-02 02:56:11 UTC

update: ml_grammar

diff --git a/python/ml_grammar.py b/python/ml_grammar.py index 3bc1d44..88cddef 100644 --- a/python/ml_grammar.py +++ b/python/ml_grammar.py @@ -1,11 +1,13 @@ #!/bin/python from dataclasses import dataclass from shutil import get_terminal_size from sys import exit, argv from subprocess import run from pathlib import Path MODEL_PATH        = "/drives/drive3/ML/LLama-3-8B-grammar-correction/Llama-3-8B-grammar-correction.Q6_K.gguf" TEMPERATURE       = 0.1  # Recommendation by model TOKENS_TO_PREDICT = 256 @@ -14,24 +16,34 @@ GPU_LAYERS        = 99   # Also possible: "auto", "all" LLAMA_TOOL = "llama-completion" SYSTEM_PROMPT = "Correct the grammar and spelling of the following text. " \                 "Show only the corrected sentences." SYSTEM_PROMPT = "Correct the grammar and spelling of the following text, " \                 "but omit what was already correct." @dataclass class Args:     fp: string = ""     debug: bool = False def main():     path_maybe = arg_parse()     fp = Path(path_maybe)     fp_abs = fp.absolute()     fp_abs = ""     parsed_args = arg_parse()     if not fp.exists():         print("Error: File path does not exist:", fp_abs)         exit(1)     if not parsed_args.debug:         fp = Path(parsed_args.fp)         fp_abs = fp.absolute()         if not fp.exists():             print("Error: File path does not exist:", fp_abs)             exit(1)     print("Loading ...")     run_model(fp_abs)     run_model(parsed_args, fp_abs) def arg_parse():     parsed_args = Args()     args = argv     max_args = 2 @@ -39,10 +51,15 @@ def arg_parse():         print("Insufficient arguments. Expecting a path to a text file")         exit(1)     return args[1]     if args[1] == "-debug":         parsed_args.debug = True     else:         parsed_args.fp = args[1]     return parsed_args def run_model(fp): def run_model(parsed_args, fp):     cmd = [         LLAMA_TOOL,         "-m", MODEL_PATH, @@ -55,6 +72,10 @@ def run_model(fp):         "-f", fp,     ]     if parsed_args.debug:         print(" ".join(cmd))         return     try:         result = run(cmd, capture_output=True, text=True)     except FileNotFoundError: @@ -85,4 +106,3 @@ if __name__ == "__main__":         print("Terminated by user.")         exit(1)