maque 0.2.1__py3-none-any.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.
- maque/__init__.py +30 -0
- maque/__main__.py +926 -0
- maque/ai_platform/__init__.py +0 -0
- maque/ai_platform/crawl.py +45 -0
- maque/ai_platform/metrics.py +258 -0
- maque/ai_platform/nlp_preprocess.py +67 -0
- maque/ai_platform/webpage_screen_shot.py +195 -0
- maque/algorithms/__init__.py +78 -0
- maque/algorithms/bezier.py +15 -0
- maque/algorithms/bktree.py +117 -0
- maque/algorithms/core.py +104 -0
- maque/algorithms/hilbert.py +16 -0
- maque/algorithms/rate_function.py +92 -0
- maque/algorithms/transform.py +27 -0
- maque/algorithms/trie.py +272 -0
- maque/algorithms/utils.py +63 -0
- maque/algorithms/video.py +587 -0
- maque/api/__init__.py +1 -0
- maque/api/common.py +110 -0
- maque/api/fetch.py +26 -0
- maque/api/static/icon.png +0 -0
- maque/api/static/redoc.standalone.js +1782 -0
- maque/api/static/swagger-ui-bundle.js +3 -0
- maque/api/static/swagger-ui.css +3 -0
- maque/cli/__init__.py +1 -0
- maque/cli/clean_invisible_chars.py +324 -0
- maque/cli/core.py +34 -0
- maque/cli/groups/__init__.py +26 -0
- maque/cli/groups/config.py +205 -0
- maque/cli/groups/data.py +615 -0
- maque/cli/groups/doctor.py +259 -0
- maque/cli/groups/embedding.py +222 -0
- maque/cli/groups/git.py +29 -0
- maque/cli/groups/help.py +410 -0
- maque/cli/groups/llm.py +223 -0
- maque/cli/groups/mcp.py +241 -0
- maque/cli/groups/mllm.py +1795 -0
- maque/cli/groups/mllm_simple.py +60 -0
- maque/cli/groups/quant.py +210 -0
- maque/cli/groups/service.py +490 -0
- maque/cli/groups/system.py +570 -0
- maque/cli/mllm_run.py +1451 -0
- maque/cli/script.py +52 -0
- maque/cli/tree.py +49 -0
- maque/clustering/__init__.py +52 -0
- maque/clustering/analyzer.py +347 -0
- maque/clustering/clusterers.py +464 -0
- maque/clustering/sampler.py +134 -0
- maque/clustering/visualizer.py +205 -0
- maque/constant.py +13 -0
- maque/core.py +133 -0
- maque/cv/__init__.py +1 -0
- maque/cv/image.py +219 -0
- maque/cv/utils.py +68 -0
- maque/cv/video/__init__.py +3 -0
- maque/cv/video/keyframe_extractor.py +368 -0
- maque/embedding/__init__.py +43 -0
- maque/embedding/base.py +56 -0
- maque/embedding/multimodal.py +308 -0
- maque/embedding/server.py +523 -0
- maque/embedding/text.py +311 -0
- maque/git/__init__.py +24 -0
- maque/git/pure_git.py +912 -0
- maque/io/__init__.py +29 -0
- maque/io/core.py +38 -0
- maque/io/ops.py +194 -0
- maque/llm/__init__.py +111 -0
- maque/llm/backend.py +416 -0
- maque/llm/base.py +411 -0
- maque/llm/server.py +366 -0
- maque/mcp_server.py +1096 -0
- maque/mllm_data_processor_pipeline/__init__.py +17 -0
- maque/mllm_data_processor_pipeline/core.py +341 -0
- maque/mllm_data_processor_pipeline/example.py +291 -0
- maque/mllm_data_processor_pipeline/steps/__init__.py +56 -0
- maque/mllm_data_processor_pipeline/steps/data_alignment.py +267 -0
- maque/mllm_data_processor_pipeline/steps/data_loader.py +172 -0
- maque/mllm_data_processor_pipeline/steps/data_validation.py +304 -0
- maque/mllm_data_processor_pipeline/steps/format_conversion.py +411 -0
- maque/mllm_data_processor_pipeline/steps/mllm_annotation.py +331 -0
- maque/mllm_data_processor_pipeline/steps/mllm_refinement.py +446 -0
- maque/mllm_data_processor_pipeline/steps/result_validation.py +501 -0
- maque/mllm_data_processor_pipeline/web_app.py +317 -0
- maque/nlp/__init__.py +14 -0
- maque/nlp/ngram.py +9 -0
- maque/nlp/parser.py +63 -0
- maque/nlp/risk_matcher.py +543 -0
- maque/nlp/sentence_splitter.py +202 -0
- maque/nlp/simple_tradition_cvt.py +31 -0
- maque/performance/__init__.py +21 -0
- maque/performance/_measure_time.py +70 -0
- maque/performance/_profiler.py +367 -0
- maque/performance/_stat_memory.py +51 -0
- maque/pipelines/__init__.py +15 -0
- maque/pipelines/clustering.py +252 -0
- maque/quantization/__init__.py +42 -0
- maque/quantization/auto_round.py +120 -0
- maque/quantization/base.py +145 -0
- maque/quantization/bitsandbytes.py +127 -0
- maque/quantization/llm_compressor.py +102 -0
- maque/retriever/__init__.py +35 -0
- maque/retriever/chroma.py +654 -0
- maque/retriever/document.py +140 -0
- maque/retriever/milvus.py +1140 -0
- maque/table_ops/__init__.py +1 -0
- maque/table_ops/core.py +133 -0
- maque/table_viewer/__init__.py +4 -0
- maque/table_viewer/download_assets.py +57 -0
- maque/table_viewer/server.py +698 -0
- maque/table_viewer/static/element-plus-icons.js +5791 -0
- maque/table_viewer/static/element-plus.css +1 -0
- maque/table_viewer/static/element-plus.js +65236 -0
- maque/table_viewer/static/main.css +268 -0
- maque/table_viewer/static/main.js +669 -0
- maque/table_viewer/static/vue.global.js +18227 -0
- maque/table_viewer/templates/index.html +401 -0
- maque/utils/__init__.py +56 -0
- maque/utils/color.py +68 -0
- maque/utils/color_string.py +45 -0
- maque/utils/compress.py +66 -0
- maque/utils/constant.py +183 -0
- maque/utils/core.py +261 -0
- maque/utils/cursor.py +143 -0
- maque/utils/distance.py +58 -0
- maque/utils/docker.py +96 -0
- maque/utils/downloads.py +51 -0
- maque/utils/excel_helper.py +542 -0
- maque/utils/helper_metrics.py +121 -0
- maque/utils/helper_parser.py +168 -0
- maque/utils/net.py +64 -0
- maque/utils/nvidia_stat.py +140 -0
- maque/utils/ops.py +53 -0
- maque/utils/packages.py +31 -0
- maque/utils/path.py +57 -0
- maque/utils/tar.py +260 -0
- maque/utils/untar.py +129 -0
- maque/web/__init__.py +0 -0
- maque/web/image_downloader.py +1410 -0
- maque-0.2.1.dist-info/METADATA +450 -0
- maque-0.2.1.dist-info/RECORD +143 -0
- maque-0.2.1.dist-info/WHEEL +4 -0
- maque-0.2.1.dist-info/entry_points.txt +3 -0
- maque-0.2.1.dist-info/licenses/LICENSE +21 -0
maque/cli/groups/mcp.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""MCP Server 命令组"""
|
|
2
|
+
import subprocess
|
|
3
|
+
|
|
4
|
+
from rich import print
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MCPGroup:
|
|
10
|
+
"""MCP Server 管理命令组
|
|
11
|
+
|
|
12
|
+
提供 maque 的 MCP (Model Context Protocol) 服务管理功能,
|
|
13
|
+
让 AI Agent 能够查询 maque 的 API 文档。
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, cli_instance):
|
|
17
|
+
self.cli = cli_instance
|
|
18
|
+
self.console = Console()
|
|
19
|
+
|
|
20
|
+
def serve(self, port: int = 8765, host: str = "0.0.0.0"):
|
|
21
|
+
"""启动 MCP Server(SSE 模式,独立 HTTP 服务)
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
port: 服务端口,默认 8765
|
|
25
|
+
host: 绑定地址,默认 0.0.0.0
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
maque mcp serve
|
|
29
|
+
maque mcp serve --port=9000
|
|
30
|
+
"""
|
|
31
|
+
from maque.mcp_server import main_sse
|
|
32
|
+
|
|
33
|
+
print(f"[bold blue]启动 MCP Server (SSE 模式)[/bold blue]")
|
|
34
|
+
print(f" 地址: http://{host}:{port}")
|
|
35
|
+
print(f" 配置: claude mcp add maque --transport sse --url http://localhost:{port}/sse")
|
|
36
|
+
print()
|
|
37
|
+
|
|
38
|
+
main_sse(host=host, port=port)
|
|
39
|
+
|
|
40
|
+
def install(self, scope: str = "user", name: str = "maque"):
|
|
41
|
+
"""将 MCP Server 配置到 Claude Code
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
scope: 配置作用域,'user' 或 'project',默认 'user'
|
|
45
|
+
name: MCP Server 名称,默认 'maque'
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
maque mcp install
|
|
49
|
+
maque mcp install --scope=project
|
|
50
|
+
"""
|
|
51
|
+
cmd = [
|
|
52
|
+
"claude", "mcp", "add", name,
|
|
53
|
+
f"--scope={scope}",
|
|
54
|
+
"--",
|
|
55
|
+
"python", "-m", "maque.mcp_server"
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
print(f"[blue]配置 MCP Server 到 Claude Code...[/blue]")
|
|
59
|
+
print(f" 作用域: {scope}")
|
|
60
|
+
print()
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
64
|
+
if result.returncode == 0:
|
|
65
|
+
print(f"[green]✓ MCP Server '{name}' 已配置[/green]")
|
|
66
|
+
print(f" 重启 Claude Code 后生效")
|
|
67
|
+
print(f" 验证: 在 Claude Code 中输入 /mcp")
|
|
68
|
+
else:
|
|
69
|
+
print(f"[red]配置失败: {result.stderr}[/red]")
|
|
70
|
+
except FileNotFoundError:
|
|
71
|
+
print("[red]错误: 未找到 claude 命令[/red]")
|
|
72
|
+
print("请确保已安装 Claude Code CLI")
|
|
73
|
+
|
|
74
|
+
def uninstall(self, name: str = "maque", scope: str = "user"):
|
|
75
|
+
"""从 Claude Code 移除 MCP Server 配置
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
name: MCP Server 名称,默认 'maque'
|
|
79
|
+
scope: 配置作用域,默认 'user'
|
|
80
|
+
|
|
81
|
+
Examples:
|
|
82
|
+
maque mcp uninstall
|
|
83
|
+
"""
|
|
84
|
+
cmd = ["claude", "mcp", "remove", name, f"--scope={scope}"]
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
result = subprocess.run(cmd, capture_output=True, text=True)
|
|
88
|
+
if result.returncode == 0:
|
|
89
|
+
print(f"[green]✓ MCP Server '{name}' 已移除[/green]")
|
|
90
|
+
else:
|
|
91
|
+
print(f"[red]移除失败: {result.stderr}[/red]")
|
|
92
|
+
except FileNotFoundError:
|
|
93
|
+
print("[red]错误: 未找到 claude 命令[/red]")
|
|
94
|
+
|
|
95
|
+
def status(self):
|
|
96
|
+
"""查看 MCP Server 配置状态
|
|
97
|
+
|
|
98
|
+
Examples:
|
|
99
|
+
maque mcp status
|
|
100
|
+
"""
|
|
101
|
+
try:
|
|
102
|
+
result = subprocess.run(
|
|
103
|
+
["claude", "mcp", "list"],
|
|
104
|
+
capture_output=True,
|
|
105
|
+
text=True
|
|
106
|
+
)
|
|
107
|
+
print("[bold blue]Claude Code MCP 配置状态[/bold blue]\n")
|
|
108
|
+
print(result.stdout)
|
|
109
|
+
if result.stderr:
|
|
110
|
+
print(result.stderr)
|
|
111
|
+
except FileNotFoundError:
|
|
112
|
+
print("[red]错误: 未找到 claude 命令[/red]")
|
|
113
|
+
|
|
114
|
+
def test(self, with_llm: bool = False):
|
|
115
|
+
"""测试 MCP Server 功能
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
with_llm: 是否测试 LLM 调用功能(需要 LLM 服务运行中)
|
|
119
|
+
|
|
120
|
+
Examples:
|
|
121
|
+
maque mcp test
|
|
122
|
+
maque mcp test --with_llm
|
|
123
|
+
"""
|
|
124
|
+
print("[bold blue]测试 MCP Server 功能[/bold blue]\n")
|
|
125
|
+
|
|
126
|
+
from maque.mcp_server import search_maque, get_module_info, list_all_modules
|
|
127
|
+
|
|
128
|
+
# 测试 list_modules
|
|
129
|
+
print("[cyan]1. 测试 list_maque_modules()[/cyan]")
|
|
130
|
+
modules = list_all_modules()
|
|
131
|
+
print(f" 返回 {len(modules.split('##')) - 1} 个模块")
|
|
132
|
+
print("[green] ✓ 通过[/green]\n")
|
|
133
|
+
|
|
134
|
+
# 测试 search
|
|
135
|
+
print("[cyan]2. 测试 search_maque_api('embedding')[/cyan]")
|
|
136
|
+
results = search_maque("embedding")
|
|
137
|
+
print(f" 找到 {len(results)} 个结果")
|
|
138
|
+
if results:
|
|
139
|
+
print(f" 首个结果: {results[0].name} ({results[0].module})")
|
|
140
|
+
print("[green] ✓ 通过[/green]\n")
|
|
141
|
+
|
|
142
|
+
# 测试 get_module_usage
|
|
143
|
+
print("[cyan]3. 测试 get_module_usage('mllm')[/cyan]")
|
|
144
|
+
usage = get_module_info("mllm")
|
|
145
|
+
print(f" 返回 {len(usage)} 字符的使用示例")
|
|
146
|
+
print("[green] ✓ 通过[/green]\n")
|
|
147
|
+
|
|
148
|
+
# 测试 LLM 配置
|
|
149
|
+
print("[cyan]4. 测试 llm_config()[/cyan]")
|
|
150
|
+
from maque.mcp_server import llm_config
|
|
151
|
+
config = llm_config()
|
|
152
|
+
print(f" base_url: {config.get('base_url')}")
|
|
153
|
+
print(f" model: {config.get('model')}")
|
|
154
|
+
print("[green] ✓ 通过[/green]\n")
|
|
155
|
+
|
|
156
|
+
# 可选:测试 LLM 调用
|
|
157
|
+
if with_llm:
|
|
158
|
+
import asyncio
|
|
159
|
+
print("[cyan]5. 测试 llm_chat()[/cyan]")
|
|
160
|
+
from maque.mcp_server import llm_chat
|
|
161
|
+
try:
|
|
162
|
+
result = asyncio.run(llm_chat(
|
|
163
|
+
messages=[{"role": "user", "content": "说'测试成功'三个字"}],
|
|
164
|
+
max_tokens=20,
|
|
165
|
+
))
|
|
166
|
+
print(f" LLM 回复: {result[:50]}...")
|
|
167
|
+
print("[green] ✓ 通过[/green]\n")
|
|
168
|
+
except Exception as e:
|
|
169
|
+
print(f"[red] ✗ LLM 调用失败: {e}[/red]\n")
|
|
170
|
+
else:
|
|
171
|
+
print("[dim]跳过 LLM 调用测试(使用 --with_llm 启用)[/dim]\n")
|
|
172
|
+
|
|
173
|
+
print("[bold green]测试完成![/bold green]")
|
|
174
|
+
|
|
175
|
+
def tools(self):
|
|
176
|
+
"""列出 MCP Server 提供的工具
|
|
177
|
+
|
|
178
|
+
Examples:
|
|
179
|
+
maque mcp tools
|
|
180
|
+
"""
|
|
181
|
+
# API 文档查询工具
|
|
182
|
+
table1 = Table(title="API 文档查询工具", show_header=True)
|
|
183
|
+
table1.add_column("工具名", style="cyan")
|
|
184
|
+
table1.add_column("说明", style="green")
|
|
185
|
+
table1.add_column("参数", style="yellow")
|
|
186
|
+
|
|
187
|
+
table1.add_row(
|
|
188
|
+
"search_maque_api",
|
|
189
|
+
"搜索 maque 中的 API(类、函数、模块)",
|
|
190
|
+
"keyword: str"
|
|
191
|
+
)
|
|
192
|
+
table1.add_row(
|
|
193
|
+
"get_module_usage",
|
|
194
|
+
"获取模块的详细使用示例",
|
|
195
|
+
"module: str"
|
|
196
|
+
)
|
|
197
|
+
table1.add_row(
|
|
198
|
+
"list_maque_modules",
|
|
199
|
+
"列出所有核心模块",
|
|
200
|
+
"无"
|
|
201
|
+
)
|
|
202
|
+
table1.add_row(
|
|
203
|
+
"list_cli_commands",
|
|
204
|
+
"列出所有 CLI 命令",
|
|
205
|
+
"无"
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
self.console.print(table1)
|
|
209
|
+
print()
|
|
210
|
+
|
|
211
|
+
# LLM 调用工具
|
|
212
|
+
table2 = Table(title="LLM 调用工具", show_header=True)
|
|
213
|
+
table2.add_column("工具名", style="cyan")
|
|
214
|
+
table2.add_column("说明", style="green")
|
|
215
|
+
table2.add_column("参数", style="yellow")
|
|
216
|
+
|
|
217
|
+
table2.add_row(
|
|
218
|
+
"llm_chat",
|
|
219
|
+
"调用 LLM 进行单条聊天",
|
|
220
|
+
"messages, model?, max_tokens?, temperature?"
|
|
221
|
+
)
|
|
222
|
+
table2.add_row(
|
|
223
|
+
"llm_chat_batch",
|
|
224
|
+
"批量调用 LLM",
|
|
225
|
+
"messages_list, model?, max_tokens?, temperature?"
|
|
226
|
+
)
|
|
227
|
+
table2.add_row(
|
|
228
|
+
"llm_models",
|
|
229
|
+
"获取可用模型列表",
|
|
230
|
+
"无"
|
|
231
|
+
)
|
|
232
|
+
table2.add_row(
|
|
233
|
+
"llm_config",
|
|
234
|
+
"获取当前 LLM 配置",
|
|
235
|
+
"无"
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
self.console.print(table2)
|
|
239
|
+
|
|
240
|
+
print("\n[dim]在 Claude Code 中,AI 会自动调用这些工具[/dim]")
|
|
241
|
+
print("[dim]LLM 配置来自 ~/.maque/config.yaml 或项目中的 maque_config.yaml[/dim]")
|