Skip to content

Commit

Permalink
Disabled provider (g4f/Provider/ChatGptt.py > g4f/Provider/not_workin…
Browse files Browse the repository at this point in the history
…g/ChatGptt.py): Problem with Cloudflare
  • Loading branch information
kqlio67 committed Feb 5, 2025
1 parent 7b5dcda commit 9cb3641
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 0 additions & 1 deletion g4f/Provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from .ChatGLM import ChatGLM
from .ChatGpt import ChatGpt
from .ChatGptEs import ChatGptEs
from .ChatGptt import ChatGptt
from .Cloudflare import Cloudflare
from .Copilot import Copilot
from .DDG import DDG
Expand Down
30 changes: 21 additions & 9 deletions g4f/Provider/ChatGptt.py → g4f/Provider/not_working/ChatGptt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import os
import re

from aiohttp import ClientSession

from ..typing import AsyncResult, Messages
from ..requests.raise_for_status import raise_for_status
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
from .helper import format_prompt
from ...typing import AsyncResult, Messages
from ...requests.raise_for_status import raise_for_status
from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
from ..helper import format_prompt

class ChatGptt(AsyncGeneratorProvider, ProviderModelMixin):
url = "https://chatgptt.me"
api_endpoint = "https://chatgptt.me/wp-admin/admin-ajax.php"

working = True
working = False
supports_stream = True
supports_system_message = True
supports_message_history = True
Expand All @@ -41,10 +40,22 @@ async def create_async_generator(
}

async with ClientSession(headers=headers) as session:
# Get initial page content
initial_response = await session.get(cls.url)
nonce_ = re.findall(r'data-nonce="(.+?)"', await initial_response.text())[0]
post_id = re.findall(r'data-post-id="(.+?)"', await initial_response.text())[0]
await raise_for_status(initial_response)
html = await initial_response.text()

# Extract nonce and post ID with error handling
nonce_match = re.search(r'data-nonce=["\']([^"\']+)["\']', html)
post_id_match = re.search(r'data-post-id=["\']([^"\']+)["\']', html)

if not nonce_match or not post_id_match:
raise RuntimeError("Required authentication tokens not found in page HTML")

nonce_ = nonce_match.group(1)
post_id = post_id_match.group(1)

# Prepare payload with session data
payload = {
'_wpnonce': nonce_,
'post_id': post_id,
Expand All @@ -57,7 +68,8 @@ async def create_async_generator(
'wpaicg_chat_history': None
}

# Stream the response
async with session.post(cls.api_endpoint, headers=headers, data=payload, proxy=proxy) as response:
await raise_for_status(response)
result = await response.json()
yield result['data']
yield result['data']
1 change: 1 addition & 0 deletions g4f/Provider/not_working/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .Chatgpt4o import Chatgpt4o
from .Chatgpt4Online import Chatgpt4Online
from .ChatgptFree import ChatgptFree
from .ChatGptt import ChatGptt
from .DarkAI import DarkAI
from .FlowGpt import FlowGpt
from .FreeNetfly import FreeNetfly
Expand Down

0 comments on commit 9cb3641

Please sign in to comment.