Отправьте большой объем текста в заголовке запроса.Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Отправьте большой объем текста в заголовке запроса.

Сообщение Anonymous »

Я пытаюсь отправить это в заголовке запроса, используя Python и Curl:
Hi hi, ChatGPT!!

I'd like you to write me a fundraiser for anything random, your going to come up with the whole thing,
just make sure it's not a business idea or anything like that or some creative idea, make it be about a single mother, in debt,
need help paying bills, need money for my pet, need money for my Grandma, needing money for a family member or anything like that,
your going to make all the names up, make them simple, and emotional that makes readers feel bad maybe a little sad, and yeah, just make
it be randomised with all that in mind.

Also, make it seem as if it's the writer you that's facing the problem, and use "I" more, and make them seem realistic, and relatable ish,
and make sure there based in either the UK or the US, and make the names not be to generic or to common.

Ensure the fundraiser title is on the very first line, make sure the name you've generated is on the very 2nd line, and the
category to be one of the following, and depending on the one it is you've picked, for you to just put the number of it on the very 3rd line:

1 = Uncategorized
2 = Emergency Money
3 = Mortgage
4 = Medical Bills
5 = Single Moms
6 = Business Capital
7 = Tuition Fees
8 = Rent
9 = Funeral Costs
10 = Eviction Notice
11 = Dental
12 = Car Repairs
13 = Home Foreclosure
14 = Scammers
18 = Wishes
19 = Animals
23 = Begpackers
50 = Student Loans
52 = Single Dads

Another reminder, make sure to put UK on the very 4th line if it's UK based, and US if it's US based on the very 4th line, then a line space,
and all of the content.

[Please do not say anything else besides that]

Вся подсказка хранится в Data/Prompt.txt, и этот скрипт Python должен прочитать ее и отправить в заголовке запроса в Curl:
# Import some libs
import Helper
import subprocess
#import GenerateUA
#import GenerateCookie

# Clear the terminal!!
Helper.Clear()

# Grab all the prompt from Prompt.txt and save the prompt as a variable
with open('Data/Prompt.txt', 'r', encoding='utf-8') as prompt:
# Read the entire content of the file
ChatGPT_Request = prompt.read()

# Prepare a user agent to use
#UserAgent = GenerateUA.GeneratedUserAgent
UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6575.168 Safari/537.36"

# Prepare a cookie to use
#Cookie = GenerateCookie.GeneratedCookie
Cookie = "YOUR-COOKIE-HERE"

# Define the basic boring info, most likely you don't need to change any of this
url = "https://talkai.info/chat/send/"
method = "-X POST"
compressed = "--compressed"
accept = '-H "Accept: application/json, text/event-stream"'
accept_language = '-H "Accept-Language: en-GB,en;q=0.5"'
accept_encoding = '-H "Accept-Encoding: gzip, deflate"'
referer = '-H "Referer: https://talkai.info/chat/"'
content_type = '-H "content-type: application/json"'
origin = '-H "Origin: https://talkai.info"'
messages_history_start = '"messagesHistory":['

# Defining all the interesting info
#api_key = ""
Type = "chat"
Model = "gpt-4o-mini"
#ChatID = ""
Content = ChatGPT_Request

# Define each part of the CURL command as variables
user_agent_header = f'-H "User-Agent: {UserAgent}"'
header_cookie = f'-H "Cookie: {Cookie}"'
data_type = f'"type":"{Type}"'

message_id_start = '{"id":"'
#message_id = ChatID
message_id_end = '"'

message_from = '"from":"you"'

# Send the message to ChatGPT
message_content_start = '"content":"'
message_content = Content
message_content_end = '"}'

messages_history_end = ']'
settings_start = '"settings":{'
model = f'"model":"{Model}"'
settings_end = '}'

# Combine the chunks to form the full data_raw content
data_raw = f"--data-raw '{{{data_type},{messages_history_start}{message_id_start}, {message_id_end}, {message_from},{message_content_start}{message_content}{message_content_end}{messages_history_end},{settings_start}{model}{settings_end}}}'"

# Combine all parts into a single curl command
curl_command = f"curl '{url}' {compressed} {method} {user_agent_header} {accept} {accept_language} {accept_encoding} {referer} {content_type} {origin} {header_cookie} {data_raw}"

# Run the combinined CURL command, with all the data and everything
result = subprocess.run(curl_command, shell=True, capture_output=True, text=True)

# Print the CURL command output
print(result.stdout)
#print("Error:", result.stderr) #uncomment this out if needed

Как видите, в сценарии он определяет содержимое для отправки в ChatGPT из файла Data/Prompt.txt, который является приглашением, которое я уже показывал.
Этот скрипт Python работает, и у меня не было с ним проблем, однако, когда я использую текст в Data/Prompt.txt, даже определенный непосредственно в коде как переменная, она по-прежнему не работает, кажется, она работает только тогда, когда это небольшой текст, например «привет» или «привет», всякий раз, когда я делаю это с большим фрагментом текста, я получаю эту ошибку:
{"errors":["Attempt to read property \"type\" on null"],"code":400}


Подробнее здесь: https://stackoverflow.com/questions/790 ... est-header
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Объем отправьте таблицу, созданную шаблоном Jinja2 в колбу
    Anonymous » » в форуме Html
    0 Ответы
    27 Просмотры
    Последнее сообщение Anonymous
  • Объем отправьте таблицу, созданную шаблоном Jinja2 в колбу
    Anonymous » » в форуме Html
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Объем отправьте таблицу, созданную шаблоном Jinja2 в колбу
    Anonymous » » в форуме Html
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Строка, определенная в заголовке A, не определена в заголовке B [закрыто]
    Anonymous » » в форуме C++
    0 Ответы
    3 Просмотры
    Последнее сообщение Anonymous
  • Android. Как эффективно загрузить большой объем текста в TextView?
    Anonymous » » в форуме JAVA
    0 Ответы
    11 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»