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

XFEstudio/gpt4free

feat: Add OpenClaw setup script for multi-platform configuration and onboarding

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

代码差异

1 个文件 +159 -0
Added scripts/setup-openclaw.sh +159 -0
@@ -0,0 +1,159 @@
1 #!/bin/bash
2
3 # gpt4free-style OpenClaw route setup
4 # Works on: macOS, Linux, Windows (WSL/Git Bash/MSYS2)
5 # Usage: curl -fsSL https://raw.githubusercontent.com/xtekky/gpt4free/main/scripts/setup-openclaw.sh | bash -s -- <POLLINATIONS_API_KEY>
6
7 set -e
8
9 if [ -z "$1" ]; then
10 echo "No API key provided. Proceeding without a Pollinations API key."
11 API_KEY=""
12 else
13 API_KEY="$1"
14 fi
15
16 if ! command -v python >/dev/null 2>&1; then
17 echo "Python not found. Please install Python 3.10+ first."
18 exit 1
19 fi
20
21 if ! python -m g4f --help >/dev/null 2>&1; then
22 echo "g4f not installed. Installing with pip..."
23 python -m pip install -U g4f[all]
24 fi
25
26 CONFIG_DIR="${HOME}/.config/g4f/cookies"
27 CONFIG_FILE="${CONFIG_DIR}/config.yaml"
28 ENV_FILE="${CONFIG_DIR}/.env"
29
30 mkdir -p "${CONFIG_DIR}"
31
32 cat > "${CONFIG_FILE}" <<'EOF'
33 models:
34 - name: "openclaw"
35 providers:
36 - provider: "GeminiCLI"
37 model: "gemini-3-flash-preview"
38 condition: "quota.models.gemini-3-flash-preview.remaining > 0 and error_count < 3"
39 - provider: "Antigravity"
40 model: "gemini-3-flash"
41 condition: "quota.models.gemini-3-flash.quotaInfo.remainingFraction > 0 and error_count < 3"
42 - provider: "PollinationsAI"
43 model: "openai"
44 condition: "balance > 0 or error_count < 3"
45 EOF
46
47 cat > "${ENV_FILE}" <<EOF
48 POLLINATIONS_API_KEY=${API_KEY}
49 OPENAI_API_KEY=${API_KEY}
50 GEMINI_API_KEY=
51 EOF
52
53 # OpenClaw onboarding and configuration (if available)
54 if command -v openclaw >/dev/null 2>&1; then
55 echo "OpenClaw CLI found. Configuring OpenClaw..."
56 OPENCLAW_CONFIG_FILE="${HOME}/.openclaw/openclaw.json"
57 mkdir -p "${HOME}/.openclaw"
58
59 if [ ! -f "${OPENCLAW_CONFIG_FILE}" ]; then
60 echo "Fresh install — running OpenClaw setup..."
61 openclaw onboard \
62 --non-interactive \
63 --accept-risk \
64 --mode local \
65 --flow quickstart \
66 --auth-choice custom-api-key \
67 --custom-base-url "http://localhost:8080/v1" \
68 --custom-provider-id gpt4free \
69 --custom-model-id openclaw \
70 --custom-api-key "${API_KEY}" \
71 --secret-input-mode plaintext \
72 --skip-channels \
73 --skip-daemon \
74 --skip-skills \
75 --skip-ui \
76 --skip-health \
77 2>&1 | grep -v "^$" || true
78 else
79 echo "OpenClaw config already exists at ${OPENCLAW_CONFIG_FILE}, skipping onboard."
80 fi
81
82 echo "Patching OpenClaw provider and model list..."
83
84 echo "using Python to patch OpenClaw config..."
85 python - <<PYEOF
86 import json, sys, os
87
88 config_file = os.path.expanduser("~/.openclaw/openclaw.json")
89 api_key = "${API_KEY}"
90
91 provider = {
92 "baseUrl": "https://localhost:8080/v1",
93 "apiKey": api_key,
94 "api": "openai-completions",
95 "models": [
96 {
97 "id": "openclaw",
98 "name": "Custom GPT4Free",
99 "reasoning": True,
100 "input": ["text", "image"],
101 "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
102 "contextWindow": 256000,
103 "maxTokens": 8192,
104 }
105 ],
106 }
107
108 os.makedirs(os.path.dirname(config_file), exist_ok=True)
109
110 try:
111 with open(config_file) as f:
112 cfg = json.load(f)
113 except (FileNotFoundError, json.JSONDecodeError):
114 cfg = {}
115
116 cfg.setdefault("models", {})["providers"] = cfg.get("models", {}).get("providers", {})
117 cfg["models"]["providers"]["gpt4free"] = provider
118 cfg.setdefault("tools", {}).setdefault("web", {})["search"] = {
119 "provider": "perplexity",
120 "perplexity": {
121 "baseUrl": "https://g4f.dev/api/perplexity",
122 "apiKey": "",
123 "model": "turbo",
124 },
125 }
126
127 with open(config_file, "w") as f:
128 json.dump(cfg, f, indent=2)
129
130 print("OpenClaw config patched via Python.")
131 PYEOF
132
133 # apply fallback models with openclaw commands if available
134 openclaw models set gpt4free/openclaw >/dev/null 2>&1 || true
135 openclaw gateway restart >/dev/null 2>&1 || true
136 else
137 echo "OpenClaw CLI not found; skipping OpenClaw setup steps."
138 fi
139
140 printf "\n🚀 OpenClaw route configured in %s\n" "${CONFIG_FILE}"
141 printf "✅ .env written to %s\n" "${ENV_FILE}"
142
143 cat <<'INFO'
144
145 Next steps:
146 g4f client "Hello OpenClaw" --model openclaw
147 or use python:
148 from g4f.client import Client
149 client = Client()
150 resp = client.chat.completions.create(model='openclaw', messages=[{'role':'user','content':'Hello'}])
151 print(resp.choices[0].message.content)
152
153 Start the server:
154 g4f api --debug --port 8080
155
156 And auth into Antigravity and GeminiCLI (or any other provider you wish to use).
157
158 For more setting options, edit config.yaml and add other providers or condition values.
159 INFO