diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-05 05:13:37 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-05 05:13:37 +0200 |
commit | 88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9 (patch) | |
tree | 7e6e3b6c179cf1a695f9d80026d544a4fd3c5203 /g4f/Provider/deprecated | |
parent | ~ | g4f v-0.1.4.8 - Fixed `g4f.Provider.Bing` (diff) | |
download | gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.gz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.bz2 gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.lz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.xz gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.tar.zst gpt4free-88d2cbff099df00944ed6dfb6c73b1b5e8dfc7f9.zip |
Diffstat (limited to 'g4f/Provider/deprecated')
-rw-r--r-- | g4f/Provider/deprecated/PerplexityAi.py | 101 | ||||
-rw-r--r-- | g4f/Provider/deprecated/__init__.py | 1 |
2 files changed, 0 insertions, 102 deletions
diff --git a/g4f/Provider/deprecated/PerplexityAi.py b/g4f/Provider/deprecated/PerplexityAi.py deleted file mode 100644 index f4f71712..00000000 --- a/g4f/Provider/deprecated/PerplexityAi.py +++ /dev/null @@ -1,101 +0,0 @@ -from __future__ import annotations - -import json -import time -import base64 -from curl_cffi.requests import AsyncSession - -from ..base_provider import AsyncProvider, format_prompt, get_cookies - - -class PerplexityAi(AsyncProvider): - url = "https://www.perplexity.ai" - working = False - supports_gpt_35_turbo = True - _sources = [] - - @classmethod - async def create_async( - cls, - model: str, - messages: list[dict[str, str]], - proxy: str = None, - **kwargs - ) -> str: - url = cls.url + "/socket.io/?EIO=4&transport=polling" - headers = { - "Referer": f"{cls.url}/" - } - async with AsyncSession(headers=headers, proxies={"https": proxy}, impersonate="chrome107") as session: - url_session = "https://www.perplexity.ai/api/auth/session" - response = await session.get(url_session) - response.raise_for_status() - - url_session = "https://www.perplexity.ai/api/auth/session" - response = await session.get(url_session) - response.raise_for_status() - - response = await session.get(url, params={"t": timestamp()}) - response.raise_for_status() - sid = json.loads(response.text[1:])["sid"] - - response = await session.get(url, params={"t": timestamp(), "sid": sid}) - response.raise_for_status() - - data = '40{"jwt":"anonymous-ask-user"}' - response = await session.post(url, params={"t": timestamp(), "sid": sid}, data=data) - response.raise_for_status() - - response = await session.get(url, params={"t": timestamp(), "sid": sid}) - response.raise_for_status() - - data = "424" + json.dumps([ - "perplexity_ask", - format_prompt(messages), - { - "version":"2.1", - "source":"default", - "language":"en", - "timezone": time.tzname[0], - "search_focus":"internet", - "mode":"concise" - } - ]) - response = await session.post(url, params={"t": timestamp(), "sid": sid}, data=data) - response.raise_for_status() - - while True: - response = await session.get(url, params={"t": timestamp(), "sid": sid}) - response.raise_for_status() - for line in response.text.splitlines(): - if line.startswith("434"): - result = json.loads(json.loads(line[3:])[0]["text"]) - - cls._sources = [{ - "title": source["name"], - "url": source["url"], - "snippet": source["snippet"] - } for source in result["web_results"]] - - return result["answer"] - - @classmethod - def get_sources(cls): - return cls._sources - - - @classmethod - @property - def params(cls): - params = [ - ("model", "str"), - ("messages", "list[dict[str, str]]"), - ("stream", "bool"), - ("proxy", "str"), - ] - param = ", ".join([": ".join(p) for p in params]) - return f"g4f.provider.{cls.__name__} supports: ({param})" - - -def timestamp() -> str: - return base64.urlsafe_b64encode(int(time.time()-1407782612).to_bytes(4, 'big')).decode()
\ No newline at end of file diff --git a/g4f/Provider/deprecated/__init__.py b/g4f/Provider/deprecated/__init__.py index 8d22a3c3..e4528d02 100644 --- a/g4f/Provider/deprecated/__init__.py +++ b/g4f/Provider/deprecated/__init__.py @@ -6,7 +6,6 @@ from .Forefront import Forefront from .GetGpt import GetGpt from .Opchatgpts import Opchatgpts from .Lockchat import Lockchat -from .PerplexityAi import PerplexityAi from .Wewordle import Wewordle from .Equing import Equing from .Wuguokai import Wuguokai |