From 88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Thu, 5 Oct 2023 05:13:37 +0200 Subject: Add AiAsk, Chatgpt4Online, ChatgptDemo and ChatgptX Provider Fix Bing, Liaobots and ChatgptAi Provider Add "gpt_35_long" model and custom timeout --- g4f/Provider/ChatgptDemo.py | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 g4f/Provider/ChatgptDemo.py (limited to 'g4f/Provider/ChatgptDemo.py') diff --git a/g4f/Provider/ChatgptDemo.py b/g4f/Provider/ChatgptDemo.py new file mode 100644 index 00000000..fdd7730b --- /dev/null +++ b/g4f/Provider/ChatgptDemo.py @@ -0,0 +1,62 @@ +from __future__ import annotations + +import time, json, re +from aiohttp import ClientSession +from typing import AsyncGenerator + +from .base_provider import AsyncGeneratorProvider +from .helper import format_prompt + +class ChatgptDemo(AsyncGeneratorProvider): + url = "https://chat.chatgptdemo.net" + supports_gpt_35_turbo = True + working = True + + @classmethod + async def create_async_generator( + cls, + model: str, + messages: list[dict[str, str]], + proxy: str = None, + timeout: int = 30, + **kwargs + ) -> AsyncGenerator: + headers = { + "authority": "chat.chatgptdemo.net", + "accept-language": "de-DE,de;q=0.9,en-DE;q=0.8,en;q=0.7,en-US", + "origin": "https://chat.chatgptdemo.net", + "referer": "https://chat.chatgptdemo.net/", + "sec-ch-ua": '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Linux"', + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" + } + async with ClientSession(headers=headers, timeout=timeout) as session: + async with session.get(f"{cls.url}/", proxy=proxy) as response: + response.raise_for_status() + response = await response.text() + result = re.search(r'