diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-04-17 10:43:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 10:43:11 +0200 |
commit | 6afc6722a05f6d4498e6dcf19a7689ad58ffd444 (patch) | |
tree | 7b8ab362992408b78838df82a5172be15272a485 /g4f/Provider/PerplexityLabs.py | |
parent | Merge pull request #1833 from hlohaus/curl (diff) | |
parent | Fix style.css (diff) | |
download | gpt4free-0.2.9.10.tar gpt4free-0.2.9.10.tar.gz gpt4free-0.2.9.10.tar.bz2 gpt4free-0.2.9.10.tar.lz gpt4free-0.2.9.10.tar.xz gpt4free-0.2.9.10.tar.zst gpt4free-0.2.9.10.zip |
Diffstat (limited to 'g4f/Provider/PerplexityLabs.py')
-rw-r--r-- | g4f/Provider/PerplexityLabs.py | 17 |
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") |