Skip to content

Commit ab524c6

Browse files
kenvandineCopilot
andauthored
Use jq for parsing model metadata
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 69a82c2 commit ab524c6

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

scripts/codex

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,9 @@ CONTEXT_ARGS=()
124124
if [ -n "$MODEL_NAME" ] && [ -n "$OPENAI_BASE_URL" ]; then
125125
SERVER_BASE="${OPENAI_BASE_URL%%/v1*}"
126126
ctx_size=$(curl -sf "$SERVER_BASE/api/v1/health" 2>/dev/null \
127-
| python3 -c "
128-
import sys, json
129-
model = '$MODEL_NAME'
130-
try:
131-
data = json.load(sys.stdin)
132-
for m in data.get('all_models_loaded', []):
133-
if m.get('model_name') == model:
134-
v = m.get('recipe_options', {}).get('ctx_size', '')
135-
if v: print(v)
136-
break
137-
except Exception:
138-
pass
139-
" 2>/dev/null)
127+
| jq -r --arg model "$MODEL_NAME" \
128+
'.all_models_loaded[]? | select(.model_name == $model) | .recipe_options.ctx_size // empty' \
129+
2>/dev/null | head -n1)
140130
if [ -n "$ctx_size" ] && [ "$ctx_size" -gt 0 ] 2>/dev/null; then
141131
tool_limit=$(( ctx_size / 8 ))
142132
[ "$tool_limit" -lt 8192 ] && tool_limit=8192

0 commit comments

Comments
 (0)