XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

feat: Add OpenClaw configuration patching script and update setup script for model application

ed4ef157
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +48 -4
Added scripts/patch-openclaw.py +46 -0
@@ -0,0 +1,46 @@
1 import json, sys, os
2
3 config_file = os.path.expanduser("~/.openclaw/openclaw.json")
4 if not os.path.exists(config_file):
5 print("OpenClaw config not found. Please onboard OpenClaw first with `openclaw onboard` command.")
6 sys.exit(1)
7
8 provider = {
9 "baseUrl": "http://localhost:8080/v1",
10 "api": "openai-completions",
11 "models": [
12 {
13 "id": "openclaw",
14 "name": "Custom GPT4Free",
15 "reasoning": True,
16 "input": ["text", "image"],
17 "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
18 "contextWindow": 256000,
19 "maxTokens": 8192,
20 }
21 ],
22 }
23
24 try:
25 with open(config_file) as f:
26 cfg = json.load(f)
27 except (FileNotFoundError, json.JSONDecodeError):
28 cfg = {}
29
30 cfg.setdefault("models", {})["providers"] = cfg.get("models", {}).get("providers", {})
31 cfg["models"]["providers"]["gpt4free"] = provider
32 cfg["models"]["providers"]["g4f-perplexity"] = {
33 "baseUrl": "https://perplexity.g4f-dev.workers.dev",
34 "model": "turbo",
35 }
36 cfg["tools"] = cfg.get("tools", {})
37 cfg["tools"]["web"] = cfg["tools"].get("web", {})
38 cfg["tools"]["web"]["search"] = {
39 "provider": "g4f-perplexity",
40 }
41
42 with open(config_file, "w") as f:
43 json.dump(cfg, f, indent=2)
44
45 print("OpenClaw config patched via Python.")
46 print("You can now run `openclaw models set gpt4free/openclaw` to apply the new model config and `openclaw gateway restart` to restart the gateway with the new config.")
Modified scripts/setup-openclaw.sh +2 -4
@@ -103,8 +103,6 @@ provider = {
103 103 ],
104 104 }
105 105
106 os.makedirs(os.path.dirname(config_file), exist_ok=True)
107
108 106 try:
109 107 with open(config_file) as f:
110 108 cfg = json.load(f)
@@ -117,7 +115,7 @@ cfg["models"]["providers"]["g4f-perplexity"] = {
117 115 "baseUrl": "https://perplexity.g4f-dev.workers.dev",
118 116 "apiKey": "",
119 117 "model": "turbo",
120 };
118 }
121 119 cfg["tools"] = cfg.get("tools", {})
122 120 cfg["tools"]["web"] = cfg["tools"].get("web", {})
123 121 cfg["tools"]["web"]["search"] = {
@@ -130,7 +128,7 @@ with open(config_file, "w") as f:
130 128 print("OpenClaw config patched via Python.")
131 129 PYEOF
132 130
133 # apply fallback models with openclaw commands if available
131 # apply models with openclaw commands if available
134 132 openclaw models set gpt4free/openclaw >/dev/null 2>&1 || true
135 133 openclaw gateway restart >/dev/null 2>&1 || true
136 134 else