summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/PerplexityLabs.py
diff options
context:
space:
mode:
Diffstat (limited to 'g4f/Provider/PerplexityLabs.py')
-rw-r--r--g4f/Provider/PerplexityLabs.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/g4f/Provider/PerplexityLabs.py b/g4f/Provider/PerplexityLabs.py
index ba956100..ab36d284 100644
--- a/g4f/Provider/PerplexityLabs.py
+++ b/g4f/Provider/PerplexityLabs.py
@@ -2,14 +2,13 @@ from __future__ import annotations
import random
import json
-from aiohttp import ClientSession, BaseConnector
from ..typing import AsyncResult, Messages
+from ..requests import StreamSession, raise_for_status
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
-from .helper import get_connector
-API_URL = "https://labs-api.perplexity.ai/socket.io/"
-WS_URL = "wss://labs-api.perplexity.ai/socket.io/"
+API_URL = "https://www.perplexity.ai/socket.io/"
+WS_URL = "wss://www.perplexity.ai/socket.io/"
class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
url = "https://labs.perplexity.ai"
@@ -35,7 +34,6 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
model: str,
messages: Messages,
proxy: str = None,
- connector: BaseConnector = None,
**kwargs
) -> AsyncResult:
headers = {
@@ -51,21 +49,22 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
"Sec-Fetch-Site": "same-site",
"TE": "trailers",
}
- async with ClientSession(headers=headers, connector=get_connector(connector, proxy)) as session:
+ async with StreamSession(headers=headers, proxies={"all": proxy}) as session:
t = format(random.getrandbits(32), "08x")
async with session.get(
f"{API_URL}?EIO=4&transport=polling&t={t}"
) as response:
+ await raise_for_status(response)
text = await response.text()
-
+ assert text.startswith("0")
sid = json.loads(text[1:])["sid"]
post_data = '40{"jwt":"anonymous-ask-user"}'
async with session.post(
f"{API_URL}?EIO=4&transport=polling&t={t}&sid={sid}",
data=post_data
) as response:
- assert await response.text() == "OK"
-
+ await raise_for_status(response)
+ assert await response.text() == "OK"
async with session.ws_connect(f"{WS_URL}?EIO=4&transport=websocket&sid={sid}", autoping=False) as ws:
await ws.send_str("2probe")
assert(await ws.receive_str() == "3probe")