cnhkmcp 2.0.3__py3-none-any.whl → 2.1.0__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.
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/README.md +38 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/config.json +6 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/ace_lib.py +1510 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_datasets.py +157 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_documentation.py +132 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/fetch_all_operators.py +99 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/get_knowledgeBase_tool/helpful_functions.py +180 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.ico +0 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/icon.png +0 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/knowledge/test.txt +1 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/main.py +581 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/process_knowledge_base.py +280 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/rag_engine.py +265 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/requirements.txt +12 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/run.bat +3 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242/vector_db/chroma.sqlite3 +0 -0
- cnhkmcp/untracked/AI/321/206/320/261/320/234/321/211/320/255/320/262/321/206/320/237/320/242/321/204/342/225/227/342/225/242//321/211/320/266/320/246/321/206/320/274/320/261/321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +265 -0
- cnhkmcp/untracked/APP/Tranformer/Transformer.py +2804 -11
- cnhkmcp/untracked/APP/Tranformer/output/Alpha_candidates.json +1524 -889
- cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_error.json +884 -111
- cnhkmcp/untracked/APP/Tranformer/output/Alpha_generated_expressions_success.json +442 -168
- cnhkmcp/untracked/APP/Tranformer/template_summary.txt +2775 -1
- cnhkmcp/untracked/APP/ace.log +2 -0
- cnhkmcp/untracked/APP/give_me_idea/fetch_all_datasets.py +157 -0
- cnhkmcp/untracked/APP/give_me_idea/fetch_all_operators.py +99 -0
- cnhkmcp/untracked/APP/simulator/simulator_wqb.py +16 -16
- cnhkmcp/untracked/APP/static/brain.js +61 -0
- cnhkmcp/untracked/APP/static/script.js +140 -0
- cnhkmcp/untracked/APP/templates/index.html +25 -4
- cnhkmcp/untracked/APP//321/210/342/224/220/320/240/321/210/320/261/320/234/321/206/320/231/320/243/321/205/342/225/235/320/220/321/206/320/230/320/241.py +70 -8
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/METADATA +1 -1
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/RECORD +36 -20
- cnhkmcp/untracked/APP/hkSimulator/ace.log +0 -0
- cnhkmcp/untracked/APP/hkSimulator/autosim_20251205_145240.log +0 -0
- cnhkmcp/untracked/APP/hkSimulator/autosim_20251215_030103.log +0 -0
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/WHEEL +0 -0
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/entry_points.txt +0 -0
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/licenses/LICENSE +0 -0
- {cnhkmcp-2.0.3.dist-info → cnhkmcp-2.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"""
|
|
2
|
+
首次运行初始化脚本
|
|
3
|
+
- 创建桌面快捷方式指向 main.py,用 Python 运行,图标为 icon.png
|
|
4
|
+
- 检查 knowledge 文件夹文件数量
|
|
5
|
+
- 如果 <= 3,提示用户建立知识库,并自动运行 process_knowledge_base.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
import subprocess
|
|
11
|
+
import shutil
|
|
12
|
+
import json
|
|
13
|
+
import platform
|
|
14
|
+
import urllib.parse
|
|
15
|
+
import urllib.request
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
# 获取脚本所在目录(项目根目录)
|
|
19
|
+
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
20
|
+
MAIN_SCRIPT = os.path.join(PROJECT_DIR, "main.py")
|
|
21
|
+
ICON_ICO = os.path.join(PROJECT_DIR, "icon.ico")
|
|
22
|
+
ICON_PNG = os.path.join(PROJECT_DIR, "icon.png")
|
|
23
|
+
KNOWLEDGE_DIR = os.path.join(PROJECT_DIR, "knowledge")
|
|
24
|
+
PROCESS_SCRIPT = os.path.join(PROJECT_DIR, "process_knowledge_base.py")
|
|
25
|
+
CONFIG_PATH = os.path.join(PROJECT_DIR, "config.json")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def load_config():
|
|
29
|
+
if not os.path.exists(CONFIG_PATH):
|
|
30
|
+
return {}
|
|
31
|
+
try:
|
|
32
|
+
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
|
|
33
|
+
return json.load(f) or {}
|
|
34
|
+
except Exception as exc:
|
|
35
|
+
print(f"✗ 读取 config.json 失败:{exc}")
|
|
36
|
+
return {}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def save_config(cfg):
|
|
40
|
+
try:
|
|
41
|
+
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
|
42
|
+
json.dump(cfg, f, ensure_ascii=False, indent=4)
|
|
43
|
+
print(f"✓ 配置已写入:{CONFIG_PATH}")
|
|
44
|
+
except Exception as exc:
|
|
45
|
+
print(f"✗ 写入 config.json 失败:{exc}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def check_network_reachable(url="https://www.google.com/generate_204", timeout_ms=2000):
|
|
49
|
+
"""Check connectivity via ping + lightweight HTTPS GET. Returns True if either succeeds."""
|
|
50
|
+
parsed = urllib.parse.urlparse(url)
|
|
51
|
+
host = parsed.hostname or "google.com"
|
|
52
|
+
is_windows = platform.system().lower().startswith("win")
|
|
53
|
+
if is_windows:
|
|
54
|
+
cmd = ["ping", "-n", "1", "-w", str(timeout_ms), host]
|
|
55
|
+
else:
|
|
56
|
+
cmd = ["ping", "-c", "1", "-W", str(int(timeout_ms / 1000)), host]
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
result = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
60
|
+
if result.returncode == 0:
|
|
61
|
+
return True
|
|
62
|
+
except Exception as exc:
|
|
63
|
+
print(f"✗ 无法执行 ping:{exc}")
|
|
64
|
+
|
|
65
|
+
# Fallback: HTTPS request (respects proxy envs)
|
|
66
|
+
try:
|
|
67
|
+
with urllib.request.urlopen(url, timeout=timeout_ms / 1000.0) as resp:
|
|
68
|
+
return 200 <= getattr(resp, "status", 200) < 400
|
|
69
|
+
except Exception as exc:
|
|
70
|
+
print(f"✗ HTTPS 连通性检测失败:{exc}")
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def prompt_config_if_needed():
|
|
75
|
+
cfg = load_config()
|
|
76
|
+
|
|
77
|
+
defaults = {
|
|
78
|
+
"base_url": cfg.get("base_url") or "https://api.moonshot.cn/v1",
|
|
79
|
+
"model": cfg.get("model") or "kimi-latest",
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if not cfg.get("system_prompt"):
|
|
83
|
+
cfg["system_prompt"] = (
|
|
84
|
+
"You are a WorldQuant BRAIN platform expert and Consultant. "
|
|
85
|
+
"Your goal is to assist users with Alpha development, BRAIN API usage, and maximizing consultant income."
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def ask(field, label, default_value=None, allow_empty=False):
|
|
89
|
+
current = str(cfg.get(field, "")).strip()
|
|
90
|
+
prompt = f"请输入 {label}" + (f" [默认: {current or default_value}]" if (current or default_value) else "") + ": "
|
|
91
|
+
value = input(prompt).strip()
|
|
92
|
+
if not value:
|
|
93
|
+
value = current if current else (default_value if default_value is not None else "")
|
|
94
|
+
if value or allow_empty:
|
|
95
|
+
cfg[field] = value
|
|
96
|
+
return value
|
|
97
|
+
|
|
98
|
+
api_key = ask("api_key", "API Key")
|
|
99
|
+
base_url = ask("base_url", "Base URL", defaults["base_url"], allow_empty=True)
|
|
100
|
+
model = ask("model", "模型名称", defaults["model"], allow_empty=True)
|
|
101
|
+
|
|
102
|
+
if api_key:
|
|
103
|
+
save_config(cfg)
|
|
104
|
+
return True
|
|
105
|
+
|
|
106
|
+
print("✗ 配置文件中的 api_key 为空,请填写后再运行本脚本。")
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def is_api_key_configured():
|
|
111
|
+
"""Check config; if api_key missing/empty, prompt user to fill and persist."""
|
|
112
|
+
cfg = load_config()
|
|
113
|
+
|
|
114
|
+
api_key = str(cfg.get("api_key", "")).strip()
|
|
115
|
+
if api_key:
|
|
116
|
+
return True
|
|
117
|
+
|
|
118
|
+
print("✗ 当前 config.json 中 api_key 为空。")
|
|
119
|
+
return prompt_config_if_needed()
|
|
120
|
+
|
|
121
|
+
def create_desktop_shortcut():
|
|
122
|
+
"""创建桌面快捷方式"""
|
|
123
|
+
try:
|
|
124
|
+
import win32com.client
|
|
125
|
+
|
|
126
|
+
desktop = os.path.expanduser("~\\Desktop")
|
|
127
|
+
shortcut_path = os.path.join(desktop, "BRAIN顾问助手.lnk")
|
|
128
|
+
|
|
129
|
+
# 获取 Python 可执行文件路径
|
|
130
|
+
python_exe = sys.executable
|
|
131
|
+
|
|
132
|
+
# 创建 shortcut
|
|
133
|
+
shell = win32com.client.Dispatch("WScript.Shell")
|
|
134
|
+
shortcut = shell.CreateShortcut(shortcut_path)
|
|
135
|
+
shortcut.TargetPath = python_exe
|
|
136
|
+
shortcut.Arguments = f'"{MAIN_SCRIPT}"'
|
|
137
|
+
shortcut.WorkingDirectory = PROJECT_DIR
|
|
138
|
+
|
|
139
|
+
# 设置图标:优先使用 .ico(Windows 标准格式),再试 .png
|
|
140
|
+
icon_found = False
|
|
141
|
+
if os.path.exists(ICON_ICO):
|
|
142
|
+
# .ico 文件:使用 "路径,0" 格式
|
|
143
|
+
shortcut.IconLocation = f"{ICON_ICO},0"
|
|
144
|
+
icon_found = True
|
|
145
|
+
print(f" 使用图标:{ICON_ICO}")
|
|
146
|
+
elif os.path.exists(ICON_PNG):
|
|
147
|
+
# .png 文件:也需要 "路径,0" 格式
|
|
148
|
+
shortcut.IconLocation = f"{ICON_PNG},0"
|
|
149
|
+
icon_found = True
|
|
150
|
+
print(f" 使用图标:{ICON_PNG}")
|
|
151
|
+
else:
|
|
152
|
+
# 使用 Python 可执行文件的图标作为默认
|
|
153
|
+
shortcut.IconLocation = f"{python_exe},0"
|
|
154
|
+
print(f" 使用默认图标(Python 图标)")
|
|
155
|
+
|
|
156
|
+
shortcut.Description = "BRAIN 顾问助手 - AI 驱动的交互工具"
|
|
157
|
+
shortcut.save()
|
|
158
|
+
|
|
159
|
+
print(f"✓ 桌面快捷方式已创建:{shortcut_path}")
|
|
160
|
+
return True
|
|
161
|
+
except ImportError:
|
|
162
|
+
print("⚠ pywin32 未安装,尝试使用备选方案创建快捷方式...")
|
|
163
|
+
try:
|
|
164
|
+
# 备选方案:使用 Windows API
|
|
165
|
+
create_shortcut_via_batch(desktop, shortcut_path, python_exe)
|
|
166
|
+
return True
|
|
167
|
+
except Exception as e:
|
|
168
|
+
print(f"✗ 创建快捷方式失败:{e}")
|
|
169
|
+
print(f" 请手动创建快捷方式,目标为:{python_exe} \"{MAIN_SCRIPT}\"")
|
|
170
|
+
return False
|
|
171
|
+
except Exception as e:
|
|
172
|
+
print(f"✗ 创建快捷方式失败:{e}")
|
|
173
|
+
return False
|
|
174
|
+
|
|
175
|
+
def check_knowledge_base():
|
|
176
|
+
"""检查 knowledge 文件夹中的文件数量"""
|
|
177
|
+
if not os.path.exists(KNOWLEDGE_DIR):
|
|
178
|
+
os.makedirs(KNOWLEDGE_DIR)
|
|
179
|
+
print(f"✓ 创建 knowledge 文件夹:{KNOWLEDGE_DIR}")
|
|
180
|
+
return 0
|
|
181
|
+
|
|
182
|
+
# 只计算文件,不计算目录
|
|
183
|
+
files = [f for f in os.listdir(KNOWLEDGE_DIR) if os.path.isfile(os.path.join(KNOWLEDGE_DIR, f))]
|
|
184
|
+
file_count = len(files)
|
|
185
|
+
print(f"知识库文件数量:{file_count}")
|
|
186
|
+
|
|
187
|
+
if files:
|
|
188
|
+
print(f" 已有文件:{', '.join(files)}")
|
|
189
|
+
|
|
190
|
+
return file_count
|
|
191
|
+
|
|
192
|
+
def run_process_knowledge_base():
|
|
193
|
+
"""运行 process_knowledge_base.py 建立知识库"""
|
|
194
|
+
if not os.path.exists(PROCESS_SCRIPT):
|
|
195
|
+
print(f"✗ 找不到 {PROCESS_SCRIPT}")
|
|
196
|
+
return False
|
|
197
|
+
|
|
198
|
+
print(f"\n正在运行知识库初始化脚本...")
|
|
199
|
+
print(f"命令:{sys.executable} \"{PROCESS_SCRIPT}\"")
|
|
200
|
+
|
|
201
|
+
try:
|
|
202
|
+
subprocess.run([sys.executable, PROCESS_SCRIPT], cwd=PROJECT_DIR)
|
|
203
|
+
print("✓ 知识库初始化完成")
|
|
204
|
+
return True
|
|
205
|
+
except Exception as e:
|
|
206
|
+
print(f"✗ 运行 process_knowledge_base.py 失败:{e}")
|
|
207
|
+
return False
|
|
208
|
+
|
|
209
|
+
def main():
|
|
210
|
+
print("=" * 60)
|
|
211
|
+
print("BRAIN 顾问助手 - 首次运行初始化")
|
|
212
|
+
print("=" * 60)
|
|
213
|
+
print()
|
|
214
|
+
|
|
215
|
+
# 0. 检查 api_key 是否已配置,未配置则直接退出
|
|
216
|
+
if not is_api_key_configured():
|
|
217
|
+
input("按 Enter 键退出...")
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
# 0.1 检查网络(ping + HTTPS),以确认代理已开启
|
|
221
|
+
print("[网络检查] 正在测试到 https://www.google.com 的连通性...")
|
|
222
|
+
if not check_network_reachable("https://www.google.com/generate_204"):
|
|
223
|
+
print("✗ 无法连通 google.com,请确认代理已开启,然后重新运行本脚本。")
|
|
224
|
+
input("按 Enter 键退出...")
|
|
225
|
+
return
|
|
226
|
+
print("✓ 网络检查通过")
|
|
227
|
+
|
|
228
|
+
# 1. 创建桌面快捷方式
|
|
229
|
+
print("[1/2] 创建桌面快捷方式...")
|
|
230
|
+
shortcut_ok = create_desktop_shortcut()
|
|
231
|
+
print()
|
|
232
|
+
|
|
233
|
+
# 2. 检查知识库
|
|
234
|
+
print("[2/2] 检查本地知识库...")
|
|
235
|
+
file_count = check_knowledge_base()
|
|
236
|
+
print()
|
|
237
|
+
|
|
238
|
+
if file_count <= 3:
|
|
239
|
+
print("⚠ 知识库文件较少(<= 3 个)")
|
|
240
|
+
print("建议建立本地知识库以增强 AI 回答效果")
|
|
241
|
+
print()
|
|
242
|
+
|
|
243
|
+
response = input("是否现在运行知识库初始化脚本?(y/n) [默认: y]: ").strip().lower()
|
|
244
|
+
if response != 'n':
|
|
245
|
+
run_process_knowledge_base()
|
|
246
|
+
else:
|
|
247
|
+
print(f"✓ 知识库已初始化(包含 {file_count} 个文件)")
|
|
248
|
+
|
|
249
|
+
print()
|
|
250
|
+
print("=" * 60)
|
|
251
|
+
print("初始化完成!")
|
|
252
|
+
print("=" * 60)
|
|
253
|
+
print()
|
|
254
|
+
|
|
255
|
+
if shortcut_ok:
|
|
256
|
+
print("📌 你现在可以从桌面快捷方式启动应用")
|
|
257
|
+
print(f" 或者运行:{sys.executable} \"{MAIN_SCRIPT}\"")
|
|
258
|
+
else:
|
|
259
|
+
print(f"请运行:{sys.executable} \"{MAIN_SCRIPT}\"")
|
|
260
|
+
print()
|
|
261
|
+
|
|
262
|
+
input("按 Enter 键退出...")
|
|
263
|
+
|
|
264
|
+
if __name__ == "__main__":
|
|
265
|
+
main()
|