# shellcheck shell=dash

# Define function tools
#   -d '{"contents":[{"parts":[{"text":"Write a story about a magic backpack"}]}]}' \
___x_cmd_gemini_request_generaxwtecontent(){
    local model="${1:-"$___X_CMD_GEMINI_DEFAULT_FIRST_MODEL"}"
    local is_stream="$2"
    local apikey=
    local proxy=
    ___x_cmd_gemini_cur   apikey:=   proxy:=   2>/dev/null

    local gen_endpoint="generateContent"
    [ "$is_stream" != 1 ] || gen_endpoint="streamGenerateContent"

    gemini:info "Requesting Gemini [model=$model]"
    ___x_cmd proxy runifset "$proxy" \
        ___x_cmd curl -s -X POST            \
        "${___X_CMD_GEMINI_ENDPOINT}/v1beta/models/${model}:${gen_endpoint}" \
        -H "x-goog-api-key: $apikey"        \
        -H 'Content-Type: application/json' \
        ${is_stream:+"--no-buffer"} \
        -d @-
}
