From 98895e5b09ea5e3f19b2263ddca028c7b296abb2 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 06:38:11 +0200 Subject: Update HuggingChat to new api Impersonate Aivvm Provider Add ChatForAi and FreeGpt Provider Update AItianhuSpace Provider Improve StreamRequest Support Update get_event_loop Helper --- g4f/Provider/PerplexityAi.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'g4f/Provider/PerplexityAi.py') diff --git a/g4f/Provider/PerplexityAi.py b/g4f/Provider/PerplexityAi.py index fc0fd48c..6e95fd51 100644 --- a/g4f/Provider/PerplexityAi.py +++ b/g4f/Provider/PerplexityAi.py @@ -4,8 +4,9 @@ import json import time import base64 from curl_cffi.requests import AsyncSession +from fake_useragent import UserAgent -from .base_provider import AsyncProvider, format_prompt +from .base_provider import AsyncProvider, format_prompt, get_cookies class PerplexityAi(AsyncProvider): @@ -23,18 +24,35 @@ class PerplexityAi(AsyncProvider): **kwargs ) -> str: url = cls.url + "/socket.io/?EIO=4&transport=polling" - async with AsyncSession(proxies={"https": proxy}, impersonate="chrome107") as session: + headers = { + "User-Agent": UserAgent().random, + "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() + + print(session.cookies) + 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), -- cgit v1.2.3 From 261fac86dcf278310d035f89f06e7f187e4ebf9c Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 1 Oct 2023 06:41:00 +0200 Subject: Disable PerplexityAi Provider --- g4f/Provider/PerplexityAi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'g4f/Provider/PerplexityAi.py') diff --git a/g4f/Provider/PerplexityAi.py b/g4f/Provider/PerplexityAi.py index 6e95fd51..612e2d98 100644 --- a/g4f/Provider/PerplexityAi.py +++ b/g4f/Provider/PerplexityAi.py @@ -11,7 +11,7 @@ from .base_provider import AsyncProvider, format_prompt, get_cookies class PerplexityAi(AsyncProvider): url = "https://www.perplexity.ai" - working = True + working = False supports_gpt_35_turbo = True _sources = [] -- cgit v1.2.3 From 2dbeb5460827d7e3792b4e6f5871463a430fa525 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 2 Oct 2023 02:06:33 +0200 Subject: Remove fake_useragent module --- g4f/Provider/PerplexityAi.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'g4f/Provider/PerplexityAi.py') diff --git a/g4f/Provider/PerplexityAi.py b/g4f/Provider/PerplexityAi.py index 612e2d98..c7e58ad3 100644 --- a/g4f/Provider/PerplexityAi.py +++ b/g4f/Provider/PerplexityAi.py @@ -4,7 +4,6 @@ import json import time import base64 from curl_cffi.requests import AsyncSession -from fake_useragent import UserAgent from .base_provider import AsyncProvider, format_prompt, get_cookies @@ -25,7 +24,6 @@ class PerplexityAi(AsyncProvider): ) -> str: url = cls.url + "/socket.io/?EIO=4&transport=polling" headers = { - "User-Agent": UserAgent().random, "Referer": f"{cls.url}/" } async with AsyncSession(headers=headers, proxies={"https": proxy}, impersonate="chrome107") as session: @@ -44,8 +42,6 @@ class PerplexityAi(AsyncProvider): response = await session.get(url, params={"t": timestamp(), "sid": sid}) response.raise_for_status() - print(session.cookies) - data = '40{"jwt":"anonymous-ask-user"}' response = await session.post(url, params={"t": timestamp(), "sid": sid}, data=data) response.raise_for_status() -- cgit v1.2.3