From e08bc182a0a67d2a37efbf36bbe2714960febc6e Mon Sep 17 00:00:00 2001 From: Dominoar Date: Fri, 16 Aug 2024 01:50:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dhugchat=E9=80=86=E5=90=91?= =?UTF-8?q?=E5=BA=93Query=E6=96=B9=E6=B3=95=E6=97=A0=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- free_one_api/impls/adapter/hugchat.py | 75 +++++++++++++-------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/free_one_api/impls/adapter/hugchat.py b/free_one_api/impls/adapter/hugchat.py index 589166f..cbf14ef 100644 --- a/free_one_api/impls/adapter/hugchat.py +++ b/free_one_api/impls/adapter/hugchat.py @@ -17,11 +17,11 @@ @adapter.llm_adapter class HuggingChatAdapter(llm.LLMLibAdapter): - + @classmethod def name(cls) -> str: return "Soulter/hugging-chat-api" - + @classmethod def description(self) -> str: return "Use Soulter/hugging-chat-api to access reverse engineering huggingchat." @@ -36,30 +36,30 @@ def function_call_supported(self) -> bool: return False def stream_mode_supported(self) -> bool: - return True + return True def multi_round_supported(self) -> bool: return True - + @classmethod def config_comment(cls) -> str: return \ -"""Please provide email and passwd to sign up for HuggingChat: - -{ - "email": "your email", - "passwd": "your password" -} + """Please provide email and passwd to sign up for HuggingChat: + + { + "email": "your email", + "passwd": "your password" + } + + Please refer to https://github.com/Soulter/hugging-chat-api + """ -Please refer to https://github.com/Soulter/hugging-chat-api -""" - @classmethod def supported_path(self) -> str: return "/v1/chat/completions" - + _chatbot: hugchat.ChatBot = None - + @property def chatbot(self) -> hugchat.ChatBot: if self._chatbot is None: @@ -70,51 +70,46 @@ def chatbot(self) -> hugchat.ChatBot: except: cookie = sign.login() sign.saveCookiesToDir("data/hugchatCookies") - + self._chatbot = hugchat.ChatBot(cookies=cookie.get_dict()) return self._chatbot - + def __init__(self, config: dict, eval: evaluation.AbsChannelEvaluation): self.config = config self.eval = eval - + async def test(self) -> typing.Union[bool, str]: try: self.chatbot.change_conversation(self.chatbot.new_conversation()) - for data in self.chatbot.query( - "Hi, respond 'Hello, world!' please.", - stream=True - ): + for data in self.chatbot.chat("Hi, respond 'Hello, world!' please."): pass - + self.chatbot.delete_conversation(self.chatbot.current_conversation) - + return True, "" except Exception as e: traceback.print_exc() return False, str(e) - - async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Response, None]: + + async def query(self, req: request.Request) -> typing.AsyncGenerator[response.Response, None]: prompt = "" - + for msg in req.messages: prompt += f"{msg['role']}: {msg['content']}\n" - + prompt += "assistant: " - + random_int = random.randint(0, 1000000000) self.chatbot.change_conversation(self.chatbot.new_conversation()) - - for resp in self.chatbot.query( - text=prompt, - stream=True - ): - yield response.Response( - id=random_int, - finish_reason=response.FinishReason.NULL, - normal_message=resp['token'], - function_call=None - ) + + for resp in self.chatbot.chat(prompt): + if resp is not None: + yield response.Response( + id=random_int, + finish_reason=response.FinishReason.NULL, + normal_message=resp['token'], + function_call=None + ) self.chatbot.delete_conversation(self.chatbot.current_conversation) yield response.Response( From 016552c4f830620eb20484200995b0bb3bfdb67f Mon Sep 17 00:00:00 2001 From: Dominoar Date: Fri, 16 Aug 2024 02:03:53 +0800 Subject: [PATCH 2/3] Fix: Add re_gpt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 85d0b2b..2ebd5ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ hugchat g4f revTongYi colorlog +re_gpt git+https://github.com/Zai-Kun/reverse-engineered-chatgpt \ No newline at end of file From fbef182be3e1d2ec309e3fcf1ccbab9f8f07d1b4 Mon Sep 17 00:00:00 2001 From: Dominoar Date: Fri, 16 Aug 2024 02:04:07 +0800 Subject: [PATCH 3/3] Fix: the issue with the Query method in the Hugging Face reverse library. --- free_one_api/impls/adapter/hugchat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/free_one_api/impls/adapter/hugchat.py b/free_one_api/impls/adapter/hugchat.py index cbf14ef..71c2c38 100644 --- a/free_one_api/impls/adapter/hugchat.py +++ b/free_one_api/impls/adapter/hugchat.py @@ -45,7 +45,7 @@ def multi_round_supported(self) -> bool: def config_comment(cls) -> str: return \ """Please provide email and passwd to sign up for HuggingChat: - + { "email": "your email", "passwd": "your password"