diff options
author | abc <98614666+xtekky@users.noreply.github.com> | 2024-06-29 16:00:50 +0200 |
---|---|---|
committer | abc <98614666+xtekky@users.noreply.github.com> | 2024-06-29 16:00:50 +0200 |
commit | 46c48bb09e38944b02ffd28a4384c420d91d0e9c (patch) | |
tree | fcc9f0382844b1471878c8c46adfcac681d53ef3 /g4f/Provider | |
parent | unpatch HuggingChat (diff) | |
download | gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar.gz gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar.bz2 gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar.lz gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar.xz gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.tar.zst gpt4free-46c48bb09e38944b02ffd28a4384c420d91d0e9c.zip |
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/Aichatos.py | 1 | ||||
-rw-r--r-- | g4f/Provider/HuggingChat.py | 77 | ||||
-rw-r--r-- | g4f/Provider/deprecated/Acytoo.py | 6 |
3 files changed, 43 insertions, 41 deletions
diff --git a/g4f/Provider/Aichatos.py b/g4f/Provider/Aichatos.py index 427aa0e7..1d4747d7 100644 --- a/g4f/Provider/Aichatos.py +++ b/g4f/Provider/Aichatos.py @@ -8,7 +8,6 @@ from .helper import format_prompt import random - class Aichatos(AsyncGeneratorProvider): url = "https://chat10.aichatos.xyz" api = "https://api.binjie.fun" diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index cb8405ae..00d49b82 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -5,7 +5,7 @@ import json, requests, re from curl_cffi import requests as cf_reqs from ..typing import CreateResult, Messages from .base_provider import ProviderModelMixin, AbstractProvider -from .helper import format_prompt, get_connector, get_cookies +from .helper import format_prompt class HuggingChat(AbstractProvider, ProviderModelMixin): url = "https://huggingface.co/chat" @@ -41,34 +41,34 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): session = requests.Session() headers = { - 'accept': '*/*', - 'accept-language': 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', - 'cache-control': 'no-cache', - 'origin': 'https://huggingface.co', - 'pragma': 'no-cache', - 'priority': 'u=1, i', - 'referer': 'https://huggingface.co/chat/', - 'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"', - 'sec-ch-ua-mobile': '?0', + 'accept' : '*/*', + 'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3', + 'cache-control' : 'no-cache', + 'origin' : 'https://huggingface.co', + 'pragma' : 'no-cache', + 'priority' : 'u=1, i', + 'referer' : 'https://huggingface.co/chat/', + 'sec-ch-ua' : '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"', + 'sec-ch-ua-mobile' : '?0', 'sec-ch-ua-platform': '"macOS"', - 'sec-fetch-dest': 'empty', - 'sec-fetch-mode': 'cors', - 'sec-fetch-site': 'same-origin', - 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', + 'sec-fetch-dest' : 'empty', + 'sec-fetch-mode' : 'cors', + 'sec-fetch-site' : 'same-origin', + 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', } json_data = { - 'searchEnabled': True, - 'ethicsModalAccepted': True, - 'ethicsModalAcceptedAt': None, - 'activeModel': 'CohereForAI/c4ai-command-r-plus', # doesn't matter + 'searchEnabled' : True, + 'activeModel' : 'CohereForAI/c4ai-command-r-plus', # doesn't matter 'hideEmojiOnSidebar': False, + 'customPrompts' : {}, + 'assistants' : [], + 'tools' : {}, + 'disableStream' : False, + 'recentlySaved' : False, + 'ethicsModalAccepted' : True, + 'ethicsModalAcceptedAt' : None, 'shareConversationsWithModelAuthors': False, - 'customPrompts': {}, - 'assistants': [], - 'tools': {}, - 'disableStream': False, - 'recentlySaved': False, } response = cf_reqs.post('https://huggingface.co/chat/settings', headers=headers, json=json_data) @@ -85,20 +85,20 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): messageId = extract_id(response.json()) settings = { - "inputs": format_prompt(messages), - "id": messageId, - "is_retry": False, - "is_continue": False, - "web_search": False, + "inputs" : format_prompt(messages), + "id" : messageId, + "is_retry" : False, + "is_continue" : False, + "web_search" : False, - # enable tools + # TODO // add feature to enable/disable tools "tools": { - "websearch": True, - "document_parser": False, - "query_calculator": False, - "image_generation": False, - "image_editing": False, - "fetch_url": False, + "websearch" : True, + "document_parser" : False, + "query_calculator" : False, + "image_generation" : False, + "image_editing" : False, + "fetch_url" : False, } } @@ -122,8 +122,11 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): if first_token: token = token.lstrip().replace('\u0000', '') first_token = False - #yield token - yield (token) + + else: + token = token.replace('\u0000', '') + + yield token elif line["type"] == "finalAnswer": break diff --git a/g4f/Provider/deprecated/Acytoo.py b/g4f/Provider/deprecated/Acytoo.py index 0379fdd6..f75821ce 100644 --- a/g4f/Provider/deprecated/Acytoo.py +++ b/g4f/Provider/deprecated/Acytoo.py @@ -7,10 +7,10 @@ from ..base_provider import AsyncGeneratorProvider class Acytoo(AsyncGeneratorProvider): - url = 'https://chat.acytoo.com' - working = False + url = 'https://chat.acytoo.com' + working = False supports_message_history = True - supports_gpt_35_turbo = True + supports_gpt_35_turbo = True @classmethod async def create_async_generator( |