78 lines
2.0 KiB
Bash
78 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# exit if any command fails
|
|
set -e
|
|
|
|
usage() {
|
|
echo "Usage: $(basename $0) <conversation_id> <parent_id> <text>"
|
|
}
|
|
|
|
if [ ! $# -eq 3 ]; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z $TOKEN ]; then
|
|
echo "TOKEN must be set with OpenAI authorization bearer token (without Bearer prefix)"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$COOKIE" ]; then
|
|
echo "COOKIE must be set with OpenAI cookies"
|
|
exit 1
|
|
fi
|
|
|
|
CONVERSATION_ID=$1
|
|
PARENT_ID=$2
|
|
TEXT="$3"
|
|
|
|
# apparently, UUIDs are generated by the client :thinking:
|
|
# or this is not really necessary, but I'll do it anyway since that's what the web version does.
|
|
MID=$(python -c 'import uuid;print(uuid.uuid4())')
|
|
|
|
BODY="{
|
|
\"action\": \"next\",
|
|
\"messages\": [
|
|
{
|
|
\"id\": \"$MID\",
|
|
\"author\": {
|
|
\"role\": \"user\"
|
|
},
|
|
\"content\": {
|
|
\"content_type\": \"text\",
|
|
\"parts\": [
|
|
\"$TEXT\"
|
|
]
|
|
},
|
|
\"metadata\": {}
|
|
}
|
|
],
|
|
\"conversation_id\": \"$CONVERSATION_ID\",
|
|
\"parent_message_id\": \"$PARENT_ID\",
|
|
\"model\": \"text-davinci-002-render-sha\",
|
|
\"timezone_offset_min\": -120,
|
|
\"suggestions\": [],
|
|
\"history_and_training_disabled\": false,
|
|
\"arkose_token\": null
|
|
}"
|
|
|
|
curl 'https://chat.openai.com/backend-api/conversation' \
|
|
-H 'authority: chat.openai.com' \
|
|
-H 'accept: text/event-stream' \
|
|
-H 'accept-language: en-US' \
|
|
-H "authorization: Bearer $TOKEN" \
|
|
-H 'content-type: application/json' \
|
|
-H "cookie: $COOKIE" \
|
|
-H 'origin: https://chat.openai.com' \
|
|
-H 'referer: https://chat.openai.com/c/3ad5849d-5a51-4b8e-8974-669c965a3896' \
|
|
-H 'sec-ch-ua: "Chromium";v="116", "Not)A;Brand";v="24", "Brave";v="116"' \
|
|
-H 'sec-ch-ua-mobile: ?0' \
|
|
-H 'sec-ch-ua-platform: "Linux"' \
|
|
-H 'sec-fetch-dest: empty' \
|
|
-H 'sec-fetch-mode: cors' \
|
|
-H 'sec-fetch-site: same-origin' \
|
|
-H 'sec-gpc: 1' \
|
|
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36' \
|
|
--data-raw "$BODY" \
|
|
--compressed
|