mill.py/mill_readme.py

87 lines
2.5 KiB
Python

# mill.py, Markdown interface for llama.cpp
# Copyright (C) 2024 unworriedsafari <unworriedsafari@tilde.club>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>
"""
# README
`mill.py v1.2.0`
Markdown interface for [llama.cpp](//github.com/ggerganov/llama.cpp).
## Requirements
1. [Python 3.x](//python.org) (tested on `3.11`)
2. [llama.cpp](//github.com/ggerganov/llama.cpp) (tested on `b1860`)
Developed and tested on Linux. I believe it could also work on Windows or Mac.
## Features
1. Lets you interact with `llama.cpp` using Markdown
2. Enables you to use almost every `llama.cpp` option
3. Makes no assumptions about what model you want to use
4. Lets you change any option at any point in the document
5. Caches prompts automatically
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 (i.e. other than Markdown) or
LLM engine through Python modules
"""
import mill, mill_cgi, mill_cli
def print_readme(language, llm_engine):
language_mod = mill.load_module(f'lang_{language}')
llm_engine_mod = mill.load_module(f'llm_{llm_engine}')
try:
example_mod = mill.load_module(f'example_{language}_{llm_engine}')
except ModuleNotFoundError:
example_mod = None
print(__doc__.strip())
print()
print()
if example_mod:
print(example_mod.example.strip())
print()
print()
print(mill_cli.__doc__.strip())
print()
print()
print(mill_cgi.__doc__.strip())
print()
print()
print(language_mod.__doc__.strip())
print()
print()
print(llm_engine_mod.__doc__.strip())
print()
print()
print(mill.__doc__.strip())
if example_mod:
print()
print()
print(example_mod.runnable_example.strip())
if __name__ == "__main__":
print_readme('markdown', 'llama.cpp')