diff --git a/scripts/setup/update-models.sh b/scripts/setup/update-models.sh index 58126ba..7ad943a 100755 --- a/scripts/setup/update-models.sh +++ b/scripts/setup/update-models.sh @@ -1,9 +1,10 @@ #!/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. # # 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 ollama # update only ollama # @@ -33,6 +34,18 @@ get_display_name() { 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. # Preserves any existing entries that have extra metadata (limits, modalities, variants) # beyond just a name — so your manual overrides aren't lost. @@ -69,6 +82,9 @@ build_models_json() { local existing_entry 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" if [[ -n "$existing_entry" ]]; then local key_count @@ -83,14 +99,16 @@ build_models_json() { new_models=$(echo "$new_models" | jq \ --arg id "$model_id" \ --argjson entry "$existing_entry" \ + --argjson limit "$default_limit" \ --arg name "${model_id} (${display_name})" \ - '.[$id] = ($entry | .name = $name)') + '.[$id] = ($entry | .name = $name | .limit = (.limit // $limit))') else # Simple entry with just a name new_models=$(echo "$new_models" | jq \ --arg id "$model_id" \ + --argjson limit "$default_limit" \ --arg name "${model_id} (${display_name})" \ - '.[$id] = { "name": $name }') + '.[$id] = { "name": $name, "limit": $limit }') fi done <<< "$model_ids" @@ -136,7 +154,7 @@ update_provider() { # --- Main --- -targets=("${@:-lmstudio ollama}") +targets=("${@:-vllm ollama}") errors=0 for target in $targets; do