summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/PerplexityLabs.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-23 23:48:11 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-23 23:48:11 +0100
commit8864b70ee4bd405d9405263a63e3ada793b30ac1 (patch)
tree93987936dfd94b0b69b18736b9b6814d31424f3d /g4f/Provider/PerplexityLabs.py
parentAdd ProviderModelMixin for model selection (diff)
downloadgpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar.gz
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar.bz2
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar.lz
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar.xz
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.tar.zst
gpt4free-8864b70ee4bd405d9405263a63e3ada793b30ac1.zip
Diffstat (limited to 'g4f/Provider/PerplexityLabs.py')
-rw-r--r--g4f/Provider/PerplexityLabs.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/g4f/Provider/PerplexityLabs.py b/g4f/Provider/PerplexityLabs.py
index 90258da5..9b11b708 100644
--- a/g4f/Provider/PerplexityLabs.py
+++ b/g4f/Provider/PerplexityLabs.py
@@ -2,7 +2,7 @@ from __future__ import annotations
import random
import json
-from aiohttp import ClientSession
+from aiohttp import ClientSession, BaseConnector
from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
@@ -32,6 +32,7 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
model: str,
messages: Messages,
proxy: str = None,
+ connector: BaseConnector = None,
**kwargs
) -> AsyncResult:
headers = {
@@ -47,7 +48,13 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
"Sec-Fetch-Site": "same-site",
"TE": "trailers",
}
- async with ClientSession(headers=headers) as session:
+ if proxy and not connector:
+ try:
+ from aiohttp_socks import ProxyConnector
+ connector = ProxyConnector.from_url(proxy)
+ except ImportError:
+ raise RuntimeError('Install "aiohttp_socks" package for proxy support')
+ async with ClientSession(headers=headers, connector=connector) as session:
t = format(random.getrandbits(32), '08x')
async with session.get(
f"{API_URL}?EIO=4&transport=polling&t={t}",