gguf-server 0.0.2__py3-none-win_amd64.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.
@@ -0,0 +1 @@
1
+ __version__ = '0.0.2'
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python3
2
+ """gguf-server command line entry point.
3
+
4
+ python -m gguf_server launch the server GUI in the browser
5
+ python -m gguf_server engine ... run the bundled llama-server directly
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import signal
12
+ import sys
13
+ import threading
14
+ import webbrowser
15
+
16
+ from . import __version__, engine
17
+
18
+
19
+ def _cmd_serve(args) -> int:
20
+ from .server import serve, shutdown_engine
21
+
22
+ httpd = serve(host=args.host, port=args.port)
23
+
24
+ # Ctrl-C arrives as KeyboardInterrupt below; SIGTERM (kill, a closing
25
+ # terminal, a service manager) would otherwise skip the cleanup and
26
+ # orphan the llama-server child. shutdown() must run off the serving
27
+ # thread, hence the helper thread.
28
+ def _terminate(_signum, _frame):
29
+ threading.Thread(target=httpd.shutdown, daemon=True).start()
30
+
31
+ try:
32
+ signal.signal(signal.SIGTERM, _terminate)
33
+ except (ValueError, OSError, AttributeError):
34
+ pass # not the main thread, or no SIGTERM on this platform
35
+
36
+ host, port = httpd.server_address[0], httpd.server_address[1]
37
+ url = f"http://{host}:{port}/"
38
+ print(f"gguf-server {__version__} — serving on {url}")
39
+ if not engine.is_available():
40
+ print(f"note: llama-server engine unavailable ({engine.load_error()})")
41
+ if not args.no_browser:
42
+ webbrowser.open(url)
43
+ try:
44
+ httpd.serve_forever()
45
+ except KeyboardInterrupt:
46
+ print("\nshutting down")
47
+ finally:
48
+ shutdown_engine()
49
+ httpd.server_close()
50
+ return 0
51
+
52
+
53
+ def _cmd_engine(args) -> int:
54
+ argv = list(args.engine_args)
55
+ if argv and argv[0] == "--":
56
+ argv = argv[1:]
57
+ return engine.run_cli(argv)
58
+
59
+
60
+ def main(argv=None) -> int:
61
+ parser = argparse.ArgumentParser(
62
+ prog="gguf-server",
63
+ description="Local OpenAI-compatible LLM server GUI for GGUF models.",
64
+ )
65
+ parser.add_argument("--version", action="version", version=__version__)
66
+ sub = parser.add_subparsers(dest="command")
67
+
68
+ p_serve = sub.add_parser("serve", help="launch the server GUI (default)")
69
+ p_serve.add_argument("--host", default="127.0.0.1")
70
+ p_serve.add_argument("--port", type=int, default=8642,
71
+ help="port the GUI listens on (0 = auto; default 8642). "
72
+ "The LLM server itself defaults to 8888.")
73
+ p_serve.add_argument("--no-browser", action="store_true",
74
+ help="don't open the web browser automatically")
75
+ p_serve.set_defaults(func=_cmd_serve)
76
+
77
+ p_engine = sub.add_parser(
78
+ "engine", help="run the bundled llama-server with raw arguments")
79
+ p_engine.add_argument("engine_args", nargs=argparse.REMAINDER,
80
+ help="arguments passed to llama-server verbatim")
81
+ p_engine.set_defaults(func=_cmd_engine)
82
+
83
+ argv_list = list(sys.argv[1:] if argv is None else argv)
84
+ # bare invocation (`python -m gguf_server [--port ...]`) defaults to serve
85
+ if not argv_list or argv_list[0] not in ("serve", "engine",
86
+ "-h", "--help", "--version"):
87
+ argv_list.insert(0, "serve")
88
+ args = parser.parse_args(argv_list)
89
+ return args.func(args)
90
+
91
+
92
+ if __name__ == "__main__":
93
+ sys.exit(main())
Binary file