-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenwebui_search_deploy.sh
More file actions
248 lines (205 loc) · 8.67 KB
/
Copy pathopenwebui_search_deploy.sh
File metadata and controls
248 lines (205 loc) · 8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
# Christopher Gray
# Version 0.0.23
# Updated: 5/24/2026
#
# *** ENTRY POINT ***
#
# Self-contained deploy script for SearXNG + Open WebUI tool.
# Run directly on the server as root — no other files needed.
#
# Download and run in one command:
# curl -fsSL https://raw.githubusercontent.com/c2theg/ai/refs/heads/main/openwebui_search_deploy.sh -o openwebui_search_deploy.sh && bash openwebui_search_deploy.sh
set -e
SEARXNG_CONFIG_DIR="/opt/models/searxng"
TOOL_URL="https://raw.githubusercontent.com/c2theg/ai/refs/heads/main/openwebui_tool.py"
TOOL_DEST="/opt/models/openwebui_tool.py"
PUSH_URL="https://raw.githubusercontent.com/c2theg/ai/refs/heads/main/openweb_ui_push_tool.py"
PUSH_DEST="/opt/models/openweb_ui_push_tool.py"
# ---------------------------------------------------------------------------
# 1. SearXNG settings.yml
# ---------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SETTINGS_LOCAL="${SCRIPT_DIR}/searxng_settings.yml"
SETTINGS_URL="https://raw.githubusercontent.com/c2theg/ai/refs/heads/main/searxng_settings.yml"
echo "==> Generating SearXNG secret key..."
SECRET=$(openssl rand -hex 32)
mkdir -p "$SEARXNG_CONFIG_DIR"
if [ -f "$SETTINGS_LOCAL" ]; then
echo "==> Copying local searxng_settings.yml..."
cp "$SETTINGS_LOCAL" "$SEARXNG_CONFIG_DIR/settings.yml"
else
echo "==> Downloading searxng_settings.yml..."
curl -fsSL "$SETTINGS_URL" -o "$SEARXNG_CONFIG_DIR/settings.yml"
fi
if [ -n "$SECRET" ]; then
echo "==> Injecting generated secret key..."
sed -i \
-e '/^ secret_key: /d' \
-e "s| #secret_key: \"\${SECRET}\"| secret_key: \"${SECRET}\"|" \
"$SEARXNG_CONFIG_DIR/settings.yml"
else
echo "==> No secret generated — using default key from settings file."
fi
echo "==> settings.yml written."
# ---------------------------------------------------------------------------
# 2. Start SearXNG container
# ---------------------------------------------------------------------------
# Remove existing container if present so we can re-apply the new config
if docker ps -a --format '{{.Names}}' | grep -q '^searxng$'; then
echo "==> Removing existing searxng container..."
docker rm -f searxng
fi
echo "==> Starting SearXNG container..."
docker run -d \
--name searxng \
--restart always \
-p 8080:8080 \
-v "$SEARXNG_CONFIG_DIR/settings.yml:/etc/searxng/settings.yml:ro" \
searxng/searxng
echo "==> Waiting for SearXNG to be ready..."
for i in $(seq 1 15); do
if curl -sf "http://localhost:8080/search?q=test&format=json" > /dev/null 2>&1; then
echo "==> SearXNG is up."
break
fi
echo " Attempt $i/15 — waiting..."
sleep 2
done
# ---------------------------------------------------------------------------
# 3. Test JSON API
# ---------------------------------------------------------------------------
echo ""
echo "==> Testing SearXNG JSON API..."
curl -s "http://localhost:8080/search?q=hello+world&format=json" | python3 -c "
import sys, json
d = json.load(sys.stdin)
r = d.get('results', [])
print(f' OK — got {len(r)} results')
if r:
print(f' First result: {r[0].get(\"title\", \"\")}')
" || echo " WARNING: JSON API test failed — check logs: docker logs searxng"
# ---------------------------------------------------------------------------
# 4. Download Open WebUI tool
# ---------------------------------------------------------------------------
echo ""
echo "==> Downloading Open WebUI tool to ${TOOL_DEST}..."
curl -fsSL "$TOOL_URL" -o "$TOOL_DEST"
echo "==> Tool saved."
# ---------------------------------------------------------------------------
# 5. Download push_tool.py (auto-deploy without the browser)
# ---------------------------------------------------------------------------
echo ""
echo "==> Downloading push_tool.py to ${PUSH_DEST}..."
curl -fsSL "$PUSH_URL" -o "$PUSH_DEST"
chmod +x "$PUSH_DEST"
echo "==> push_tool.py saved and marked executable."
# Check python3 + requests are available for push_tool.py
if command -v python3 &>/dev/null; then
if ! python3 -c "import requests" 2>/dev/null; then
echo "==> Installing requests for push_tool.py..."
python3 -m pip install --quiet requests
else
echo "==> python3 + requests OK."
fi
else
echo " WARNING: python3 not found — install it to use push_tool.py"
fi
# ---------------------------------------------------------------------------
# 6. Instructions
# ---------------------------------------------------------------------------
echo ""
echo "========================================================"
echo " Setup complete. Follow these steps to finish:"
echo "========================================================"
echo ""
echo " [1] Configure Web Search (Admin Panel > Settings > Web Search):"
echo " - Enable Web Search: ON"
echo " - Web Search Engine: searxng"
echo " - SearXNG Query URL: http://localhost:8080/search?q=<query>"
echo " - Save"
echo ""
echo " [2] Install the Tool (Workspace > Tools > '+'):"
echo " - Paste the contents of: ${TOOL_DEST}"
echo " - Or copy from: ${TOOL_URL}"
echo " - Save"
echo ""
echo " [3] Use in any chat:"
echo " - Click the tools '+' icon in the chat bar"
echo " - Toggle on 'Web Search & URL Fetch'"
echo " - Works with Gemma4, Qwen, or any Ollama / vLLM model"
echo ""
echo " [4] Set up push_tool.py so you never paste via the browser again:"
echo " Add to your shell profile (~/.bashrc or ~/.zshrc):"
echo ""
echo " Option A — email + password (easiest, works with any version):"
echo " export OWUI_URL=\"http://$(hostname -I | awk '{print $1}'):3000\""
echo " export OWUI_EMAIL=\"you@example.com\""
echo " export OWUI_PASSWORD=\"yourpassword\""
echo ""
echo " Option B — API key (Admin Panel > Settings > Account > API Keys):"
echo " export OWUI_URL=\"http://$(hostname -I | awk '{print $1}'):3000\""
echo " export OWUI_API_KEY=\"sk-...\""
echo ""
echo " Push once: python3 ${PUSH_DEST}"
echo " Auto-push on save: python3 ${PUSH_DEST} --watch"
echo ""
echo "========================================================"
echo " Done!"
echo "========================================================"
echo "Examples: "
echo "
🌤 Weather
curl -s 'http://localhost:8080/search?q=weather+new+york&format=json' | python3 -m json.tool | head -30
📰 World News
curl -s 'http://localhost:8080/search?q=world+news+today&format=json' | python3 -m json.tool | head -30
💰 Stock Market
# General market
curl -s 'http://localhost:8080/search?q=stock+market+today&format=json' | python3 -m json.tool | head -30
# Specific stock
curl -s 'http://localhost:8080/search?q=NVIDIA+stock+price&format=json' | python3 -m json.tool | head -30
🏈 Sports
# General scores
curl -s 'http://localhost:8080/search?q=sports+scores+today&format=json' | python3 -m json.tool | head -30
# Specific sport
curl -s 'http://localhost:8080/search?q=NBA+scores+today&format=json' | python3 -m json.tool | head -30
📖 Wikipedia
curl -s 'http://localhost:8080/search?q=!wp+artificial+intelligence&format=json' | python3 -m json.tool | head -30
💻 Tech News
curl -s 'http://localhost:8080/search?q=AI+news+today&format=json' | python3 -m json.tool | head -30
🤖 AI News
curl -s 'http://localhost:8080/search?q=large+language+models+2026&format=json' | python3 -m json.tool | head -30
📡 RSS Feed Test (BBC specifically)
curl -s 'http://localhost:8080/search?q=breaking+news&engines=bbc+world+news&format=json' | python3 -m json.tool | head -30
"
echo " Performing a series of tests... (this will take a minute.).
"
for query in "weather New York, New York" "world news today" "NVIDIA stock" "NFL scores" "artificial intelligence wikipedia" "tech news today"; do
echo "==============================="
echo "Testing: $query"
echo "==============================="
result=$(curl -s "http://localhost:8080/search?q=$(echo $query | sed 's/ /+/g')&format=json")
echo $result | python3 -c "
import json,sys
data=json.load(sys.stdin)
results=data.get('results',[])
print(f'Found {len(results)} results')
for r in results[:2]:
print(f' - {r.get(\"title\",\"no title\")}')
print(f' {r.get(\"url\",\"no url\")}')
"
echo ""
done
echo " Check which engines responded...
"
curl -s "http://localhost:8080/search?q=bitcoin&format=json" | python3 -c "
import json,sys
data=json.load(sys.stdin)
print('Engines used:')
for e in data.get('answers',[]):
print(f' {e}')
print(f'Total results: {len(data.get(\"results\",[]))}')
print(f'Infoboxes: {len(data.get(\"infoboxes\",[]))}')
for r in data.get('results',[])[:5]:
print(f' [{r.get(\"engine\",\"?\")}] {r.get(\"title\",\"?\")}')
"