diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-23 23:48:11 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-01-23 23:48:11 +0100 |
commit | 8864b70ee4bd405d9405263a63e3ada793b30ac1 (patch) | |
tree | 93987936dfd94b0b69b18736b9b6814d31424f3d /g4f/Provider/HuggingChat.py | |
parent | Add ProviderModelMixin for model selection (diff) | |
download | gpt4free-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/HuggingChat.py')
-rw-r--r-- | g4f/Provider/HuggingChat.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index d493da8f..a481ce7c 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -2,7 +2,7 @@ from __future__ import annotations import json, uuid -from aiohttp import ClientSession +from aiohttp import ClientSession, BaseConnector from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider, ProviderModelMixin @@ -33,6 +33,7 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin): messages: Messages, stream: bool = True, proxy: str = None, + connector: BaseConnector = None, web_search: bool = False, cookies: dict = None, **kwargs @@ -43,9 +44,16 @@ class HuggingChat(AsyncGeneratorProvider, ProviderModelMixin): headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.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( cookies=cookies, - headers=headers + headers=headers, + connector=connector ) as session: async with session.post(f"{cls.url}/conversation", json={"model": cls.get_model(model)}, proxy=proxy) as response: conversation_id = (await response.json())["conversationId"] |