diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-09-22 21:40:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 21:40:59 +0200 |
commit | ba287e89b55118965ff0e151e54636b1f50d3b38 (patch) | |
tree | dc69218fecae4971c90ae391ff6919c032b93540 /g4f/Provider/HuggingChat.py | |
parent | ~ | gpt-3.5-turbo-0613 (diff) | |
parent | Add RetryProvider (diff) | |
download | gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.gz gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.bz2 gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.lz gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.xz gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.zst gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.zip |
Diffstat (limited to 'g4f/Provider/HuggingChat.py')
-rw-r--r-- | g4f/Provider/HuggingChat.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index 85f879f3..7702c9dd 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -25,10 +25,10 @@ class HuggingChat(AsyncGeneratorProvider): **kwargs ) -> AsyncGenerator: model = model if model else cls.model - if not cookies: - cookies = get_cookies(".huggingface.co") if proxy and "://" not in proxy: proxy = f"http://{proxy}" + if not cookies: + cookies = get_cookies(".huggingface.co") 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', @@ -37,7 +37,7 @@ class HuggingChat(AsyncGeneratorProvider): cookies=cookies, headers=headers ) as session: - async with session.post("https://huggingface.co/chat/conversation", proxy=proxy, json={"model": model}) as response: + async with session.post(f"{cls.url}/conversation", proxy=proxy, json={"model": model}) as response: conversation_id = (await response.json())["conversationId"] send = { @@ -62,7 +62,7 @@ class HuggingChat(AsyncGeneratorProvider): "web_search_id": "" } } - async with session.post(f"https://huggingface.co/chat/conversation/{conversation_id}", proxy=proxy, json=send) as response: + async with session.post(f"{cls.url}/conversation/{conversation_id}", proxy=proxy, json=send) as response: if not stream: data = await response.json() if "error" in data: @@ -76,8 +76,6 @@ class HuggingChat(AsyncGeneratorProvider): first = True async for line in response.content: line = line.decode("utf-8") - if not line: - continue if line.startswith(start): line = json.loads(line[len(start):-1]) if "token" not in line: @@ -89,7 +87,7 @@ class HuggingChat(AsyncGeneratorProvider): else: yield line["token"]["text"] - async with session.delete(f"https://huggingface.co/chat/conversation/{conversation_id}", proxy=proxy) as response: + async with session.delete(f"{cls.url}/conversation/{conversation_id}", proxy=proxy) as response: response.raise_for_status() |