diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2024-09-07 21:37:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-07 21:37:24 +0200 |
commit | 07fa87b4d180259d1da86afb565e14ac3d60d50b (patch) | |
tree | d474a2bf8bd79cf94bfa48cbaca3917659dd19be /g4f/Provider/HuggingChat.py | |
parent | Merge pull request #2206 from Parthsadaria/patch-1 (diff) | |
parent | g4f/models.py g4f/Provider/MagickPen.py (diff) | |
download | gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.gz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.bz2 gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.lz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.xz gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.tar.zst gpt4free-07fa87b4d180259d1da86afb565e14ac3d60d50b.zip |
Diffstat (limited to 'g4f/Provider/HuggingChat.py')
-rw-r--r-- | g4f/Provider/HuggingChat.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/g4f/Provider/HuggingChat.py b/g4f/Provider/HuggingChat.py index f1010c1c..76c76a35 100644 --- a/g4f/Provider/HuggingChat.py +++ b/g4f/Provider/HuggingChat.py @@ -22,7 +22,7 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): 'mistralai/Mistral-7B-Instruct-v0.3', 'microsoft/Phi-3-mini-4k-instruct', ] - + model_aliases = { "llama-3.1-70b": "meta-llama/Meta-Llama-3.1-70B-Instruct", "llama-3.1-405b": "meta-llama/Meta-Llama-3.1-405B-Instruct-FP8", @@ -42,7 +42,7 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): return cls.model_aliases[model] else: return cls.default_model - + @classmethod def create_completion( cls, @@ -52,7 +52,7 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): **kwargs ) -> CreateResult: model = cls.get_model(model) - + if model in cls.models: session = cf_reqs.Session() session.headers = { @@ -71,12 +71,17 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): '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/127.0.0.0 Safari/537.36', } + + print(model) json_data = { 'model': model, } + response = session.post('https://huggingface.co/chat/conversation', json=json_data) conversationId = response.json()['conversationId'] + response = session.get(f'https://huggingface.co/chat/conversation/{conversationId}/__data.json?x-sveltekit-invalidated=01',) + data: list = (response.json())["nodes"][1]["data"] keys: list[int] = data[data[0]["messages"]] message_keys: dict = data[keys[0]] @@ -117,6 +122,7 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): headers=headers, files=files, ) + first_token = True for line in response.iter_lines(): line = json.loads(line) @@ -133,6 +139,6 @@ class HuggingChat(AbstractProvider, ProviderModelMixin): token = token.replace('\u0000', '') yield token - + elif line["type"] == "finalAnswer": - break
\ No newline at end of file + break |