feat(setup): add vllm support and default model limits to update-models.sh

This commit is contained in:
tke
2026-08-17 09:37:23 +02:00
parent 52e0c00cd8
commit 348a275480
+23 -5
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Updates lmstudio and/or ollama model listings in opencode.json # Updates vllm/lmstudio/ollama model listings in opencode.json
# by querying their /v1/models endpoints. # by querying their /v1/models endpoints.
# #
# Usage: # Usage:
# ./update-models.sh # update both # ./update-models.sh # update configured defaults
# ./update-models.sh vllm # update only vllm
# ./update-models.sh lmstudio # update only lmstudio # ./update-models.sh lmstudio # update only lmstudio
# ./update-models.sh ollama # update only ollama # ./update-models.sh ollama # update only ollama
# #
@@ -33,6 +34,18 @@ get_display_name() {
jq -r ".provider.${1}.name // \"${1}\"" "$CONFIG" jq -r ".provider.${1}.name // \"${1}\"" "$CONFIG"
} }
# Emit the default opencode limits for locally served OpenAI-compatible models.
# The output limit must stay below the context window so auto-compaction can
# reserve space before the upstream API rejects input_tokens + max_tokens.
model_limit_json() {
local provider="$1"
local model_id="$2"
case "${provider}:${model_id}" in
*) jq -cn '{context: 262144, output: 32000}' ;;
esac
}
# Fetch models from API endpoint and build the opencode models object. # Fetch models from API endpoint and build the opencode models object.
# Preserves any existing entries that have extra metadata (limits, modalities, variants) # Preserves any existing entries that have extra metadata (limits, modalities, variants)
# beyond just a name — so your manual overrides aren't lost. # beyond just a name — so your manual overrides aren't lost.
@@ -69,6 +82,9 @@ build_models_json() {
local existing_entry local existing_entry
existing_entry=$(echo "$existing" | jq -r --arg id "$model_id" '.[$id] // empty') existing_entry=$(echo "$existing" | jq -r --arg id "$model_id" '.[$id] // empty')
local default_limit
default_limit=$(model_limit_json "$provider" "$model_id")
local has_extras="false" local has_extras="false"
if [[ -n "$existing_entry" ]]; then if [[ -n "$existing_entry" ]]; then
local key_count local key_count
@@ -83,14 +99,16 @@ build_models_json() {
new_models=$(echo "$new_models" | jq \ new_models=$(echo "$new_models" | jq \
--arg id "$model_id" \ --arg id "$model_id" \
--argjson entry "$existing_entry" \ --argjson entry "$existing_entry" \
--argjson limit "$default_limit" \
--arg name "${model_id} (${display_name})" \ --arg name "${model_id} (${display_name})" \
'.[$id] = ($entry | .name = $name)') '.[$id] = ($entry | .name = $name | .limit = (.limit // $limit))')
else else
# Simple entry with just a name # Simple entry with just a name
new_models=$(echo "$new_models" | jq \ new_models=$(echo "$new_models" | jq \
--arg id "$model_id" \ --arg id "$model_id" \
--argjson limit "$default_limit" \
--arg name "${model_id} (${display_name})" \ --arg name "${model_id} (${display_name})" \
'.[$id] = { "name": $name }') '.[$id] = { "name": $name, "limit": $limit }')
fi fi
done <<< "$model_ids" done <<< "$model_ids"
@@ -136,7 +154,7 @@ update_provider() {
# --- Main --- # --- Main ---
targets=("${@:-lmstudio ollama}") targets=("${@:-vllm ollama}")
errors=0 errors=0
for target in $targets; do for target in $targets; do