llmgui 0.1.0__tar.gz
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.
- llmgui-0.1.0/PKG-INFO +14 -0
- llmgui-0.1.0/llmgui/__init__.py +1 -0
- llmgui-0.1.0/llmgui/__main__.py +6 -0
- llmgui-0.1.0/llmgui/app.py +551 -0
- llmgui-0.1.0/llmgui/client.py +115 -0
- llmgui-0.1.0/llmgui/config.py +65 -0
- llmgui-0.1.0/llmgui/models.py +205 -0
- llmgui-0.1.0/llmgui/server.py +180 -0
- llmgui-0.1.0/llmgui/terminal.py +71 -0
- llmgui-0.1.0/llmgui.egg-info/PKG-INFO +14 -0
- llmgui-0.1.0/llmgui.egg-info/SOURCES.txt +15 -0
- llmgui-0.1.0/llmgui.egg-info/dependency_links.txt +1 -0
- llmgui-0.1.0/llmgui.egg-info/entry_points.txt +3 -0
- llmgui-0.1.0/llmgui.egg-info/requires.txt +1 -0
- llmgui-0.1.0/llmgui.egg-info/top_level.txt +1 -0
- llmgui-0.1.0/pyproject.toml +27 -0
- llmgui-0.1.0/setup.cfg +4 -0
llmgui-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llmgui
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: llama.cpp 的终端交互前端:模型选择、参数调节与带速度统计的流式对话
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: llama.cpp,llm,tui,terminal,gguf
|
|
7
|
+
Classifier: Environment :: Console
|
|
8
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
9
|
+
Classifier: Operating System :: MacOS
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""llmgui 包:llama.cpp 的终端前端。"""
|
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"""主程序:原生终端菜单式界面,负责模型、会话、设置与对话编排。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .client import ChatStats, fetch_context_size, stream_chat
|
|
11
|
+
from .config import load_config, save_config
|
|
12
|
+
from .models import ModelInfo, find_server_binary, scan_models
|
|
13
|
+
from .server import LlamaServer, ServerConfig
|
|
14
|
+
from .terminal import (
|
|
15
|
+
BOLD, Cbreak, CYAN, DIM, GREEN, RED, YELLOW,
|
|
16
|
+
clear_screen, erase_lines, paint, read_key,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class MenuItem:
|
|
22
|
+
"""菜单项:key 用于分发动作,enabled 控制是否可选。"""
|
|
23
|
+
|
|
24
|
+
key: str
|
|
25
|
+
label: str
|
|
26
|
+
enabled: bool = True
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class Session:
|
|
31
|
+
"""一个会话的标题与消息历史。"""
|
|
32
|
+
|
|
33
|
+
title: str
|
|
34
|
+
messages: list[dict] = field(default_factory=list)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class LlmguiApp:
|
|
38
|
+
"""应用主体,所有运行状态集中在这里声明。"""
|
|
39
|
+
|
|
40
|
+
def __init__(self) -> None:
|
|
41
|
+
# --- 集中声明的状态 ---
|
|
42
|
+
self.config: dict = {} # 用户配置
|
|
43
|
+
self.server: LlamaServer = LlamaServer() # 常驻推理服务
|
|
44
|
+
self.models: list[ModelInfo] = [] # 扫描到的模型
|
|
45
|
+
self.current_model: ModelInfo | None = None # 当前加载的模型
|
|
46
|
+
self.sessions: list[Session] = [Session("会话1")] # 会话列表
|
|
47
|
+
self.current_session: int = 0 # 当前会话下标
|
|
48
|
+
self.running: bool = True # 主循环开关
|
|
49
|
+
self.show_thinking: bool = True # 是否显示思考内容
|
|
50
|
+
self.max_ctx: int = 0 # 服务端上下文上限
|
|
51
|
+
self.stats: ChatStats = ChatStats() # 最近一轮性能数据
|
|
52
|
+
|
|
53
|
+
# ---------- 启动与主循环 ----------
|
|
54
|
+
|
|
55
|
+
def run(self) -> None:
|
|
56
|
+
"""加载配置、扫描模型,然后进入菜单主循环。"""
|
|
57
|
+
self.config = load_config()
|
|
58
|
+
self.scan_models()
|
|
59
|
+
try:
|
|
60
|
+
while self.running:
|
|
61
|
+
action = self.home_menu()
|
|
62
|
+
if action is not None:
|
|
63
|
+
self.handle_home(action)
|
|
64
|
+
except KeyboardInterrupt:
|
|
65
|
+
pass
|
|
66
|
+
finally:
|
|
67
|
+
self.server.stop()
|
|
68
|
+
print(paint("已退出", DIM))
|
|
69
|
+
|
|
70
|
+
def scan_models(self) -> None:
|
|
71
|
+
"""扫描配置中的目录,更新模型列表。"""
|
|
72
|
+
self.models = scan_models(self.config.get("models_dirs", []))
|
|
73
|
+
|
|
74
|
+
# ---------- 通用菜单 ----------
|
|
75
|
+
|
|
76
|
+
def pick(self, items: list[MenuItem]) -> str | None:
|
|
77
|
+
"""显示可上下移动的菜单,回车返回 key,Esc 返回 None。"""
|
|
78
|
+
selectable = [i for i, item in enumerate(items) if item.enabled]
|
|
79
|
+
if not selectable:
|
|
80
|
+
print(paint("没有可选项目", DIM))
|
|
81
|
+
return None
|
|
82
|
+
selected = selectable[0]
|
|
83
|
+
lines = self._render_items(items, selected)
|
|
84
|
+
print("\n".join(lines), flush=True)
|
|
85
|
+
with Cbreak():
|
|
86
|
+
while True:
|
|
87
|
+
key = read_key()
|
|
88
|
+
if key == "up":
|
|
89
|
+
pos = selectable.index(selected)
|
|
90
|
+
selected = selectable[(pos - 1) % len(selectable)]
|
|
91
|
+
elif key == "down":
|
|
92
|
+
pos = selectable.index(selected)
|
|
93
|
+
selected = selectable[(pos + 1) % len(selectable)]
|
|
94
|
+
elif key == "enter":
|
|
95
|
+
erase_lines(len(lines))
|
|
96
|
+
return items[selected].key
|
|
97
|
+
elif key == "esc":
|
|
98
|
+
erase_lines(len(lines))
|
|
99
|
+
return None
|
|
100
|
+
else:
|
|
101
|
+
continue
|
|
102
|
+
erase_lines(len(lines))
|
|
103
|
+
lines = self._render_items(items, selected)
|
|
104
|
+
print("\n".join(lines), flush=True)
|
|
105
|
+
|
|
106
|
+
def _render_items(self, items: list[MenuItem], selected: int) -> list[str]:
|
|
107
|
+
"""按三种状态渲染菜单:禁用 x 灰色、选中 > 青色、可选 - 默认色。"""
|
|
108
|
+
rendered: list[str] = []
|
|
109
|
+
for index, item in enumerate(items):
|
|
110
|
+
if not item.enabled:
|
|
111
|
+
rendered.append(paint("x " + item.label, DIM))
|
|
112
|
+
elif index == selected:
|
|
113
|
+
rendered.append(paint("> " + item.label, BOLD, CYAN))
|
|
114
|
+
else:
|
|
115
|
+
rendered.append("- " + item.label)
|
|
116
|
+
return rendered
|
|
117
|
+
|
|
118
|
+
def prompt(self, label: str, default: str = "") -> str:
|
|
119
|
+
"""用标准行输入读取内容,保证中文输入法正常工作。"""
|
|
120
|
+
try:
|
|
121
|
+
raw = input(paint(f"> {label}: ", DIM))
|
|
122
|
+
except EOFError:
|
|
123
|
+
return ""
|
|
124
|
+
return raw.strip() or default
|
|
125
|
+
|
|
126
|
+
# ---------- 主界面 ----------
|
|
127
|
+
|
|
128
|
+
def home_menu(self) -> str | None:
|
|
129
|
+
"""清屏渲染主界面,返回用户选择的动作。"""
|
|
130
|
+
clear_screen()
|
|
131
|
+
self._render_home_header()
|
|
132
|
+
return self.pick(self._home_items())
|
|
133
|
+
|
|
134
|
+
def _render_home_header(self) -> None:
|
|
135
|
+
"""打印当前目录、模型列表和当前模型。"""
|
|
136
|
+
folders = self.config.get("models_dirs", [])
|
|
137
|
+
display = folders[0] if folders else "未设置"
|
|
138
|
+
extra = f" (+{len(folders) - 1})" if len(folders) > 1 else ""
|
|
139
|
+
print(f"当前文件夹: {display}{extra}")
|
|
140
|
+
if not self.models:
|
|
141
|
+
print(paint("未找到模型", RED))
|
|
142
|
+
else:
|
|
143
|
+
print(f"找到 {len(self.models)} 个模型文件:")
|
|
144
|
+
for model in self.models[:8]:
|
|
145
|
+
print(f"· {model.name}")
|
|
146
|
+
if len(self.models) > 8:
|
|
147
|
+
print(paint(f"· 还有 {len(self.models) - 8} 个…", DIM))
|
|
148
|
+
name = self.current_model.name if self.current_model else "无"
|
|
149
|
+
print(f"当前模型: {name}")
|
|
150
|
+
print()
|
|
151
|
+
|
|
152
|
+
def _home_items(self) -> list[MenuItem]:
|
|
153
|
+
"""根据是否有模型决定主菜单内容。"""
|
|
154
|
+
loaded = self.current_model is not None and self.server.is_alive()
|
|
155
|
+
items: list[MenuItem] = []
|
|
156
|
+
if self.models:
|
|
157
|
+
items.append(MenuItem("model", "切换模型..."))
|
|
158
|
+
items.append(MenuItem("import", "导入文件夹链接..."))
|
|
159
|
+
items.append(MenuItem("settings", "设置..."))
|
|
160
|
+
items.append(MenuItem("session", f"选择会话...({self.sessions[self.current_session].title})"))
|
|
161
|
+
items.append(MenuItem("message", "消息...", loaded))
|
|
162
|
+
items.append(MenuItem("quit", "退出..."))
|
|
163
|
+
return items
|
|
164
|
+
|
|
165
|
+
def handle_home(self, action: str) -> None:
|
|
166
|
+
"""分发主菜单动作。"""
|
|
167
|
+
if action == "model":
|
|
168
|
+
self.choose_model()
|
|
169
|
+
elif action == "import":
|
|
170
|
+
self.import_folder()
|
|
171
|
+
elif action == "settings":
|
|
172
|
+
self.settings_menu()
|
|
173
|
+
elif action == "session":
|
|
174
|
+
self.choose_session()
|
|
175
|
+
elif action == "message":
|
|
176
|
+
self.session_loop()
|
|
177
|
+
elif action == "quit":
|
|
178
|
+
self.running = False
|
|
179
|
+
|
|
180
|
+
# ---------- 模型 ----------
|
|
181
|
+
|
|
182
|
+
def import_folder(self) -> None:
|
|
183
|
+
"""输入一个目录路径并加入扫描列表。"""
|
|
184
|
+
clear_screen()
|
|
185
|
+
path_text = self.prompt("文件夹路径(支持 ~ 开头)")
|
|
186
|
+
if not path_text:
|
|
187
|
+
return
|
|
188
|
+
folder = Path(path_text).expanduser()
|
|
189
|
+
if not folder.is_dir():
|
|
190
|
+
print(paint(f"目录不存在:{folder}", RED))
|
|
191
|
+
input(paint("按回车返回", DIM))
|
|
192
|
+
return
|
|
193
|
+
folders = self.config.setdefault("models_dirs", [])
|
|
194
|
+
if str(folder) not in folders:
|
|
195
|
+
folders.append(str(folder))
|
|
196
|
+
save_config(self.config)
|
|
197
|
+
self.scan_models()
|
|
198
|
+
|
|
199
|
+
def choose_model(self) -> None:
|
|
200
|
+
"""列出模型供选择,选中后启动服务。"""
|
|
201
|
+
clear_screen()
|
|
202
|
+
items = [
|
|
203
|
+
MenuItem(str(i), f"{m.name} {m.quant or '?'} {m.params} {m.size_text}")
|
|
204
|
+
for i, m in enumerate(self.models)
|
|
205
|
+
]
|
|
206
|
+
items.append(MenuItem("back", "返回..."))
|
|
207
|
+
key = self.pick(items)
|
|
208
|
+
if key is None or key == "back":
|
|
209
|
+
return
|
|
210
|
+
self.load_model(self.models[int(key)])
|
|
211
|
+
|
|
212
|
+
def load_model(self, model: ModelInfo) -> None:
|
|
213
|
+
"""启动常驻服务,阻塞到健康检查通过为止。"""
|
|
214
|
+
binary = find_server_binary(self.config.get("server_path", ""))
|
|
215
|
+
if not binary:
|
|
216
|
+
clear_screen()
|
|
217
|
+
print(paint("找不到 llama-server,请先在设置里填写路径", RED))
|
|
218
|
+
input(paint("按回车返回", DIM))
|
|
219
|
+
return
|
|
220
|
+
clear_screen()
|
|
221
|
+
print(f"正在加载 {model.name} …")
|
|
222
|
+
try:
|
|
223
|
+
self.server.start(
|
|
224
|
+
ServerConfig(
|
|
225
|
+
binary=binary,
|
|
226
|
+
model=str(model.path),
|
|
227
|
+
ctx_size=int(self.config.get("ctx_size", 8192)),
|
|
228
|
+
n_gpu_layers=int(self.config.get("n_gpu_layers", 99)),
|
|
229
|
+
port=int(self.config.get("port", 0)),
|
|
230
|
+
threads=int(self.config.get("threads", -1)),
|
|
231
|
+
cache_type_k=str(self.config.get("cache_type_k", "f16")),
|
|
232
|
+
cache_type_v=str(self.config.get("cache_type_v", "f16")),
|
|
233
|
+
keep_tokens=int(self.config.get("keep_tokens", 0)),
|
|
234
|
+
context_shift=bool(self.config.get("context_shift", True)),
|
|
235
|
+
metrics=bool(self.config.get("metrics", False)),
|
|
236
|
+
json_schema_file=str(self.config.get("json_schema_file", "")),
|
|
237
|
+
slot_save_path=str(self.config.get("slot_save_path", "")),
|
|
238
|
+
draft_model=str(self.config.get("draft_model", "")),
|
|
239
|
+
draft_max=int(self.config.get("draft_max", 4)),
|
|
240
|
+
thinking=str(self.config.get("thinking", "auto")),
|
|
241
|
+
reasoning_budget=int(self.config.get("reasoning_budget", -1)),
|
|
242
|
+
dry_multiplier=float(self.config.get("dry_multiplier", 0.0)),
|
|
243
|
+
extra_args=str(self.config.get("extra_args", "")),
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
except (RuntimeError, TimeoutError, OSError) as error:
|
|
247
|
+
clear_screen()
|
|
248
|
+
print(paint(f"加载失败:{error}", RED))
|
|
249
|
+
input(paint("按回车返回", DIM))
|
|
250
|
+
return
|
|
251
|
+
self.current_model = model
|
|
252
|
+
self.config["last_model"] = str(model.path)
|
|
253
|
+
save_config(self.config)
|
|
254
|
+
self.max_ctx = asyncio.run(fetch_context_size(self.server.base_url))
|
|
255
|
+
if not self.max_ctx:
|
|
256
|
+
self.max_ctx = int(self.config.get("ctx_size", 8192))
|
|
257
|
+
print(paint(f"已加载 {model.name}", GREEN))
|
|
258
|
+
input(paint("按回车进入", DIM))
|
|
259
|
+
|
|
260
|
+
# ---------- 会话 ----------
|
|
261
|
+
|
|
262
|
+
def choose_session(self) -> None:
|
|
263
|
+
"""列出会话,支持切换或新建。"""
|
|
264
|
+
clear_screen()
|
|
265
|
+
items = [MenuItem(str(i), s.title) for i, s in enumerate(self.sessions)]
|
|
266
|
+
items.append(MenuItem("new", "新建会话..."))
|
|
267
|
+
items.append(MenuItem("back", "返回..."))
|
|
268
|
+
key = self.pick(items)
|
|
269
|
+
if key is None or key == "back":
|
|
270
|
+
return
|
|
271
|
+
if key == "new":
|
|
272
|
+
self.sessions.append(Session(f"会话{len(self.sessions) + 1}"))
|
|
273
|
+
self.current_session = len(self.sessions) - 1
|
|
274
|
+
else:
|
|
275
|
+
self.current_session = int(key)
|
|
276
|
+
|
|
277
|
+
def session_loop(self) -> None:
|
|
278
|
+
"""进入会话界面:先打印历史,再循环展示菜单与输入。"""
|
|
279
|
+
session = self.sessions[self.current_session]
|
|
280
|
+
clear_screen()
|
|
281
|
+
print(paint(session.title, BOLD))
|
|
282
|
+
for message in session.messages:
|
|
283
|
+
self._print_message(message)
|
|
284
|
+
loaded = self.server.is_alive()
|
|
285
|
+
while True:
|
|
286
|
+
items = [
|
|
287
|
+
MenuItem("message", "消息...", loaded),
|
|
288
|
+
MenuItem("leave", "退出..."),
|
|
289
|
+
]
|
|
290
|
+
action = self.pick(items)
|
|
291
|
+
if action != "message":
|
|
292
|
+
return
|
|
293
|
+
text = self.prompt("消息")
|
|
294
|
+
if not text:
|
|
295
|
+
continue
|
|
296
|
+
self.chat(session, text)
|
|
297
|
+
|
|
298
|
+
def chat(self, session: Session, text: str) -> None:
|
|
299
|
+
"""发送一条消息并流式打印回复,最后追加统计行。"""
|
|
300
|
+
session.messages.append({"role": "user", "content": text})
|
|
301
|
+
print(paint(f"[ {text}", CYAN))
|
|
302
|
+
print("[ ", end="", flush=True)
|
|
303
|
+
|
|
304
|
+
reasoning: list[str] = []
|
|
305
|
+
content: list[str] = []
|
|
306
|
+
in_thinking = False
|
|
307
|
+
|
|
308
|
+
def on_content(delta: str) -> None:
|
|
309
|
+
"""正文到达时恢复正常色并立即输出。"""
|
|
310
|
+
nonlocal in_thinking
|
|
311
|
+
if in_thinking:
|
|
312
|
+
sys.stdout.write("\033[0m")
|
|
313
|
+
in_thinking = False
|
|
314
|
+
content.append(delta)
|
|
315
|
+
sys.stdout.write(delta)
|
|
316
|
+
sys.stdout.flush()
|
|
317
|
+
|
|
318
|
+
def on_reasoning(delta: str) -> None:
|
|
319
|
+
"""思考内容用暗色输出,与正文区分。"""
|
|
320
|
+
nonlocal in_thinking
|
|
321
|
+
if self.show_thinking:
|
|
322
|
+
if not in_thinking:
|
|
323
|
+
sys.stdout.write(DIM)
|
|
324
|
+
in_thinking = True
|
|
325
|
+
reasoning.append(delta)
|
|
326
|
+
sys.stdout.write(delta)
|
|
327
|
+
sys.stdout.flush()
|
|
328
|
+
|
|
329
|
+
try:
|
|
330
|
+
asyncio.run(
|
|
331
|
+
stream_chat(
|
|
332
|
+
self.server.base_url,
|
|
333
|
+
[{"role": m["role"], "content": m["content"]} for m in session.messages],
|
|
334
|
+
self.config,
|
|
335
|
+
on_content,
|
|
336
|
+
on_reasoning,
|
|
337
|
+
self._store_stats,
|
|
338
|
+
)
|
|
339
|
+
)
|
|
340
|
+
except Exception as error: # noqa: BLE001 - 网络异常统一转为界面提示
|
|
341
|
+
sys.stdout.write("\033[0m")
|
|
342
|
+
print(paint(f"\n[请求失败] {error}", RED))
|
|
343
|
+
else:
|
|
344
|
+
if in_thinking:
|
|
345
|
+
sys.stdout.write("\033[0m")
|
|
346
|
+
print()
|
|
347
|
+
answer = "".join(content)
|
|
348
|
+
session.messages.append({"role": "assistant", "content": answer})
|
|
349
|
+
self._print_stats()
|
|
350
|
+
|
|
351
|
+
def _print_stats(self) -> None:
|
|
352
|
+
"""在回复后打印一行灰色性能信息。"""
|
|
353
|
+
ctx = f"{self.stats.prompt_tokens + self.stats.predicted_tokens}/{self.max_ctx}" if self.max_ctx else "?"
|
|
354
|
+
print(paint(
|
|
355
|
+
f"[ 首字 {self.stats.ttft:.2f}s · 生成 {self.stats.predicted_per_second:.1f} tok/s"
|
|
356
|
+
f" · 提示 {self.stats.prompt_per_second:.0f} tok/s · 上下文 {ctx} ]",
|
|
357
|
+
DIM,
|
|
358
|
+
))
|
|
359
|
+
|
|
360
|
+
def _store_stats(self, stats: ChatStats) -> None:
|
|
361
|
+
"""保存本轮统计供状态行使用。"""
|
|
362
|
+
self.stats = stats
|
|
363
|
+
|
|
364
|
+
def _print_message(self, message: dict) -> None:
|
|
365
|
+
"""打印历史消息,用户青色、助手默认色。"""
|
|
366
|
+
content = message.get("content", "")
|
|
367
|
+
if message.get("role") == "user":
|
|
368
|
+
print(paint(f"[ {content}", CYAN))
|
|
369
|
+
else:
|
|
370
|
+
print(f"[ {content}")
|
|
371
|
+
|
|
372
|
+
# ---------- 设置 ----------
|
|
373
|
+
|
|
374
|
+
def settings_menu(self) -> None:
|
|
375
|
+
"""设置分组入口,避免一页塞太多选项。"""
|
|
376
|
+
while True:
|
|
377
|
+
clear_screen()
|
|
378
|
+
print(paint("设置", BOLD))
|
|
379
|
+
print(paint("标注需重载的项目会在下次加载模型时生效", DIM))
|
|
380
|
+
print()
|
|
381
|
+
action = self.pick([
|
|
382
|
+
MenuItem("gen", "生成参数..."),
|
|
383
|
+
MenuItem("think", "思考控制...(需重载)"),
|
|
384
|
+
MenuItem("perf", "上下文与性能...(需重载)"),
|
|
385
|
+
MenuItem("adv", "高级与实验...(需重载)"),
|
|
386
|
+
MenuItem("extra", f"追加启动参数: {self.config.get('extra_args') or '无'}"),
|
|
387
|
+
MenuItem("show", f"显示思考内容: {'开' if self.show_thinking else '关'}"),
|
|
388
|
+
MenuItem("back", "返回..."),
|
|
389
|
+
])
|
|
390
|
+
if action is None or action == "back":
|
|
391
|
+
return
|
|
392
|
+
if action == "extra":
|
|
393
|
+
self._edit_extra_args()
|
|
394
|
+
elif action == "show":
|
|
395
|
+
self.show_thinking = not self.show_thinking
|
|
396
|
+
else:
|
|
397
|
+
self._settings_group(action)
|
|
398
|
+
|
|
399
|
+
def _edit_extra_args(self) -> None:
|
|
400
|
+
"""编辑追加到启动命令末尾的自由参数。"""
|
|
401
|
+
clear_screen()
|
|
402
|
+
value = self.prompt("额外参数,原样拼到启动命令末尾,留空清除")
|
|
403
|
+
self.config["extra_args"] = value
|
|
404
|
+
save_config(self.config)
|
|
405
|
+
|
|
406
|
+
def _settings_group(self, group: str) -> None:
|
|
407
|
+
"""在某一组设置里循环选择并修改。"""
|
|
408
|
+
while True:
|
|
409
|
+
clear_screen()
|
|
410
|
+
key = self.pick(self._group_items(group))
|
|
411
|
+
if key is None or key == "back":
|
|
412
|
+
return
|
|
413
|
+
if key == "thinking":
|
|
414
|
+
self._pick_thinking()
|
|
415
|
+
elif key in ("cache_type_k", "cache_type_v"):
|
|
416
|
+
self._pick_cache(key)
|
|
417
|
+
elif key in ("context_shift", "metrics"):
|
|
418
|
+
self.config[key] = not self.config.get(key, False)
|
|
419
|
+
save_config(self.config)
|
|
420
|
+
elif key == "draft_model":
|
|
421
|
+
self._pick_draft()
|
|
422
|
+
elif key in ("json_schema_file", "slot_save_path", "server_path"):
|
|
423
|
+
self._edit_path(key)
|
|
424
|
+
else:
|
|
425
|
+
self._edit_number(key)
|
|
426
|
+
|
|
427
|
+
def _group_items(self, group: str) -> list[MenuItem]:
|
|
428
|
+
"""按组生成菜单项,标签里直接显示当前值。"""
|
|
429
|
+
cfg = self.config
|
|
430
|
+
if group == "gen":
|
|
431
|
+
return [
|
|
432
|
+
MenuItem("temperature", f"温度: {cfg['temperature']}"),
|
|
433
|
+
MenuItem("top_p", f"top_p: {cfg['top_p']}"),
|
|
434
|
+
MenuItem("top_k", f"top_k: {cfg['top_k']}(0 关闭)"),
|
|
435
|
+
MenuItem("min_p", f"min_p: {cfg['min_p']}(0 关闭)"),
|
|
436
|
+
MenuItem("repeat_penalty", f"重复惩罚: {cfg['repeat_penalty']}"),
|
|
437
|
+
MenuItem("seed", f"随机种子: {cfg['seed']}(-1 随机)"),
|
|
438
|
+
MenuItem("dry_multiplier", f"DRY 强度: {cfg['dry_multiplier']}(0 关闭)"),
|
|
439
|
+
MenuItem("back", "返回..."),
|
|
440
|
+
]
|
|
441
|
+
if group == "think":
|
|
442
|
+
return [
|
|
443
|
+
MenuItem("thinking", f"思考模式: {cfg['thinking']}"),
|
|
444
|
+
MenuItem("reasoning_budget", f"思考预算: {cfg['reasoning_budget']}(-1 不限,0 立即结束)"),
|
|
445
|
+
MenuItem("back", "返回..."),
|
|
446
|
+
]
|
|
447
|
+
if group == "perf":
|
|
448
|
+
return [
|
|
449
|
+
MenuItem("ctx_size", f"上下文长度: {cfg['ctx_size']}"),
|
|
450
|
+
MenuItem("n_gpu_layers", f"GPU 层数: {cfg['n_gpu_layers']}"),
|
|
451
|
+
MenuItem("threads", f"CPU 线程: {cfg['threads']}(-1 自动)"),
|
|
452
|
+
MenuItem("cache_type_k", f"K 缓存类型: {cfg['cache_type_k']}"),
|
|
453
|
+
MenuItem("cache_type_v", f"V 缓存类型: {cfg['cache_type_v']}"),
|
|
454
|
+
MenuItem("keep_tokens", f"保留初始提示 token: {cfg['keep_tokens']}"),
|
|
455
|
+
MenuItem("context_shift", f"上下文平移: {'开' if cfg['context_shift'] else '关'}"),
|
|
456
|
+
MenuItem("metrics", f"性能指标端点: {'开' if cfg['metrics'] else '关'}"),
|
|
457
|
+
MenuItem("back", "返回..."),
|
|
458
|
+
]
|
|
459
|
+
draft = Path(cfg["draft_model"]).name if cfg["draft_model"] else "关闭"
|
|
460
|
+
return [
|
|
461
|
+
MenuItem("json_schema_file", f"JSON 结构文件: {cfg['json_schema_file'] or '未设置'}"),
|
|
462
|
+
MenuItem("slot_save_path", f"会话缓存目录: {cfg['slot_save_path'] or '未设置'}"),
|
|
463
|
+
MenuItem("draft_model", f"草稿模型: {draft}"),
|
|
464
|
+
MenuItem("draft_max", f"草稿长度: {cfg['draft_max']}"),
|
|
465
|
+
MenuItem("server_path", f"服务端路径: {cfg['server_path'] or '自动探测'}"),
|
|
466
|
+
MenuItem("back", "返回..."),
|
|
467
|
+
]
|
|
468
|
+
|
|
469
|
+
def _edit_number(self, field_name: str) -> None:
|
|
470
|
+
"""修改数值型设置,按原类型决定整数或浮点解析。"""
|
|
471
|
+
labels = {
|
|
472
|
+
"temperature": "温度", "top_p": "top_p", "top_k": "top_k",
|
|
473
|
+
"min_p": "min_p", "repeat_penalty": "重复惩罚", "seed": "随机种子",
|
|
474
|
+
"dry_multiplier": "DRY 强度", "reasoning_budget": "思考预算",
|
|
475
|
+
"ctx_size": "上下文长度", "n_gpu_layers": "GPU 层数",
|
|
476
|
+
"threads": "CPU 线程", "keep_tokens": "保留 token 数",
|
|
477
|
+
"draft_max": "草稿长度",
|
|
478
|
+
}
|
|
479
|
+
clear_screen()
|
|
480
|
+
current = self.config.get(field_name)
|
|
481
|
+
value = self.prompt(f"{labels.get(field_name, field_name)}(当前 {current})")
|
|
482
|
+
if not value:
|
|
483
|
+
return
|
|
484
|
+
try:
|
|
485
|
+
self.config[field_name] = int(value) if isinstance(current, int) else float(value)
|
|
486
|
+
save_config(self.config)
|
|
487
|
+
except ValueError:
|
|
488
|
+
print(paint("不是有效数字,未修改", YELLOW))
|
|
489
|
+
input(paint("按回车返回", DIM))
|
|
490
|
+
|
|
491
|
+
def _edit_path(self, field_name: str) -> None:
|
|
492
|
+
"""修改路径型设置,留空表示清除。"""
|
|
493
|
+
labels = {
|
|
494
|
+
"json_schema_file": "JSON 结构文件",
|
|
495
|
+
"slot_save_path": "会话缓存目录",
|
|
496
|
+
"server_path": "llama-server 路径",
|
|
497
|
+
}
|
|
498
|
+
clear_screen()
|
|
499
|
+
current = self.config.get(field_name) or "未设置"
|
|
500
|
+
value = self.prompt(f"{labels.get(field_name, field_name)}(当前 {current},留空清除)")
|
|
501
|
+
self.config[field_name] = str(Path(value).expanduser()) if value else ""
|
|
502
|
+
save_config(self.config)
|
|
503
|
+
|
|
504
|
+
def _pick_thinking(self) -> None:
|
|
505
|
+
"""选择思考模式,决定服务端是否启用推理。"""
|
|
506
|
+
clear_screen()
|
|
507
|
+
print(paint("思考控制", BOLD))
|
|
508
|
+
print()
|
|
509
|
+
key = self.pick([
|
|
510
|
+
MenuItem("auto", "自动(跟随模型模板)"),
|
|
511
|
+
MenuItem("on", "强制开启"),
|
|
512
|
+
MenuItem("off", "强制关闭"),
|
|
513
|
+
MenuItem("back", "返回..."),
|
|
514
|
+
])
|
|
515
|
+
if key and key != "back":
|
|
516
|
+
self.config["thinking"] = key
|
|
517
|
+
save_config(self.config)
|
|
518
|
+
|
|
519
|
+
def _pick_cache(self, field_name: str) -> None:
|
|
520
|
+
"""选择 KV 缓存精度,q8_0 可显著降低内存占用。"""
|
|
521
|
+
clear_screen()
|
|
522
|
+
print(paint("KV 缓存类型", BOLD))
|
|
523
|
+
print(paint("q8_0 约省一半内存,f16 精度最高", DIM))
|
|
524
|
+
print()
|
|
525
|
+
key = self.pick([
|
|
526
|
+
MenuItem("f16", "f16(默认)"),
|
|
527
|
+
MenuItem("q8_0", "q8_0(省内存)"),
|
|
528
|
+
MenuItem("q4_0", "q4_0(更省,精度低)"),
|
|
529
|
+
MenuItem("back", "返回..."),
|
|
530
|
+
])
|
|
531
|
+
if key and key != "back":
|
|
532
|
+
self.config[field_name] = key
|
|
533
|
+
save_config(self.config)
|
|
534
|
+
|
|
535
|
+
def _pick_draft(self) -> None:
|
|
536
|
+
"""从已扫描模型中选择投机解码的草稿模型。"""
|
|
537
|
+
clear_screen()
|
|
538
|
+
items = [MenuItem("none", "关闭草稿模型")]
|
|
539
|
+
for index, model in enumerate(self.models):
|
|
540
|
+
items.append(MenuItem(str(index), f"{model.name} {model.quant} {model.size_text}"))
|
|
541
|
+
items.append(MenuItem("back", "返回..."))
|
|
542
|
+
key = self.pick(items)
|
|
543
|
+
if key is None or key == "back":
|
|
544
|
+
return
|
|
545
|
+
self.config["draft_model"] = "" if key == "none" else str(self.models[int(key)].path)
|
|
546
|
+
save_config(self.config)
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def main() -> None:
|
|
550
|
+
"""程序入口。"""
|
|
551
|
+
LlmguiApp().run()
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""对话客户端:向 llama-server 发送流式请求,并把思考与正文分流回调。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import time
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Awaitable, Callable
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class ChatStats:
|
|
15
|
+
"""一轮对话的性能数据,来源优先取服务端 timings。"""
|
|
16
|
+
|
|
17
|
+
ttft: float = 0.0 # 首 token 延迟,秒
|
|
18
|
+
prompt_tokens: int = 0 # 本次提示词 token 数
|
|
19
|
+
predicted_tokens: int = 0 # 本次生成 token 数
|
|
20
|
+
prompt_per_second: float = 0.0 # 提示词处理速度
|
|
21
|
+
predicted_per_second: float = 0.0 # 生成速度
|
|
22
|
+
elapsed: float = 0.0 # 客户端总耗时,作为 timings 缺失时的兜底
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
DeltaCallback = Callable[[str], None]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
async def stream_chat(
|
|
29
|
+
base_url: str,
|
|
30
|
+
messages: list[dict[str, str]],
|
|
31
|
+
settings: dict,
|
|
32
|
+
on_content: DeltaCallback,
|
|
33
|
+
on_reasoning: DeltaCallback,
|
|
34
|
+
on_stats: Callable[[ChatStats], None],
|
|
35
|
+
) -> None:
|
|
36
|
+
"""发起一次流式补全,边收边回调,结束后回传统计信息。"""
|
|
37
|
+
payload: dict = {
|
|
38
|
+
"messages": messages,
|
|
39
|
+
"stream": True,
|
|
40
|
+
"temperature": settings.get("temperature", 0.7),
|
|
41
|
+
"top_p": settings.get("top_p", 0.95),
|
|
42
|
+
"top_k": settings.get("top_k", 40),
|
|
43
|
+
"min_p": settings.get("min_p", 0.05),
|
|
44
|
+
"repeat_penalty": settings.get("repeat_penalty", 1.0),
|
|
45
|
+
}
|
|
46
|
+
# 随机种子为 -1 时交给服务端随机,避免部分版本不接受负值
|
|
47
|
+
if int(settings.get("seed", -1)) >= 0:
|
|
48
|
+
payload["seed"] = int(settings["seed"])
|
|
49
|
+
|
|
50
|
+
stats = ChatStats()
|
|
51
|
+
started = time.monotonic()
|
|
52
|
+
first_token_at = 0.0
|
|
53
|
+
|
|
54
|
+
timeout = httpx.Timeout(connect=10.0, read=None, write=30.0, pool=10.0)
|
|
55
|
+
async with httpx.AsyncClient(timeout=timeout) as client:
|
|
56
|
+
async with client.stream(
|
|
57
|
+
"POST", f"{base_url}/v1/chat/completions", json=payload
|
|
58
|
+
) as response:
|
|
59
|
+
if response.status_code != 200:
|
|
60
|
+
body = (await response.aread()).decode("utf-8", errors="replace")
|
|
61
|
+
raise RuntimeError(f"服务端返回 {response.status_code}:{body[:500]}")
|
|
62
|
+
async for line in response.aiter_lines():
|
|
63
|
+
if not line.startswith("data:"):
|
|
64
|
+
continue
|
|
65
|
+
raw = line[5:].strip()
|
|
66
|
+
if not raw or raw == "[DONE]":
|
|
67
|
+
continue
|
|
68
|
+
chunk = json.loads(raw)
|
|
69
|
+
# 服务端在末尾附带 timings,用它作为速度的权威来源
|
|
70
|
+
if "timings" in chunk:
|
|
71
|
+
_apply_timings(stats, chunk["timings"])
|
|
72
|
+
for choice in chunk.get("choices", []):
|
|
73
|
+
delta = choice.get("delta") or {}
|
|
74
|
+
reasoning = delta.get("reasoning_content")
|
|
75
|
+
content = delta.get("content")
|
|
76
|
+
if reasoning:
|
|
77
|
+
on_reasoning(reasoning)
|
|
78
|
+
if content:
|
|
79
|
+
if first_token_at == 0.0:
|
|
80
|
+
first_token_at = time.monotonic()
|
|
81
|
+
stats.ttft = first_token_at - started
|
|
82
|
+
stats.predicted_tokens += 1
|
|
83
|
+
on_content(content)
|
|
84
|
+
|
|
85
|
+
stats.elapsed = time.monotonic() - started
|
|
86
|
+
# timings 缺失时用客户端计时估算,保证状态栏永远有数字
|
|
87
|
+
if stats.predicted_per_second == 0.0 and stats.elapsed > 0:
|
|
88
|
+
stats.predicted_per_second = stats.predicted_tokens / stats.elapsed
|
|
89
|
+
on_stats(stats)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _apply_timings(stats: ChatStats, timings: dict) -> None:
|
|
93
|
+
"""把服务端 timings 字段映射到统计结构,字段缺失时保持原值。"""
|
|
94
|
+
stats.prompt_tokens = int(timings.get("prompt_n", stats.prompt_tokens))
|
|
95
|
+
stats.predicted_tokens = int(timings.get("predicted_n", stats.predicted_tokens))
|
|
96
|
+
stats.prompt_per_second = float(
|
|
97
|
+
timings.get("prompt_per_second", stats.prompt_per_second)
|
|
98
|
+
)
|
|
99
|
+
stats.predicted_per_second = float(
|
|
100
|
+
timings.get("predicted_per_second", stats.predicted_per_second)
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
async def fetch_context_size(base_url: str) -> int:
|
|
105
|
+
"""读取 /props 获取模型实际上下文长度,拿不到则返回 0。"""
|
|
106
|
+
try:
|
|
107
|
+
async with httpx.AsyncClient(timeout=5.0) as client:
|
|
108
|
+
response = await client.get(f"{base_url}/props")
|
|
109
|
+
if response.status_code == 200:
|
|
110
|
+
data = response.json()
|
|
111
|
+
settings = data.get("default_generation_settings") or {}
|
|
112
|
+
return int(settings.get("n_ctx", 0))
|
|
113
|
+
except (httpx.HTTPError, ValueError, TypeError):
|
|
114
|
+
pass
|
|
115
|
+
return 0
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""配置读写:把用户设置持久化为 JSON,放在 ~/.config/llmgui 下。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
# 配置目录与文件路径,遵循 XDG 习惯
|
|
10
|
+
CONFIG_DIR = Path.home() / ".config" / "llmgui"
|
|
11
|
+
CONFIG_PATH = CONFIG_DIR / "config.json"
|
|
12
|
+
|
|
13
|
+
# 默认配置,所有可用键集中在这里,新增键必须同步补默认值
|
|
14
|
+
DEFAULT_CONFIG: dict[str, Any] = {
|
|
15
|
+
"server_path": "", # llama-server 可执行文件路径,空表示自动探测
|
|
16
|
+
"models_dirs": [str(Path.home() / "models")], # 模型扫描目录列表
|
|
17
|
+
"last_model": "", # 上次使用的模型路径
|
|
18
|
+
"ctx_size": 8192, # 上下文长度
|
|
19
|
+
"n_gpu_layers": 99, # 卸载到 GPU 的层数,Mac 上 99 表示全量
|
|
20
|
+
"temperature": 0.7, # 采样温度
|
|
21
|
+
"top_p": 0.95, # 核采样阈值
|
|
22
|
+
"top_k": 40, # 每步候选词数量,0 表示关闭
|
|
23
|
+
"min_p": 0.05, # 最低概率阈值,0 表示关闭
|
|
24
|
+
"repeat_penalty": 1.0, # 重复惩罚,1.0 表示关闭
|
|
25
|
+
"seed": -1, # 随机种子,-1 表示每次随机
|
|
26
|
+
"dry_multiplier": 0.0, # DRY 采样强度,0 表示关闭
|
|
27
|
+
"thinking": "auto", # 思考开关:auto / on / off
|
|
28
|
+
"reasoning_budget": -1, # 思考 token 预算,-1 不限,0 立即结束
|
|
29
|
+
"threads": -1, # CPU 线程数,-1 由服务端自动决定
|
|
30
|
+
"cache_type_k": "f16", # K 缓存类型,可改 q8_0 省内存
|
|
31
|
+
"cache_type_v": "f16", # V 缓存类型
|
|
32
|
+
"keep_tokens": 0, # 超长时保留的初始提示 token 数
|
|
33
|
+
"context_shift": True, # 是否允许超长时平移上下文
|
|
34
|
+
"metrics": False, # 是否开启性能指标端点
|
|
35
|
+
"json_schema_file": "", # JSON 结构约束文件路径
|
|
36
|
+
"slot_save_path": "", # 会话 KV 缓存存盘目录
|
|
37
|
+
"draft_model": "", # 投机解码草稿模型路径
|
|
38
|
+
"draft_max": 4, # 草稿模型每次最多猜几个 token
|
|
39
|
+
"extra_args": "", # 原样追加到启动命令的额外参数
|
|
40
|
+
"port": 0, # 固定端口,0 表示自动挑选空闲端口
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def load_config() -> dict[str, Any]:
|
|
45
|
+
"""读取配置并与默认值合并,文件损坏时返回默认值而不是崩溃。"""
|
|
46
|
+
config = dict(DEFAULT_CONFIG)
|
|
47
|
+
if CONFIG_PATH.exists():
|
|
48
|
+
try:
|
|
49
|
+
stored = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
|
|
50
|
+
if isinstance(stored, dict):
|
|
51
|
+
# 只接受已知键,避免旧版本残留字段污染运行状态
|
|
52
|
+
config.update({k: v for k, v in stored.items() if k in DEFAULT_CONFIG})
|
|
53
|
+
except (OSError, json.JSONDecodeError):
|
|
54
|
+
pass
|
|
55
|
+
return config
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def save_config(config: dict[str, Any]) -> None:
|
|
59
|
+
"""原子写入配置,先写临时文件再替换,避免中途失败留下半截文件。"""
|
|
60
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
61
|
+
tmp_path = CONFIG_PATH.with_suffix(".tmp")
|
|
62
|
+
tmp_path.write_text(
|
|
63
|
+
json.dumps(config, ensure_ascii=False, indent=2), encoding="utf-8"
|
|
64
|
+
)
|
|
65
|
+
tmp_path.replace(CONFIG_PATH)
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""GGUF 模型发现与元数据读取,供模型列表展示参数量、上下文与量化类型。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import struct
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
# GGUF 魔数,用于校验文件确实是模型而不是同名垃圾文件
|
|
10
|
+
GGUF_MAGIC = b"GGUF"
|
|
11
|
+
|
|
12
|
+
# general.file_type 到量化名称的映射,只覆盖常见取值
|
|
13
|
+
FILE_TYPE_NAMES: dict[int, str] = {
|
|
14
|
+
0: "F32", 1: "F16", 2: "Q4_0", 3: "Q4_1", 7: "Q8_0",
|
|
15
|
+
8: "Q5_0", 9: "Q5_1", 10: "Q2_K", 11: "Q3_K_S", 12: "Q3_K_M",
|
|
16
|
+
13: "Q3_K_L", 14: "Q4_K_S", 15: "Q4_K_M", 16: "Q5_K_S",
|
|
17
|
+
17: "Q5_K_M", 18: "Q6_K",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
# GGUF 元数据值类型编号,用于跳过不认识的值
|
|
21
|
+
_TYPE_UINT8, _TYPE_INT8 = 0, 1
|
|
22
|
+
_TYPE_UINT16, _TYPE_INT16 = 2, 3
|
|
23
|
+
_TYPE_UINT32, _TYPE_INT32 = 4, 5
|
|
24
|
+
_TYPE_FLOAT32, _TYPE_BOOL = 6, 7
|
|
25
|
+
_TYPE_STRING, _TYPE_ARRAY = 8, 9
|
|
26
|
+
_TYPE_UINT64, _TYPE_INT64 = 10, 11
|
|
27
|
+
_TYPE_FLOAT64 = 12
|
|
28
|
+
|
|
29
|
+
# 标量类型的固定字节数与 struct 解包格式
|
|
30
|
+
_SCALAR_FORMATS: dict[int, str] = {
|
|
31
|
+
_TYPE_UINT8: "<B", _TYPE_INT8: "<b",
|
|
32
|
+
_TYPE_UINT16: "<H", _TYPE_INT16: "<h",
|
|
33
|
+
_TYPE_UINT32: "<I", _TYPE_INT32: "<i",
|
|
34
|
+
_TYPE_FLOAT32: "<f", _TYPE_BOOL: "<?",
|
|
35
|
+
_TYPE_UINT64: "<Q", _TYPE_INT64: "<q",
|
|
36
|
+
_TYPE_FLOAT64: "<d",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass
|
|
41
|
+
class ModelInfo:
|
|
42
|
+
"""单个模型的展示信息,字段全部来自文件名或 GGUF 头部。"""
|
|
43
|
+
|
|
44
|
+
path: Path
|
|
45
|
+
name: str
|
|
46
|
+
arch: str = ""
|
|
47
|
+
params: str = ""
|
|
48
|
+
quant: str = ""
|
|
49
|
+
ctx_train: int = 0
|
|
50
|
+
size_bytes: int = 0
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def size_text(self) -> str:
|
|
54
|
+
"""把字节数格式化成便于阅读的 GB/MB 文本。"""
|
|
55
|
+
gb = self.size_bytes / (1024 ** 3)
|
|
56
|
+
if gb >= 1:
|
|
57
|
+
return f"{gb:.1f}G"
|
|
58
|
+
return f"{self.size_bytes / (1024 ** 2):.0f}M"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class _Reader:
|
|
62
|
+
"""极简二进制读取器,只实现 GGUF 头部需要的几种读取方式。"""
|
|
63
|
+
|
|
64
|
+
def __init__(self, handle) -> None:
|
|
65
|
+
self._handle = handle
|
|
66
|
+
|
|
67
|
+
def read(self, count: int) -> bytes:
|
|
68
|
+
"""读固定长度字节,不足则抛错以便上层回退。"""
|
|
69
|
+
data = self._handle.read(count)
|
|
70
|
+
if len(data) != count:
|
|
71
|
+
raise EOFError("GGUF 头部被截断")
|
|
72
|
+
return data
|
|
73
|
+
|
|
74
|
+
def uint32(self) -> int:
|
|
75
|
+
"""读取小端 32 位无符号整数。"""
|
|
76
|
+
return struct.unpack("<I", self.read(4))[0]
|
|
77
|
+
|
|
78
|
+
def uint64(self) -> int:
|
|
79
|
+
"""读取小端 64 位无符号整数。"""
|
|
80
|
+
return struct.unpack("<Q", self.read(8))[0]
|
|
81
|
+
|
|
82
|
+
def string(self) -> str:
|
|
83
|
+
"""读取 GGUF 字符串:64 位长度前缀加 UTF-8 内容。"""
|
|
84
|
+
length = self.uint64()
|
|
85
|
+
return self.read(length).decode("utf-8", errors="replace")
|
|
86
|
+
|
|
87
|
+
def value(self, vtype: int):
|
|
88
|
+
"""按类型编号读取一个元数据值,数组递归读取。"""
|
|
89
|
+
if vtype == _TYPE_STRING:
|
|
90
|
+
return self.string()
|
|
91
|
+
if vtype == _TYPE_ARRAY:
|
|
92
|
+
item_type = self.uint32()
|
|
93
|
+
count = self.uint64()
|
|
94
|
+
return [self.value(item_type) for _ in range(count)]
|
|
95
|
+
fmt = _SCALAR_FORMATS.get(vtype)
|
|
96
|
+
if fmt is None:
|
|
97
|
+
raise ValueError(f"未知 GGUF 类型 {vtype}")
|
|
98
|
+
return struct.unpack(fmt, self.read(struct.calcsize(fmt)))[0]
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _read_metadata(path: Path) -> dict[str, object]:
|
|
102
|
+
"""解析 GGUF 头部键值对,遇到不认识的结构立即放弃并返回已读部分。"""
|
|
103
|
+
meta: dict[str, object] = {}
|
|
104
|
+
with path.open("rb") as handle:
|
|
105
|
+
reader = _Reader(handle)
|
|
106
|
+
if reader.read(4) != GGUF_MAGIC:
|
|
107
|
+
raise ValueError("不是 GGUF 文件")
|
|
108
|
+
reader.uint32() # 版本号,暂不区分
|
|
109
|
+
reader.uint64() # 张量数量,列表展示用不到
|
|
110
|
+
kv_count = reader.uint64()
|
|
111
|
+
for _ in range(kv_count):
|
|
112
|
+
key = reader.string()
|
|
113
|
+
vtype = reader.uint32()
|
|
114
|
+
meta[key] = reader.value(vtype)
|
|
115
|
+
return meta
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _format_params(count: float) -> str:
|
|
119
|
+
"""把参数量换算成 B/M 单位,便于在窄列里显示。"""
|
|
120
|
+
if count >= 1e9:
|
|
121
|
+
return f"{count / 1e9:.1f}B"
|
|
122
|
+
if count >= 1e6:
|
|
123
|
+
return f"{count / 1e6:.0f}M"
|
|
124
|
+
return f"{count:.0f}"
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _estimate_params_from_size(size_bytes: int, quant: str) -> str:
|
|
128
|
+
"""元数据缺失时用文件体积粗估参数量,仅作参考值。"""
|
|
129
|
+
bits = 16.0
|
|
130
|
+
if quant.startswith("Q4"):
|
|
131
|
+
bits = 4.8
|
|
132
|
+
elif quant.startswith("Q5"):
|
|
133
|
+
bits = 5.6
|
|
134
|
+
elif quant.startswith("Q6"):
|
|
135
|
+
bits = 6.6
|
|
136
|
+
elif quant.startswith("Q8"):
|
|
137
|
+
bits = 8.5
|
|
138
|
+
elif quant.startswith("Q3"):
|
|
139
|
+
bits = 3.5
|
|
140
|
+
elif quant.startswith("Q2"):
|
|
141
|
+
bits = 2.6
|
|
142
|
+
count = size_bytes * 8 / bits
|
|
143
|
+
return _format_params(count)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def inspect_model(path: Path) -> ModelInfo:
|
|
147
|
+
"""读取单个模型文件,解析失败时退化为文件名与体积推断。"""
|
|
148
|
+
info = ModelInfo(path=path, name=path.stem, size_bytes=path.stat().st_size)
|
|
149
|
+
try:
|
|
150
|
+
meta = _read_metadata(path)
|
|
151
|
+
except (OSError, EOFError, ValueError, struct.error):
|
|
152
|
+
# 头部损坏或格式不认识时,不阻断列表展示
|
|
153
|
+
return info
|
|
154
|
+
|
|
155
|
+
info.name = str(meta.get("general.name") or path.stem)
|
|
156
|
+
info.arch = str(meta.get("general.architecture") or "")
|
|
157
|
+
file_type = meta.get("general.file_type")
|
|
158
|
+
if isinstance(file_type, int):
|
|
159
|
+
info.quant = FILE_TYPE_NAMES.get(file_type, f"type{file_type}")
|
|
160
|
+
if info.arch:
|
|
161
|
+
ctx_key = f"{info.arch}.context_length"
|
|
162
|
+
params_key = f"{info.arch}.parameter_count"
|
|
163
|
+
ctx_value = meta.get(ctx_key)
|
|
164
|
+
param_value = meta.get(params_key)
|
|
165
|
+
if isinstance(ctx_value, int):
|
|
166
|
+
info.ctx_train = ctx_value
|
|
167
|
+
if isinstance(param_value, int):
|
|
168
|
+
info.params = _format_params(param_value)
|
|
169
|
+
if not info.params:
|
|
170
|
+
info.params = _estimate_params_from_size(info.size_bytes, info.quant)
|
|
171
|
+
return info
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def scan_models(directories: list[str]) -> list[ModelInfo]:
|
|
175
|
+
"""递归扫描目录下的 .gguf 文件,按路径去重并排序。"""
|
|
176
|
+
found: dict[Path, ModelInfo] = {}
|
|
177
|
+
for raw_dir in directories:
|
|
178
|
+
base = Path(raw_dir).expanduser()
|
|
179
|
+
if not base.is_dir():
|
|
180
|
+
continue
|
|
181
|
+
for path in base.rglob("*.gguf"):
|
|
182
|
+
if path.is_file() and path not in found:
|
|
183
|
+
found[path] = inspect_model(path)
|
|
184
|
+
return sorted(found.values(), key=lambda m: (m.name.lower(), m.size_bytes))
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def find_server_binary(configured: str) -> str:
|
|
188
|
+
"""按配置、PATH、常见安装目录的顺序定位 llama-server。"""
|
|
189
|
+
import shutil
|
|
190
|
+
|
|
191
|
+
if configured and Path(configured).expanduser().is_file():
|
|
192
|
+
return str(Path(configured).expanduser())
|
|
193
|
+
which = shutil.which("llama-server")
|
|
194
|
+
if which:
|
|
195
|
+
return which
|
|
196
|
+
candidates = [
|
|
197
|
+
Path.home() / "llama" / "llama-server",
|
|
198
|
+
Path.home() / "llama.cpp" / "build" / "bin" / "llama-server",
|
|
199
|
+
Path("/opt/homebrew/bin/llama-server"),
|
|
200
|
+
Path("/usr/local/bin/llama-server"),
|
|
201
|
+
]
|
|
202
|
+
for candidate in candidates:
|
|
203
|
+
if candidate.is_file():
|
|
204
|
+
return str(candidate)
|
|
205
|
+
return ""
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""llama-server 进程管理:挑选端口、拉起进程、等待健康检查、优雅退出。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import shlex
|
|
6
|
+
import socket
|
|
7
|
+
import subprocess
|
|
8
|
+
import time
|
|
9
|
+
from collections import deque
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def pick_free_port() -> int:
|
|
17
|
+
"""让系统分配一个空闲端口,避免与其他服务冲突。"""
|
|
18
|
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
19
|
+
sock.bind(("127.0.0.1", 0))
|
|
20
|
+
return sock.getsockname()[1]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def detect_jinja_support(binary: str) -> bool:
|
|
24
|
+
"""读取 help 输出判断该版本是否支持 --jinja,避免老版本启动即报错。"""
|
|
25
|
+
try:
|
|
26
|
+
result = subprocess.run(
|
|
27
|
+
[binary, "--help"], capture_output=True, text=True, timeout=10
|
|
28
|
+
)
|
|
29
|
+
return "--jinja" in (result.stdout + result.stderr)
|
|
30
|
+
except (OSError, subprocess.SubprocessError):
|
|
31
|
+
return False
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ServerConfig:
|
|
36
|
+
"""启动一次 llama-server 所需的全部参数。"""
|
|
37
|
+
|
|
38
|
+
binary: str
|
|
39
|
+
model: str
|
|
40
|
+
ctx_size: int = 8192
|
|
41
|
+
n_gpu_layers: int = 99
|
|
42
|
+
port: int = 0 # 0 表示自动挑选
|
|
43
|
+
threads: int = -1
|
|
44
|
+
cache_type_k: str = "f16"
|
|
45
|
+
cache_type_v: str = "f16"
|
|
46
|
+
keep_tokens: int = 0
|
|
47
|
+
context_shift: bool = True
|
|
48
|
+
metrics: bool = False
|
|
49
|
+
json_schema_file: str = ""
|
|
50
|
+
slot_save_path: str = ""
|
|
51
|
+
draft_model: str = ""
|
|
52
|
+
draft_max: int = 4
|
|
53
|
+
thinking: str = "auto"
|
|
54
|
+
reasoning_budget: int = -1
|
|
55
|
+
dry_multiplier: float = 0.0
|
|
56
|
+
extra_args: str = ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class LlamaServer:
|
|
60
|
+
"""把 llama-server 的生命周期封装成可预测的 start/stop。"""
|
|
61
|
+
|
|
62
|
+
def __init__(self) -> None:
|
|
63
|
+
# 进程句柄,None 表示当前没有运行中的 server
|
|
64
|
+
self.process: subprocess.Popen | None = None
|
|
65
|
+
# 实际监听端口,启动后才有意义
|
|
66
|
+
self.port: int = 0
|
|
67
|
+
# 对外暴露的基地址,如 http://127.0.0.1:8080
|
|
68
|
+
self.base_url: str = ""
|
|
69
|
+
# 保留最近 200 行日志,启动失败时用来展示原因
|
|
70
|
+
self.log_lines: deque[str] = deque(maxlen=200)
|
|
71
|
+
|
|
72
|
+
def start(self, config: ServerConfig, timeout: float = 90.0) -> None:
|
|
73
|
+
"""启动进程并轮询健康检查,超时或提前退出都抛出带日志的异常。"""
|
|
74
|
+
self.stop()
|
|
75
|
+
self.port = config.port or pick_free_port()
|
|
76
|
+
self.base_url = f"http://127.0.0.1:{self.port}"
|
|
77
|
+
self.log_lines.clear()
|
|
78
|
+
|
|
79
|
+
command = [
|
|
80
|
+
config.binary,
|
|
81
|
+
"--model", str(Path(config.model).expanduser()),
|
|
82
|
+
"--host", "127.0.0.1",
|
|
83
|
+
"--port", str(self.port),
|
|
84
|
+
"--ctx-size", str(config.ctx_size),
|
|
85
|
+
"--n-gpu-layers", str(config.n_gpu_layers),
|
|
86
|
+
]
|
|
87
|
+
# 只有确认支持时才加 --jinja,否则老版本会直接拒绝启动
|
|
88
|
+
if detect_jinja_support(config.binary):
|
|
89
|
+
command.append("--jinja")
|
|
90
|
+
# 以下参数只在偏离默认值时追加,避免命令冗长
|
|
91
|
+
if config.threads > 0:
|
|
92
|
+
command += ["--threads", str(config.threads)]
|
|
93
|
+
if config.cache_type_k and config.cache_type_k != "f16":
|
|
94
|
+
command += ["--cache-type-k", config.cache_type_k]
|
|
95
|
+
if config.cache_type_v and config.cache_type_v != "f16":
|
|
96
|
+
command += ["--cache-type-v", config.cache_type_v]
|
|
97
|
+
if config.keep_tokens != 0:
|
|
98
|
+
command += ["--keep", str(config.keep_tokens)]
|
|
99
|
+
if not config.context_shift:
|
|
100
|
+
command.append("--no-context-shift")
|
|
101
|
+
if config.metrics:
|
|
102
|
+
command.append("--metrics")
|
|
103
|
+
if config.json_schema_file:
|
|
104
|
+
command += ["--json-schema-file", str(Path(config.json_schema_file).expanduser())]
|
|
105
|
+
if config.slot_save_path:
|
|
106
|
+
command += ["--slot-save-path", str(Path(config.slot_save_path).expanduser())]
|
|
107
|
+
if config.draft_model:
|
|
108
|
+
command += ["--model-draft", str(Path(config.draft_model).expanduser())]
|
|
109
|
+
command += ["--spec-draft-n-max", str(config.draft_max)]
|
|
110
|
+
if config.thinking in ("on", "off"):
|
|
111
|
+
command += ["--reasoning", config.thinking]
|
|
112
|
+
if config.reasoning_budget >= 0 and config.thinking != "off":
|
|
113
|
+
command += ["--reasoning-budget", str(config.reasoning_budget)]
|
|
114
|
+
if config.dry_multiplier > 0:
|
|
115
|
+
command += ["--dry-multiplier", str(config.dry_multiplier)]
|
|
116
|
+
# 自由追加参数放在最后,允许用户覆盖前面的所有设置
|
|
117
|
+
if config.extra_args.strip():
|
|
118
|
+
try:
|
|
119
|
+
command += shlex.split(config.extra_args)
|
|
120
|
+
except ValueError:
|
|
121
|
+
pass
|
|
122
|
+
|
|
123
|
+
self.log_lines.append("$ " + " ".join(command))
|
|
124
|
+
self.process = subprocess.Popen(
|
|
125
|
+
command,
|
|
126
|
+
stdout=subprocess.PIPE,
|
|
127
|
+
stderr=subprocess.STDOUT,
|
|
128
|
+
text=True,
|
|
129
|
+
bufsize=1,
|
|
130
|
+
)
|
|
131
|
+
self._wait_until_ready(timeout)
|
|
132
|
+
|
|
133
|
+
def _wait_until_ready(self, timeout: float) -> None:
|
|
134
|
+
"""轮询 /health,同时检查进程是否已经异常退出。"""
|
|
135
|
+
deadline = time.monotonic() + timeout
|
|
136
|
+
with httpx.Client(timeout=2.0) as client:
|
|
137
|
+
while time.monotonic() < deadline:
|
|
138
|
+
if self.process is not None and self.process.poll() is not None:
|
|
139
|
+
self._drain_log()
|
|
140
|
+
detail = "\n".join(list(self.log_lines)[-8:])
|
|
141
|
+
raise RuntimeError(f"llama-server 启动失败:\n{detail}")
|
|
142
|
+
try:
|
|
143
|
+
response = client.get(f"{self.base_url}/health")
|
|
144
|
+
if response.status_code == 200:
|
|
145
|
+
self._drain_log()
|
|
146
|
+
return
|
|
147
|
+
except httpx.HTTPError:
|
|
148
|
+
pass
|
|
149
|
+
time.sleep(0.3)
|
|
150
|
+
self._drain_log()
|
|
151
|
+
raise TimeoutError(f"等待 llama-server 就绪超时({timeout:.0f} 秒)")
|
|
152
|
+
|
|
153
|
+
def _drain_log(self) -> None:
|
|
154
|
+
"""非阻塞地读走已输出的日志行,避免管道写满卡死子进程。"""
|
|
155
|
+
if self.process is None or self.process.stdout is None:
|
|
156
|
+
return
|
|
157
|
+
while True:
|
|
158
|
+
line = self.process.stdout.readline()
|
|
159
|
+
if not line:
|
|
160
|
+
break
|
|
161
|
+
self.log_lines.append(line.rstrip())
|
|
162
|
+
|
|
163
|
+
def is_alive(self) -> bool:
|
|
164
|
+
"""判断 server 是否仍在运行,供界面刷新状态用。"""
|
|
165
|
+
return self.process is not None and self.process.poll() is None
|
|
166
|
+
|
|
167
|
+
def stop(self) -> None:
|
|
168
|
+
"""先请求正常退出,超时再强制结束,确保端口被释放。"""
|
|
169
|
+
if self.process is None:
|
|
170
|
+
return
|
|
171
|
+
if self.process.poll() is None:
|
|
172
|
+
self.process.terminate()
|
|
173
|
+
try:
|
|
174
|
+
self.process.wait(timeout=5)
|
|
175
|
+
except subprocess.TimeoutExpired:
|
|
176
|
+
self.process.kill()
|
|
177
|
+
self.process.wait(timeout=5)
|
|
178
|
+
self.process = None
|
|
179
|
+
self.base_url = ""
|
|
180
|
+
self.port = 0
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""终端底层工具:ANSI 着色、清屏、局部重绘与单键读取。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import select
|
|
7
|
+
import sys
|
|
8
|
+
import termios
|
|
9
|
+
import tty
|
|
10
|
+
|
|
11
|
+
# ANSI 样式码,只改变前景色,不设置背景色,保留终端自身配色
|
|
12
|
+
RESET = "\033[0m"
|
|
13
|
+
BOLD = "\033[1m"
|
|
14
|
+
DIM = "\033[90m"
|
|
15
|
+
RED = "\033[31m"
|
|
16
|
+
GREEN = "\033[32m"
|
|
17
|
+
YELLOW = "\033[33m"
|
|
18
|
+
CYAN = "\033[36m"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def paint(text: str, *codes: str) -> str:
|
|
22
|
+
"""给文本套上样式,结尾恢复默认,避免影响后续输出。"""
|
|
23
|
+
return "".join(codes) + text + RESET
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def clear_screen() -> None:
|
|
27
|
+
"""清屏并把光标移回左上角,用于整页重绘。"""
|
|
28
|
+
sys.stdout.write("\033[H\033[2J")
|
|
29
|
+
sys.stdout.flush()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def erase_lines(count: int) -> None:
|
|
33
|
+
"""把光标上移若干行并清除到屏幕末尾,用于擦掉菜单再重绘。"""
|
|
34
|
+
if count > 0:
|
|
35
|
+
sys.stdout.write(f"\033[{count}A")
|
|
36
|
+
sys.stdout.write("\033[J")
|
|
37
|
+
sys.stdout.flush()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def read_key() -> str:
|
|
41
|
+
"""在单键模式下读取一个按键,把方向键转成 up/down。"""
|
|
42
|
+
fd = sys.stdin.fileno()
|
|
43
|
+
char = os.read(fd, 1).decode("utf-8", errors="ignore")
|
|
44
|
+
if char == "\x1b":
|
|
45
|
+
# 单独的 Esc 与方向键前缀相同,用短暂等待区分
|
|
46
|
+
ready, _, _ = select.select([fd], [], [], 0.03)
|
|
47
|
+
if ready:
|
|
48
|
+
rest = os.read(fd, 2).decode("utf-8", errors="ignore")
|
|
49
|
+
if rest == "[A":
|
|
50
|
+
return "up"
|
|
51
|
+
if rest == "[B":
|
|
52
|
+
return "down"
|
|
53
|
+
return "esc"
|
|
54
|
+
if char in ("\r", "\n"):
|
|
55
|
+
return "enter"
|
|
56
|
+
if char == "\x03":
|
|
57
|
+
raise KeyboardInterrupt
|
|
58
|
+
return char
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Cbreak:
|
|
62
|
+
"""进入单键读取模式的上下文管理器,退出时恢复终端原有设置。"""
|
|
63
|
+
|
|
64
|
+
def __enter__(self) -> "Cbreak":
|
|
65
|
+
self.fd = sys.stdin.fileno()
|
|
66
|
+
self.old = termios.tcgetattr(self.fd)
|
|
67
|
+
tty.setcbreak(self.fd)
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
def __exit__(self, *exc_info) -> None:
|
|
71
|
+
termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llmgui
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: llama.cpp 的终端交互前端:模型选择、参数调节与带速度统计的流式对话
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: llama.cpp,llm,tui,terminal,gguf
|
|
7
|
+
Classifier: Environment :: Console
|
|
8
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
9
|
+
Classifier: Operating System :: MacOS
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
llmgui/__init__.py
|
|
3
|
+
llmgui/__main__.py
|
|
4
|
+
llmgui/app.py
|
|
5
|
+
llmgui/client.py
|
|
6
|
+
llmgui/config.py
|
|
7
|
+
llmgui/models.py
|
|
8
|
+
llmgui/server.py
|
|
9
|
+
llmgui/terminal.py
|
|
10
|
+
llmgui.egg-info/PKG-INFO
|
|
11
|
+
llmgui.egg-info/SOURCES.txt
|
|
12
|
+
llmgui.egg-info/dependency_links.txt
|
|
13
|
+
llmgui.egg-info/entry_points.txt
|
|
14
|
+
llmgui.egg-info/requires.txt
|
|
15
|
+
llmgui.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
httpx>=0.27
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
llmgui
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "llmgui"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "llama.cpp 的终端交互前端:模型选择、参数调节与带速度统计的流式对话"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = ["httpx>=0.27"]
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
keywords = ["llama.cpp", "llm", "tui", "terminal", "gguf"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Environment :: Console",
|
|
15
|
+
"Intended Audience :: End Users/Desktop",
|
|
16
|
+
"Operating System :: MacOS",
|
|
17
|
+
"Operating System :: POSIX :: Linux",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
lg = "llmgui.app:main"
|
|
24
|
+
llmgui = "llmgui.app:main"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools.packages.find]
|
|
27
|
+
include = ["llmgui*"]
|
llmgui-0.1.0/setup.cfg
ADDED