summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/PerplexityAi.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-10-01 06:38:11 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-10-01 06:38:11 +0200
commit98895e5b09ea5e3f19b2263ddca028c7b296abb2 (patch)
tree514883128a48dcd4d337a97d061f1fa5f1e1db4a /g4f/Provider/PerplexityAi.py
parent~ | v-0.1.4.2 `pip install -U g4f` (diff)
downloadgpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar.gz
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar.bz2
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar.lz
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar.xz
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.tar.zst
gpt4free-98895e5b09ea5e3f19b2263ddca028c7b296abb2.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/PerplexityAi.py22
1 files changed, 20 insertions, 2 deletions
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),