From cba121daac8a0365fc192a901d8d3023f13fa535 Mon Sep 17 00:00:00 2001 From: kqlio67 Date: Thu, 3 Oct 2024 01:15:38 +0300 Subject: feat(g4f/Provider/ChatGpt.py): enhance error handling and add debugging 2 --- g4f/Provider/ChatGpt.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/g4f/Provider/ChatGpt.py b/g4f/Provider/ChatGpt.py index 37ad17d8..b5a78b9a 100644 --- a/g4f/Provider/ChatGpt.py +++ b/g4f/Provider/ChatGpt.py @@ -136,7 +136,6 @@ class ChatGpt(AbstractProvider, ProviderModelMixin): response = session.post('https://chatgpt.com/backend-anon/sentinel/chat-requirements', headers=headers, json={'p': pow_req}) - # Додана перевірка на статус відповідей, якщо "незвична активність" if response.status_code != 200: print(f"Request failed with status: {response.status_code}") print(f"Response content: {response.content}") @@ -199,7 +198,6 @@ class ChatGpt(AbstractProvider, ProviderModelMixin): }, } - # Додав паузу між запитами для уникнення блокувань через частоту time.sleep(2) response = session.post('https://chatgpt.com/backend-anon/conversation', @@ -209,10 +207,10 @@ class ChatGpt(AbstractProvider, ProviderModelMixin): for line in response.iter_lines(): if line: decoded_line = line.decode() - print(f"Received line: {decoded_line}") # Debugging output + print(f"Received line: {decoded_line}") if decoded_line.startswith('data:'): - json_string = decoded_line[6:] # Extract JSON part after 'data:' - if json_string.strip(): # Check if there's actual content + json_string = decoded_line[6:] + if json_string.strip(): try: data = json.loads(json_string) except json.JSONDecodeError as e: -- cgit v1.2.3