From 6c195215db76f169711ea85efd26fd867129a189 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 9 Sep 2023 13:27:52 +0200 Subject: [PATCH] Basic prompt script --- prompt.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 prompt.sh diff --git a/prompt.sh b/prompt.sh new file mode 100644 index 0000000..723ac9d --- /dev/null +++ b/prompt.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +# exit if any command fails +set -e + +usage() { + echo "Usage: $(basename $0) " +} + +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