- 高危词库从 process.py 抽到 config.toml [security] section - process.py 改为 _get_high_risk_words() 动态加载(配置优先) - 新增 15 个 QQ 操作脚本(已脱敏:QQ号/IP/Token → 占位符) - 新增 8 个 SKILL.md(qq-messenger/management/resolver/napcat-extras 等) - 新增 SKILL.md 入口(完整部署方案文档) - 保留 SDK 框架(plugin_modules.py, file_store_api.py, package.py 等)
59 lines
1.8 KiB
Python
Executable File
59 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
"""
|
||
qq-agent → Nix 求助工具(同步 Gateway API 调用)
|
||
|
||
直接发问题到 Gateway,等 Nix 回复,不需要文件桥接。
|
||
模仿 openclaw_bridge 插件的 `_send_to_openclaw` 实现。
|
||
|
||
用法: python3 ask_nix.py "问题内容"
|
||
返回: Nix 的回复,或超时错误
|
||
"""
|
||
import sys
|
||
import json
|
||
import requests
|
||
|
||
GATEWAY_URL = "http://127.0.0.1:18789/v1/chat/completions"
|
||
GATEWAY_TOKEN = "YOUR_GATEWAY_TOKEN"
|
||
NIX_MODEL = "openclaw/ops-manager"
|
||
|
||
|
||
def ask(question: str, timeout: int = 120) -> str:
|
||
"""同步调用 Gateway,等 Nix 回复"""
|
||
payload = {
|
||
"model": NIX_MODEL,
|
||
"messages": [{"role": "user", "content": question}],
|
||
"stream": False,
|
||
}
|
||
headers = {
|
||
"Content-Type": "application/json",
|
||
"Authorization": f"Bearer {GATEWAY_TOKEN}",
|
||
}
|
||
try:
|
||
resp = requests.post(
|
||
GATEWAY_URL,
|
||
json=payload,
|
||
headers=headers,
|
||
timeout=timeout,
|
||
)
|
||
if resp.status_code == 200:
|
||
data = resp.json()
|
||
choices = data.get("choices", [])
|
||
if choices:
|
||
return choices[0].get("message", {}).get("content", "")
|
||
return "Nix 返回为空"
|
||
return f"请求失败({resp.status_code}): {resp.text[:200]}"
|
||
except requests.exceptions.Timeout:
|
||
return "[timeout] Nix 没回 超时了 要么他不在线 要么忙着呢 老板稍后再试吧"
|
||
except requests.exceptions.ConnectionError:
|
||
return "Nix 连接失败,请检查 Gateway 服务状态"
|
||
except Exception as e:
|
||
return f"请求异常: {str(e)}"
|
||
|
||
|
||
if __name__ == "__main__":
|
||
question = sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read().strip()
|
||
if not question:
|
||
print("错误:未提供问题", file=sys.stderr)
|
||
sys.exit(1)
|
||
print(ask(question))
|