updated free collector logic for OpenCode

This commit is contained in:
Luxferre
2026-09-11 19:34:39 +03:00
parent 18f9125cb5
commit 20bafb0a14
2 changed files with 37 additions and 28 deletions
+16 -8
View File
@@ -3,12 +3,15 @@
# Depends upon curl and jq
# Created by Luxferre in 2026, released into the public domain
REQ='curl -fsSL'
REQ='curl -fsSL -4'
CONFIG='models.csv'
TCONFIG="$(mktemp)"
# Write OpenCode Zen free models
$REQ https://opencode.ai/zen/v1/models | jq -r '.data[] | select(.id | test("-free")) | "\(.id),-,https://opencode.ai/zen/v1,"' >> "$TCONFIG"
$REQ https://opencode.ai/zen/v1/models | jq -r '.data[] | select(.id | test("-free")) | "\(.id),-,https://opencode.ai/zen/v1,{\"User-Agent\":\"opencode/1.18.30\"}"' >> "$TCONFIG"
# Write Big Pickle as hardcode
echo 'big-pickle,-,https://opencode.ai/zen/v1,{"User-Agent":"opencode/1.18.30"}'>> "$TCONFIG"
# Write Kilo free models
$REQ https://api.kilo.ai/api/gateway/models | jq -r '.data[] | select(.isFree) | "\(.id),-,https://api.kilo.ai/api/gateway,"' >> "$TCONFIG"
@@ -47,6 +50,9 @@ echo 'xortron,-,https://darkc0de-chat.hf.space/v1,'>> "$TCONFIG"
# For non-timeout drops, the HTTP response code is reported for diagnostics.
VCONFIG="$(mktemp)"
SKIPF="$(mktemp)"
# OpenCode Zen endpoints require an X-Session-ID header on chat requests
sid="$(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid 2>/dev/null || python3 -c 'import uuid;print(uuid.uuid4())' 2>/dev/null)"
[ -z "$sid" ] && sid="$(head -c 16 /dev/urandom | od -An -tx1 | tr -d ' ')"
while IFS=',' read -r model key endpoint extra; do
[ -z "$model" ] && continue
case "$model" in *embed*) echo "Skipped (embedding model): $model @ $endpoint" >&2; continue;; esac
@@ -54,20 +60,22 @@ while IFS=',' read -r model key endpoint extra; do
echo "Skipped (endpoint unreachable): $model @ $endpoint" >&2
continue
fi
auth=''
[ "$key" != '-' ] && auth="-H Authorization: Bearer $key"
payload="$(jq -nc --arg m "$model" '{model:$m,messages:[{role:"user",content:"Reply with the word OK only."}],max_tokens:8,stream:true}')"
bodyf="$(mktemp)"
# Build curl args as a single-quoted list so each "-H Name: value" stays ONE
# argument. Unquoted variable expansion would word-split "Name: value" and turn
# the value into a stray URL, causing spurious "curl error 6" (couldn't resolve).
set -- -sS -4 -m 8 -o "$bodyf" -w '%{http_code}|%{time_starttransfer}' -X POST "$endpoint/chat/completions" -H 'Content-Type: application/json'
[ "$key" != '-' ] && set -- "$@" -H "Authorization: Bearer $key"
case "$endpoint" in *opencode.ai/zen*) set -- "$@" -H "X-Session-ID: $sid" -H "User-Agent: opencode/1.18.30";; esac
set -- "$@" -d "$payload"
attempt=0
max_attempts=3
ok=0
reason=''
while [ "$attempt" -lt "$max_attempts" ]; do
attempt=$((attempt+1))
out="$(curl -sS -m 8 -o "$bodyf" -w '%{http_code}|%{time_starttransfer}' \
-X POST "$endpoint/chat/completions" \
-H 'Content-Type: application/json' $auth \
-d "$payload" 2>/dev/null)"
out="$(curl "$@" 2>/dev/null)"
rc=$?
http_code="${out%%|*}"
ttft="${out##*|}"