Skip to content

Commit 2fc4e4c

Browse files
stackptrclaude
andcommitted
fix(glyph): handle models without DB entries in model sync
The update endpoint returns 401 for auto-discovered models that have no database entry yet. Fall back to the create endpoint in that case. Also add null-safety for the deactivation step's model list fetch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 47cc8bd commit 2fc4e4c

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

hosts/glyph/services/open-webui.nix

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ in {
9494
update_model() {
9595
local id=$1 form=$2
9696
echo "Configuring $id..."
97+
# Try update first; if model has no DB entry yet, create it
9798
http_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST \
9899
-H "Authorization: Bearer $API_KEY" \
99100
-H "Content-Type: application/json" \
@@ -102,6 +103,18 @@ in {
102103
103104
if [ "$http_code" = "200" ]; then
104105
echo "$id: updated."
106+
elif [ "$http_code" = "401" ]; then
107+
# Model has no DB entry — create it
108+
http_code=$(curl -s -o /dev/null -w '%{http_code}' -X POST \
109+
-H "Authorization: Bearer $API_KEY" \
110+
-H "Content-Type: application/json" \
111+
-d "$form" \
112+
"${baseUrl}/api/v1/models/create")
113+
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
114+
echo "$id: created."
115+
else
116+
echo "ERROR: failed to create $id (HTTP $http_code)"
117+
fi
105118
else
106119
echo "ERROR: failed to update $id (HTTP $http_code)"
107120
fi
@@ -121,16 +134,21 @@ in {
121134
wait
122135
123136
# Deactivate all unlisted models that are currently active
124-
curl -sf -H "Authorization: Bearer $API_KEY" \
125-
"${baseUrl}/api/v1/models/list" \
126-
| jq -r '.data[] | select(.is_active == true) | .id' \
127-
| while read -r id; do
128-
if ! echo "$ACTIVE_IDS" | jq -e --arg id "$id" 'index($id)' >/dev/null 2>&1; then
129-
curl -sf -X POST -H "Authorization: Bearer $API_KEY" \
130-
"${baseUrl}/api/v1/models/model/toggle?id=$id" >/dev/null 2>&1
131-
echo "$id: deactivated."
132-
fi
133-
done
137+
all_models=$(curl -sf -H "Authorization: Bearer $API_KEY" \
138+
"${baseUrl}/api/v1/models/list" 2>/dev/null)
139+
if [ -n "$all_models" ]; then
140+
echo "$all_models" \
141+
| jq -r '.data[] | select(.is_active == true) | .id' \
142+
| while read -r id; do
143+
if ! echo "$ACTIVE_IDS" | jq -e --arg id "$id" 'index($id)' >/dev/null 2>&1; then
144+
curl -sf -X POST -H "Authorization: Bearer $API_KEY" \
145+
"${baseUrl}/api/v1/models/model/toggle?id=$id" >/dev/null 2>&1
146+
echo "$id: deactivated."
147+
fi
148+
done
149+
else
150+
echo "WARNING: could not fetch model list for deactivation"
151+
fi
134152
'';
135153
};
136154

0 commit comments

Comments
 (0)