diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-08-31 08:47:39 +0200 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-08-31 08:47:39 +0200 |
commit | f1683c8db83cee5805a6e103fca2c2551aae5086 (patch) | |
tree | 44712b453191566e7ce0877d43a3ed2f807d78b6 /g4f/Provider/HuggingChat.py | |
parent | Merge pull request #2206 from Parthsadaria/patch-1 (diff) | |
download | gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.gz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.bz2 gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.lz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.xz gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.tar.zst gpt4free-f1683c8db83cee5805a6e103fca2c2551aae5086.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 |