BASH Post Services

Viewing: 1747803352_aigram.sh

Try wget https://bash.commongrounds.cc/uploads/1747803352_aigram.sh from the console

Raw File Link

#!/bin/bash

# Check if a prompt is provided
if [ -z "$1" ]; then
    echo "Error: Please provide a prompt in double quotes."
    exit 1
fi

# API key and endpoint
API_KEY="PLEASE PUT KEY HERE"
URL="https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$API_KEY"

# Escape the user prompt to handle special characters
PROMPT=$(echo "$1" | sed 's/"/\\"/g')

# Create JSON payload
PAYLOAD=$(printf '{"contents":[{"parts":[{"text":"%s"}]}]}' "$PROMPT")

# Make the API call and store response
RESPONSE=$(curl -s -X POST "$URL" \
    -H "Content-Type: application/json" \
    -d "$PAYLOAD" \
    -w "\n%{http_code}" \
    --limit-rate 1000000)

# Extract HTTP status code (last line)
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
# Extract JSON response (everything except last line)
JSON_RESPONSE=$(echo "$RESPONSE" | sed '$d')

# Check for successful response
if [ "$HTTP_CODE" -ne 200 ]; then
    echo "Error: API request failed with status code $HTTP_CODE"
    exit 1
fi

# Parse the response text and rate limit info
RESPONSE_TEXT=$(echo "$JSON_RESPONSE" | jq -r '.candidates[0].content.parts[0].text')
REMAINING_TOKENS=$(echo "$JSON_RESPONSE" | jq -r '.usageMetadata.totalTokenCount | tonumber | (1000 - .)')

# Output the response and remaining tokens
echo "$RESPONSE_TEXT"
echo "Remaining tokens: $REMAINING_TOKENS"
BASH to Home