summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/PerplexityLabs.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-17 10:33:23 +0200
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-04-17 10:33:23 +0200
commita2b5446b2e449f3107d9980d8eaac0a3ae07730f (patch)
treece1b1b8dc647d39f88242220db30c3636047d2fa /g4f/Provider/PerplexityLabs.py
parentadd cohere provider. (diff)
downloadgpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar.gz
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar.bz2
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar.lz
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar.xz
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.tar.zst
gpt4free-a2b5446b2e449f3107d9980d8eaac0a3ae07730f.zip
Diffstat (limited to '')
-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")