mirror of
https://github.com/xtekky/gpt4free.git
synced 2026-04-22 23:57:17 +08:00
feat: Add OpenClaw configuration patching script and update setup script for model application
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import json, sys, os
|
||||
|
||||
config_file = os.path.expanduser("~/.openclaw/openclaw.json")
|
||||
if not os.path.exists(config_file):
|
||||
print("OpenClaw config not found. Please onboard OpenClaw first with `openclaw onboard` command.")
|
||||
sys.exit(1)
|
||||
|
||||
provider = {
|
||||
"baseUrl": "http://localhost:8080/v1",
|
||||
"api": "openai-completions",
|
||||
"models": [
|
||||
{
|
||||
"id": "openclaw",
|
||||
"name": "Custom GPT4Free",
|
||||
"reasoning": True,
|
||||
"input": ["text", "image"],
|
||||
"cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
|
||||
"contextWindow": 256000,
|
||||
"maxTokens": 8192,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
try:
|
||||
with open(config_file) as f:
|
||||
cfg = json.load(f)
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
cfg = {}
|
||||
|
||||
cfg.setdefault("models", {})["providers"] = cfg.get("models", {}).get("providers", {})
|
||||
cfg["models"]["providers"]["gpt4free"] = provider
|
||||
cfg["models"]["providers"]["g4f-perplexity"] = {
|
||||
"baseUrl": "https://perplexity.g4f-dev.workers.dev",
|
||||
"model": "turbo",
|
||||
}
|
||||
cfg["tools"] = cfg.get("tools", {})
|
||||
cfg["tools"]["web"] = cfg["tools"].get("web", {})
|
||||
cfg["tools"]["web"]["search"] = {
|
||||
"provider": "g4f-perplexity",
|
||||
}
|
||||
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(cfg, f, indent=2)
|
||||
|
||||
print("OpenClaw config patched via Python.")
|
||||
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.")
|
||||
@@ -103,8 +103,6 @@ provider = {
|
||||
],
|
||||
}
|
||||
|
||||
os.makedirs(os.path.dirname(config_file), exist_ok=True)
|
||||
|
||||
try:
|
||||
with open(config_file) as f:
|
||||
cfg = json.load(f)
|
||||
@@ -117,7 +115,7 @@ cfg["models"]["providers"]["g4f-perplexity"] = {
|
||||
"baseUrl": "https://perplexity.g4f-dev.workers.dev",
|
||||
"apiKey": "",
|
||||
"model": "turbo",
|
||||
};
|
||||
}
|
||||
cfg["tools"] = cfg.get("tools", {})
|
||||
cfg["tools"]["web"] = cfg["tools"].get("web", {})
|
||||
cfg["tools"]["web"]["search"] = {
|
||||
@@ -130,7 +128,7 @@ with open(config_file, "w") as f:
|
||||
print("OpenClaw config patched via Python.")
|
||||
PYEOF
|
||||
|
||||
# apply fallback models with openclaw commands if available
|
||||
# apply models with openclaw commands if available
|
||||
openclaw models set gpt4free/openclaw >/dev/null 2>&1 || true
|
||||
openclaw gateway restart >/dev/null 2>&1 || true
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user