Files

12 lines
663 B
Bash
Raw Permalink Normal View History

#!/bin/sh
# LLM backend for portal-trainer: prompt on stdin, text on stdout.
# Needs ANTHROPIC_API_KEY, curl and jq. MODEL and MAX_TOKENS override.
set -eu
: "${ANTHROPIC_API_KEY:?set ANTHROPIC_API_KEY}"
jq -Rs --arg model "${MODEL:-claude-sonnet-5}" --argjson max "${MAX_TOKENS:-16000}" \
'{model: $model, max_tokens: $max, messages: [{role: "user", content: .}]}' |
curl -sS --fail-with-body --max-time "${TIMEOUT:-600}" https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" -H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" --data-binary @- |
jq -er '[.content[] | select(.type == "text") | .text] | join("")'