Fix HuggingFace formatting

pull/2089/head
abc 3 months ago
parent ac0bd092c0
commit 46c48bb09e

@ -8,7 +8,6 @@ from .helper import format_prompt
import random import random
class Aichatos(AsyncGeneratorProvider): class Aichatos(AsyncGeneratorProvider):
url = "https://chat10.aichatos.xyz" url = "https://chat10.aichatos.xyz"
api = "https://api.binjie.fun" api = "https://api.binjie.fun"

@ -5,7 +5,7 @@ import json, requests, re
from curl_cffi import requests as cf_reqs from curl_cffi import requests as cf_reqs
from ..typing import CreateResult, Messages from ..typing import CreateResult, Messages
from .base_provider import ProviderModelMixin, AbstractProvider from .base_provider import ProviderModelMixin, AbstractProvider
from .helper import format_prompt, get_connector, get_cookies from .helper import format_prompt
class HuggingChat(AbstractProvider, ProviderModelMixin): class HuggingChat(AbstractProvider, ProviderModelMixin):
url = "https://huggingface.co/chat" url = "https://huggingface.co/chat"
@ -41,34 +41,34 @@ class HuggingChat(AbstractProvider, ProviderModelMixin):
session = requests.Session() session = requests.Session()
headers = { headers = {
'accept': '*/*', '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', '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', 'cache-control' : 'no-cache',
'origin': 'https://huggingface.co', 'origin' : 'https://huggingface.co',
'pragma': 'no-cache', 'pragma' : 'no-cache',
'priority': 'u=1, i', 'priority' : 'u=1, i',
'referer': 'https://huggingface.co/chat/', 'referer' : 'https://huggingface.co/chat/',
'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"', 'sec-ch-ua' : '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
'sec-ch-ua-mobile': '?0', 'sec-ch-ua-mobile' : '?0',
'sec-ch-ua-platform': '"macOS"', 'sec-ch-ua-platform': '"macOS"',
'sec-fetch-dest': 'empty', 'sec-fetch-dest' : 'empty',
'sec-fetch-mode': 'cors', 'sec-fetch-mode' : 'cors',
'sec-fetch-site': 'same-origin', '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', '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 = { json_data = {
'searchEnabled': True, 'searchEnabled' : True,
'ethicsModalAccepted': True, 'activeModel' : 'CohereForAI/c4ai-command-r-plus', # doesn't matter
'ethicsModalAcceptedAt': None,
'activeModel': 'CohereForAI/c4ai-command-r-plus', # doesn't matter
'hideEmojiOnSidebar': False, 'hideEmojiOnSidebar': False,
'customPrompts' : {},
'assistants' : [],
'tools' : {},
'disableStream' : False,
'recentlySaved' : False,
'ethicsModalAccepted' : True,
'ethicsModalAcceptedAt' : None,
'shareConversationsWithModelAuthors': False, 'shareConversationsWithModelAuthors': False,
'customPrompts': {},
'assistants': [],
'tools': {},
'disableStream': False,
'recentlySaved': False,
} }
response = cf_reqs.post('https://huggingface.co/chat/settings', headers=headers, json=json_data) 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()) messageId = extract_id(response.json())
settings = { settings = {
"inputs": format_prompt(messages), "inputs" : format_prompt(messages),
"id": messageId, "id" : messageId,
"is_retry": False, "is_retry" : False,
"is_continue": False, "is_continue" : False,
"web_search": False, "web_search" : False,
# enable tools # TODO // add feature to enable/disable tools
"tools": { "tools": {
"websearch": True, "websearch" : True,
"document_parser": False, "document_parser" : False,
"query_calculator": False, "query_calculator" : False,
"image_generation": False, "image_generation" : False,
"image_editing": False, "image_editing" : False,
"fetch_url": False, "fetch_url" : False,
} }
} }
@ -122,8 +122,11 @@ class HuggingChat(AbstractProvider, ProviderModelMixin):
if first_token: if first_token:
token = token.lstrip().replace('\u0000', '') token = token.lstrip().replace('\u0000', '')
first_token = False first_token = False
#yield token
yield (token) else:
token = token.replace('\u0000', '')
yield token
elif line["type"] == "finalAnswer": elif line["type"] == "finalAnswer":
break break

@ -7,10 +7,10 @@ from ..base_provider import AsyncGeneratorProvider
class Acytoo(AsyncGeneratorProvider): class Acytoo(AsyncGeneratorProvider):
url = 'https://chat.acytoo.com' url = 'https://chat.acytoo.com'
working = False working = False
supports_message_history = True supports_message_history = True
supports_gpt_35_turbo = True supports_gpt_35_turbo = True
@classmethod @classmethod
async def create_async_generator( async def create_async_generator(

Loading…
Cancel
Save