Zai-Kun / reverse-engineered-chatgpt

Unofficial reverse-engineered ChatGPT API in Python
Apache License 2.0
258 stars 35 forks source link

gpt3 runs for a period of time will report errors. #22

Closed yayaQAQ closed 8 months ago

yayaQAQ commented 10 months ago

gpt3 runs for a period of time will report errors, and stuck, how to improve this? Replacing the session token will work for a while, but it will still be a problem after a while. Could it be a matter of proxy?

root@gpu3090:/home# python rungpt.py
# 雅鲁藏布江见闻

雅鲁藏布江,又称雅鲁藏布大峡谷,是中国最深的峡谷之一,蜿蜒曲折,横贯西藏自治区。其河流起源于西藏的昆仑山脉,向东流经喜马拉雅山脉,最终注入印度洋。雅鲁藏布江的壮丽景色和悠久历史吸引着无数探险者和旅行者。在这篇文章中,我们将一同探访雅鲁藏布江,领略其独特之美。

## 1. 奔流的江水

雅鲁藏布江的水源头位于西藏的昆仑山脉,冰雪融化形成的江水发源于高原,清澈而富有营养。在高原的怀抱中,江水奔腾而下,蜿蜒曲折,形成了令人叹为观止的壮丽景象。江水的奔流不息,仿佛是大地的血液,滋养着这片神秘Exception in thread Thread-1 (perform_request):
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/curl_cffi/requests/session.py", line 695, in request
    c.perform()
  File "/usr/local/lib/python3.12/site-packages/curl_cffi/curl.py", line 257, in perform
    self._check_error(ret, action="perform")
  File "/usr/local/lib/python3.12/site-packages/curl_cffi/curl.py", line 112, in _check_error
    raise error
curl_cffi.curl.CurlError: Failed to perform, ErrCode: 92, Reason: 'HTTP/2 stream 1 was not closed cleanly before end of the underlying stream'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/site-packages/re_gpt/sync_chatgpt.py", line 154, in perform_request
    response = self.chatgpt.session.post(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/curl_cffi/requests/session.py", line 699, in request
    raise RequestsError(str(e), e.code, rsp) from e
curl_cffi.requests.errors.RequestsError: Failed to perform, ErrCode: 92, Reason: 'HTTP/2 stream 1 was not closed cleanly before end of the underlying stream'. This may be a libcurl error, See https://curl.se/libcurl/c/libcurl-errors.html first for more details.
yayaQAQ commented 10 months ago

my code, I am testing the stability of the service and determining whether it will be blocked and so on.

def gpt3():
    count = 1
    session_token = "my token here"
    while 1:
        try:
            with SyncChatGPT(session_token=session_token) as chatgpt:
                prompt = "请帮我生成一篇关于'雅鲁藏布江见闻'的文章,使用Markdown进行排版。至少要1000字。"
                conversation = chatgpt.create_new_conversation()
                for message in conversation.chat(prompt):
                    print(message["content"], flush=True, end="")
                print(f"\n-----------------------第{count}次-------------------\n")
                time.sleep(3+3*random.random())
                count += 1
        except Exception as e:
            print(e)
            print(f"\n-----------------------第{count}次-------------------\n")
            time.sleep(3+3*random.random())
Zai-Kun commented 10 months ago

my code, I am testing the stability of the service and determining whether it will be blocked and so on.

def gpt3():
    count = 1
    session_token = "my token here"
    while 1:
        try:
            with SyncChatGPT(session_token=session_token) as chatgpt:
                prompt = "请帮我生成一篇关于'雅鲁藏布江见闻'的文章,使用Markdown进行排版。至少要1000字。"
                conversation = chatgpt.create_new_conversation()
                for message in conversation.chat(prompt):
                    print(message["content"], flush=True, end="")
                print(f"\n-----------------------第{count}次-------------------\n")
                time.sleep(3+3*random.random())
                count += 1
        except Exception as e:
            print(e)
            print(f"\n-----------------------第{count}次-------------------\n")
            time.sleep(3+3*random.random())

Why are you initializing SyncChatGPT again and again? Only initialize it once. Every time SyncChatGPT/AsyncChatGPT is initialized, it retrieves an auth token from chatgpt with the session token you provide. initializing them multiple times when you can just initialize them once is inefficient and may cause unexpected errors. And I've never encountered this issue before.

yayaQAQ commented 10 months ago

my code, I am testing the stability of the service and determining whether it will be blocked and so on.

def gpt3():
    count = 1
    session_token = "my token here"
    while 1:
        try:
            with SyncChatGPT(session_token=session_token) as chatgpt:
                prompt = "请帮我生成一篇关于'雅鲁藏布江见闻'的文章,使用Markdown进行排版。至少要1000字。"
                conversation = chatgpt.create_new_conversation()
                for message in conversation.chat(prompt):
                    print(message["content"], flush=True, end="")
                print(f"\n-----------------------第{count}次-------------------\n")
                time.sleep(3+3*random.random())
                count += 1
        except Exception as e:
            print(e)
            print(f"\n-----------------------第{count}次-------------------\n")
            time.sleep(3+3*random.random())

Why are you initializing SyncChatGPT again and again? Only initialize it once. Every time SyncChatGPT/AsyncChatGPT is initialized, it retrieves an auth token from chatgpt with the session token you provide. initializing them multiple times when you can just initialize them once is inefficient and may cause unexpected errors. And I've never encountered this issue before.

ok, I will try it.

yayaQAQ commented 10 months ago

Change to only one authentication, and do not go to the agent, there is no problem. But there's another problem, it seems that gpt3 also has a number limit, right? Only 52 requests in an hour? But I also use the same account on the web page is normal use

image
Zai-Kun commented 10 months ago

Only 52 requests in an hour? But I also use the same account on the web page is normal use

If you can still use chatgpt on the web just fine after hitting the limit, it's quite an issue. I'll have to test this myself and see what is causing this.

yayaQAQ commented 10 months ago

Only 52 requests in an hour? But I also use the same account on the web page is normal use

If you can still use chatgpt on the web just fine after hitting the limit, it's quite an issue. I'll have to test this myself and see what is causing this.

ok👌, this is my code. hope it helps.

from re_gpt import SyncChatGPT
import time
import random
import requests
import json
import argparse

def gpt3():
    session_token = "token here"
    success_count = 0
    error_count = 0

    for item in range(100):
        try:
            with SyncChatGPT(session_token=session_token) as chatgpt:
                while 1:
                    prompt = "请帮我生成一篇关于'雅鲁藏布江见闻'的文章,使用Markdown进行排版。至少要1000字。"
                    conversation = chatgpt.create_new_conversation()
                    for message in conversation.chat(prompt):
                        print(message["content"], flush=True, end="")
                    print(f"\n-----------------------成功{success_count}失败{error_count}-------------------\n")
                    time.sleep(5+3*random.random())
                    success_count += 1
        except Exception as e:
            print(e)
            print(f"\n-----------------------成功{success_count}失败{error_count}-------------------\n")
            error_count += 1
            time.sleep(3+3*random.random())
jxyk2007 commented 10 months ago

gpt3 正常的很。