#!/usr/bin/env bash
# Amazon Ergo on Amazon Bedrock from the AWS CLI: one request, then the answer and token usage.
#
# Needs: AWS CLI 2.37.0 or later (aws --version). Tested with 2.37.0.
#        Installers for that exact version:
#          macOS    https://awscli.amazonaws.com/AWSCLIV2-2.37.0.pkg
#          Linux    https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.37.0.zip
#          Windows  https://awscli.amazonaws.com/AWSCLIV2-2.37.0.msi
#        Credentials with bedrock:InvokeModel on the Ergo inference profile.
#
# Run:   ./quickstart.sh
#        ./quickstart.sh "Write a Go function that merges two sorted slices." high
set -euo pipefail
PROMPT="${1:-Write a Python function that checks whether a string is a palindrome. Code only.}"
EFFORT="${2:-low}"   # low | medium | high | xhigh | max

aws bedrock-runtime converse \
  --region us-east-1 \
  --model-id global.amazon.ergo-1.0 \
  --messages "$(jq -n --arg p "$PROMPT" '[{role: "user", content: [{text: $p}]}]')" \
  --inference-config maxTokens=16384 \
  --output-config effort="$EFFORT" \
  --query '{answer: output.message.content[?text].text | [0], usage: usage, latencyMs: metrics.latencyMs}' \
  --output json
