From bdb2cee332de13709568d0354b82f58171f6e23d Mon Sep 17 00:00:00 2001 From: unworriedsafari Date: Thu, 29 Feb 2024 07:54:35 +0000 Subject: [PATCH] v1.2.0 --- README.md | 32 ++++++++++++++++++++++---------- mill.py | 20 +++++++++++++++++--- mill_cgi.py | 6 +++--- mill_cli.py | 10 +++++----- mill_lang_markdown.py | 6 ++++-- mill_llm_llama_cpp.py | 5 ++++- mill_readme.py | 5 +++-- 7 files changed, 58 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b6d66b6..c36ed01 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # README -`mill.py v1.1.2` +`mill.py v1.2.0` Markdown interface for [llama.cpp](//github.com/ggerganov/llama.cpp). @@ -23,7 +23,8 @@ Developed and tested on Linux. I believe it could also work on Windows or Mac. 6. Streams output 7. Runs in a CLI environment as well as a CGI environment 8. Reads input document from `stdin`, writes output document to `stdout` -9. Lets you add support for any other language or LLM through Python modules +9. Lets you add support for any other language (i.e. other than Markdown) or + LLM engine through Python modules ## Example @@ -168,8 +169,8 @@ cat document.md | ssh \ 2>/dev/null ``` -Use the command-line arguments to select a different language or LLM. You can -use `-h` for a usage description. +Use the command-line arguments to select a different language or LLM engine. +You can use `-h` for a usage description. ## CGI install + usage @@ -206,11 +207,13 @@ it to send your phone's clipboard directly to the CGI tool and copy the HTTP response automatically back to the clipboard. Use the `language` and `llm_engine` query-string parameters to select a -different language or LLM. +different language or LLM engine. ## Markdown tutorial +This section describes the Markdown language module of `mill.py`. + `mill.py` is controlled with variables embedded in the Markdown document. In general, variables take the form @@ -230,7 +233,7 @@ sense. The value of a block with only a variable name is the empty string. Variables are either syntax variables or LLM variables. The distinction is made based on the variable type contained in the info string. Syntax variables have type `mill` and are handled directly by `mill.py` while LLM variables have -other types and are passed on to the LLM module. +other types and are passed on to the LLM-engine module. Syntax variables and LLM variables exist in two different namespaces. The namespace is implied by the variable type. If the `reset` flag is given, then @@ -309,7 +312,7 @@ There are three different variable types for LLM variables: The first type simply assigns the value to the name. -For some 'LLM engines' (like `llama.cpp`), it's useful to pass arguments via a +For some LLM engines (like `llama.cpp`), it's useful to pass arguments via a file. This can be done using the second and third variable types. For example, you can pass a grammar via either `--grammar` or `--grammar-file`. However, grammars can contain tokens that `mill.py` does not know how to shell-escape. @@ -338,6 +341,9 @@ newline that ends the block is excluded. ## `llama.cpp` tutorial +This section describes the `llama.cpp` LLM-engine module of `mill.py`. + + ### LLM variables `suppress eos` @@ -364,7 +370,7 @@ Using these variables results in an error. ### Environment variables Apart from LLM variables, there are also a few environment variables that -influence the behavior of `mill.py`. +influence the behavior of the `llama.cpp` module. `MILL_LLAMACPP_MAIN` @@ -414,10 +420,13 @@ To add support for another language: 6. When using the CGI interface, pass the `language=` query-string parameter. +If the environment variable `MILL_DEFAULT_LANGUAGE` is set to ``, +`mill.py` uses the language by default. -## Adding support for other LLMs -Adding support for another LLM is similar to adding support for another +## Adding support for other LLM engines + +Adding support for another LLM engine is similar to adding support for another language: 1. Create a new Python module named `mill_llm_` where all @@ -430,6 +439,9 @@ language: 6. When using the CGI interface, pass the `llm_engine=` query-string parameter. +If the environment variable `MILL_DEFAULT_LLM` is set to ``, `mill.py` +uses the LLM engine by default. + ## Adding example documentation diff --git a/mill.py b/mill.py index 78a3f1b..826a6c9 100644 --- a/mill.py +++ b/mill.py @@ -28,10 +28,13 @@ To add support for another language: 6. When using the CGI interface, pass the `language=` query-string parameter. +If the environment variable `MILL_DEFAULT_LANGUAGE` is set to ``, +`mill.py` uses the language by default. -## Adding support for other LLMs -Adding support for another LLM is similar to adding support for another +## Adding support for other LLM engines + +Adding support for another LLM engine is similar to adding support for another language: 1. Create a new Python module named `mill_llm_` where all @@ -44,6 +47,9 @@ language: 6. When using the CGI interface, pass the `llm_engine=` query-string parameter. +If the environment variable `MILL_DEFAULT_LLM` is set to ``, `mill.py` +uses the LLM engine by default. + ## Adding example documentation @@ -61,7 +67,15 @@ the `runnable_example` variable is to have some text that can be executed by `mill.py`. It should turn the README into an executable document. """ -import importlib, re +import importlib, os, re + + +def default_language(): + return os.environ.get('MILL_DEFAULT_LANGUAGE', 'markdown') + + +def default_llm_engine(): + return os.environ.get('MILL_DEFAULT_LLM', 'llama.cpp') def load_module(name): diff --git a/mill_cgi.py b/mill_cgi.py index 0f524f1..b84b808 100644 --- a/mill_cgi.py +++ b/mill_cgi.py @@ -51,7 +51,7 @@ it to send your phone's clipboard directly to the CGI tool and copy the HTTP response automatically back to the clipboard. Use the `language` and `llm_engine` query-string parameters to select a -different language or LLM. +different language or LLM engine. """ import contextlib, io, mill, mill_readme, os, sys, urllib.parse @@ -66,8 +66,8 @@ if __name__ == '__main__': args = urllib.parse.parse_qs(os.environ.get('QUERY_STRING','')) - language = args.get('language', 'markdown') - llm_engine = args.get('llm_engine', 'llama.cpp') + language = args.get('language', mill.default_language()) + llm_engine = args.get('llm_engine', mill.default_llm_engine()) if os.environ['REQUEST_METHOD'].upper() == 'GET': print('Content-type: text/markdown') diff --git a/mill_cli.py b/mill_cli.py index 9793332..9d70db0 100644 --- a/mill_cli.py +++ b/mill_cli.py @@ -40,9 +40,8 @@ cat document.md | ssh \ 2>/dev/null ``` -Use the command-line arguments to select a different language or LLM. You can -use `-h` for a usage description. -""" +Use the command-line arguments to select a different language or LLM engine. +You can use `-h` for a usage description. """ import argparse, mill, mill_readme, sys @@ -53,9 +52,10 @@ if __name__ == '__main__': argparser.add_argument('-r', '--readme', action='store_true', help='display the README') - argparser.add_argument('-l', '--language', default='markdown', + argparser.add_argument('-l', '--language', default=mill.default_language(), help='language') - argparser.add_argument('-e', '--llm-engine', default='llama.cpp', + argparser.add_argument('-e', '--llm-engine', + default=mill.default_llm_engine(), help='LLM engine') args = argparser.parse_args() diff --git a/mill_lang_markdown.py b/mill_lang_markdown.py index 1137d86..80c146a 100644 --- a/mill_lang_markdown.py +++ b/mill_lang_markdown.py @@ -17,6 +17,8 @@ """ ## Markdown tutorial +This section describes the Markdown language module of `mill.py`. + `mill.py` is controlled with variables embedded in the Markdown document. In general, variables take the form @@ -36,7 +38,7 @@ sense. The value of a block with only a variable name is the empty string. Variables are either syntax variables or LLM variables. The distinction is made based on the variable type contained in the info string. Syntax variables have type `mill` and are handled directly by `mill.py` while LLM variables have -other types and are passed on to the LLM module. +other types and are passed on to the LLM-engine module. Syntax variables and LLM variables exist in two different namespaces. The namespace is implied by the variable type. If the `reset` flag is given, then @@ -115,7 +117,7 @@ There are three different variable types for LLM variables: The first type simply assigns the value to the name. -For some 'LLM engines' (like `llama.cpp`), it's useful to pass arguments via a +For some LLM engines (like `llama.cpp`), it's useful to pass arguments via a file. This can be done using the second and third variable types. For example, you can pass a grammar via either `--grammar` or `--grammar-file`. However, grammars can contain tokens that `mill.py` does not know how to shell-escape. diff --git a/mill_llm_llama_cpp.py b/mill_llm_llama_cpp.py index 2a534da..0ef44dd 100644 --- a/mill_llm_llama_cpp.py +++ b/mill_llm_llama_cpp.py @@ -17,6 +17,9 @@ """ ## `llama.cpp` tutorial +This section describes the `llama.cpp` LLM-engine module of `mill.py`. + + ### LLM variables `suppress eos` @@ -43,7 +46,7 @@ Using these variables results in an error. ### Environment variables Apart from LLM variables, there are also a few environment variables that -influence the behavior of `mill.py`. +influence the behavior of the `llama.cpp` module. `MILL_LLAMACPP_MAIN` diff --git a/mill_readme.py b/mill_readme.py index 27f2c58..48ac67a 100644 --- a/mill_readme.py +++ b/mill_readme.py @@ -17,7 +17,7 @@ """ # README -`mill.py v1.1.2` +`mill.py v1.2.0` Markdown interface for [llama.cpp](//github.com/ggerganov/llama.cpp). @@ -40,7 +40,8 @@ Developed and tested on Linux. I believe it could also work on Windows or Mac. 6. Streams output 7. Runs in a CLI environment as well as a CGI environment 8. Reads input document from `stdin`, writes output document to `stdout` -9. Lets you add support for any other language or LLM through Python modules +9. Lets you add support for any other language (i.e. other than Markdown) or + LLM engine through Python modules """ import mill, mill_cgi, mill_cli