mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-15 14:51:19 -08:00
Add aiohttp_socks support
This commit is contained in:
parent
91feb34054
commit
8864b70ee4
6 changed files with 61 additions and 23 deletions
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import uuid
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from aiohttp import ClientSession, BaseConnector
|
||||
|
||||
from ..typing import AsyncResult, Messages
|
||||
from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
|
||||
|
|
@ -91,6 +91,7 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
messages: Messages,
|
||||
auth: str = None,
|
||||
proxy: str = None,
|
||||
connector: BaseConnector = None,
|
||||
**kwargs
|
||||
) -> AsyncResult:
|
||||
headers = {
|
||||
|
|
@ -100,9 +101,16 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
"referer": f"{cls.url}/",
|
||||
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
|
||||
}
|
||||
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,
|
||||
cookie_jar=cls._cookie_jar
|
||||
cookie_jar=cls._cookie_jar,
|
||||
connector=connector
|
||||
) as session:
|
||||
cls._auth_code = auth if isinstance(auth, str) else cls._auth_code
|
||||
if not cls._auth_code:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue