From 88b1be94a397a37e7f419e5da3a2e03c59e71414 Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Tue, 2 Apr 2024 08:59:04 +0000 Subject: [PATCH 1/2] feat: add Zai-Kun/reverse-engineered-chatgpt --- free_one_api/impls/adapter/re_gpt.py | 125 +++++++++++++++++++++++++++ free_one_api/impls/app.py | 2 + requirements.txt | 3 +- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 free_one_api/impls/adapter/re_gpt.py diff --git a/free_one_api/impls/adapter/re_gpt.py b/free_one_api/impls/adapter/re_gpt.py new file mode 100644 index 0000000..b029979 --- /dev/null +++ b/free_one_api/impls/adapter/re_gpt.py @@ -0,0 +1,125 @@ +import typing +import traceback +import uuid +import random + +import requests +import re_gpt + +from ...models import adapter +from ...models.adapter import llm +from ...entities import request +from ...entities import response, exceptions +from ...models.channel import evaluation + + +@adapter.llm_adapter +class ReGPTAdapter(llm.LLMLibAdapter): + + @classmethod + def name(cls) -> str: + return "Zai-Kun/reverse-engineered-chatgpt" + + @classmethod + def description(self) -> str: + return "Use Zai-Kun/reverse-engineered-chatgpt to access reverse engineering OpenAI ChatGPT web edition." + + def supported_models(self) -> list[str]: + return [ + "gpt-3.5-turbo", + "gpt-4" + ] + + def function_call_supported(self) -> bool: + return False + + def stream_mode_supported(self) -> bool: + return True + + def multi_round_supported(self) -> bool: + return True + + @classmethod + def config_comment(cls) -> str: + return \ +"""Please provide `session_token` to config as: + +{ + "session_token": "your session" +} + +Session token can be found from the cookies named `__Secure-next-auth.session-token` in the browser. +""" + + _chatbot: re_gpt.SyncChatGPT = None + + @property + def chatbot(self) -> re_gpt.SyncChatGPT: + if self._chatbot is None: + self._chatbot = re_gpt.SyncChatGPT(**self.config) + return self._chatbot + + @classmethod + def supported_path(self) -> str: + return "/v1/chat/completions" + + def __init__(self, config: dict, eval: evaluation.AbsChannelEvaluation): + self.config = config + self.eval = eval + + async def test(self) -> typing.Union[bool, str]: + + with self.chatbot as chatbot: + conversation = chatbot.create_new_conversation() + + try: + for message in conversation.chat("Hi, respond 'hello, world!' please."): + pass + + return True, '' + except Exception as e: + return False, str(e) + finally: + chatbot.delete_conversation(conversation.conversation_id) + + 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, 1000000) + + with self.chatbot as chatbot: + conversation = chatbot.create_new_conversation() + try: + + for message in conversation.chat( + user_input=prompt + ): + if message["content"] == "": + continue + + yield response.Response( + id=random_int, + finish_reason=response.FinishReason.NULL, + normal_message=message["content"], + function_call=None + ) + except Exception as e: + traceback.print_exc() + raise e + finally: + chatbot.delete_conversation(conversation.conversation_id) + + yield response.Response( + id=random_int, + finish_reason=response.FinishReason.STOP, + normal_message="", + function_call=None + ) \ No newline at end of file diff --git a/free_one_api/impls/app.py b/free_one_api/impls/app.py index 7777c61..e27fdff 100644 --- a/free_one_api/impls/app.py +++ b/free_one_api/impls/app.py @@ -22,6 +22,7 @@ from .adapter import gpt4free from .adapter import hugchat from .adapter import qianwen +from .adapter import re_gpt from . import log from . import cfg as cfgutil @@ -203,6 +204,7 @@ async def make_application(config_path: str) -> Application: "xtekky_gpt4free": gpt4free.GPT4FreeAdapter, "Soulter_hugging-chat-api": hugchat.HuggingChatAdapter, "xw5xr6_revTongYi": qianwen.QianWenAdapter, + "Zai-Kun_reverse-engineered-chatgpt": re_gpt.ReGPTAdapter, } for adapter_name in adapter_config_mapping: diff --git a/requirements.txt b/requirements.txt index 94340d5..85d0b2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ bardapi hugchat g4f revTongYi -colorlog \ No newline at end of file +colorlog +git+https://github.com/Zai-Kun/reverse-engineered-chatgpt \ No newline at end of file From 05ac4889a25df87488e7c64362479b482f0cf7c7 Mon Sep 17 00:00:00 2001 From: Junyan Qin <1010553892@qq.com> Date: Tue, 2 Apr 2024 09:09:13 +0000 Subject: [PATCH 2/2] doc: add documentation for re_gpt --- docs/en/Adapters.md | 20 ++++++++++++++++++++ docs/en/README.md | 17 +++++++++-------- docs/zh-CN/Adapters.md | 19 +++++++++++++++++++ docs/zh-CN/README.md | 17 +++++++++-------- web/src/components/Channel.vue | 1 + 5 files changed, 58 insertions(+), 16 deletions(-) diff --git a/docs/en/Adapters.md b/docs/en/Adapters.md index 1c5c731..07a475f 100644 --- a/docs/en/Adapters.md +++ b/docs/en/Adapters.md @@ -118,3 +118,23 @@ Aliyun TongYi QianWen official website reverse engineering library "cookie": "通义千问cookie" } ``` + +## Zai-Kun/reverse-engineered-chatgpt + +ChatGPT official website reverse engineering library, this is newer. acheong08/ChatGPT is no longer maintained. + +### Configuration + +1. Select `Zai-Kun/reverse-engineered-chatgpt` as `Adapter` + +2. Go to`chat.openai.com` and log in to your account + +3. Take the value of `__Secure-next-auth.session-token` from Cookies as `session_token` + +4. Enter in the `Config` column + +```json +{ + "session_token": "your session token" +} +``` \ No newline at end of file diff --git a/docs/en/README.md b/docs/en/README.md index e2622e7..66dd6d2 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -5,14 +5,15 @@ ## Supported LLM libs -|Adapter|Multi Round|Stream|Function Call|Status|Comment| -|---|---|---|---|---|---| -|[acheong08/ChatGPT](https://github.com/acheong08/ChatGPT)|✅|✅|❌|✅|ChatGPT Web Version| -|[KoushikNavuluri/Claude-API](https://github.com/KoushikNavuluri/Claude-API)|✅|❌|❌|✅|Claude Web Version| -|[dsdanielpark/Bard-API](https://github.com/dsdanielpark/Bard-API)|✅|❌|❌|✅|Google Bard Web Version| -|[xtekky/gpt4free](https://github.com/xtekky/gpt4free)|✅|✅|❌|✅|gpt4free cracked multiple platforms| -|[Soulter/hugging-chat-api](https://github.com/Soulter/hugging-chat-api)|✅|✅|❌|✅|hubbingface chat model| -|[xw5xr6/revTongYi](https://github.com/xw5xr6/revTongYi)|✅|✅|❌|✅|Aliyun TongYi QianWen Web Version| +|Adapter|Multi Round|Stream|Function Call|Comment| +|---|---|---|---|---| +|[acheong08/ChatGPT](https://github.com/acheong08/ChatGPT)|✅|✅|❌|ChatGPT Web Version| +|[KoushikNavuluri/Claude-API](https://github.com/KoushikNavuluri/Claude-API)|✅|❌|❌|Claude Web Version| +|[dsdanielpark/Bard-API](https://github.com/dsdanielpark/Bard-API)|✅|❌|❌|Google Bard Web Version| +|[xtekky/gpt4free](https://github.com/xtekky/gpt4free)|✅|✅|❌|gpt4free cracked multiple platforms| +|[Soulter/hugging-chat-api](https://github.com/Soulter/hugging-chat-api)|✅|✅|❌|hubbingface chat model| +|[xw5xr6/revTongYi](https://github.com/xw5xr6/revTongYi)|✅|✅|❌|Aliyun TongYi QianWen Web Version| +|[Zai-Kun/reverse-engineered-chatgpt](https://github.com/Zai-Kun/reverse-engineered-chatgpt)|✅|✅|❌|ChatGPT Web Version| ## Supported API paths diff --git a/docs/zh-CN/Adapters.md b/docs/zh-CN/Adapters.md index 03d26a2..486ffea 100644 --- a/docs/zh-CN/Adapters.md +++ b/docs/zh-CN/Adapters.md @@ -119,3 +119,22 @@ huggingface.co/chat 官网逆向工程库 } ``` +## Zai-Kun/reverse-engineered-chatgpt + +ChatGPT 官网逆向工程库,这个新一点。acheong08/ChatGPT 已经不维护了。 + +### 配置方式 + +1. 选择 `Zai-Kun/reverse-engineered-chatgpt` 作为 `Adapter` + +2. 前往 `chat.openai.com` 登录账号 + +3. 从 Cookies 中取出 `__Secure-next-auth.session-token` 的值作为 `session_token` + +4. 在 `Config` 栏中输入 + +```json +{ + "session_token": "你的session token" +} +``` \ No newline at end of file diff --git a/docs/zh-CN/README.md b/docs/zh-CN/README.md index 7fda358..4e2f811 100644 --- a/docs/zh-CN/README.md +++ b/docs/zh-CN/README.md @@ -2,14 +2,15 @@ ## 支持的 LLM 库 -|Adapter|Multi Round|Stream|Function Call|Status|Comment| -|---|---|---|---|---|---| -|[acheong08/ChatGPT](https://github.com/acheong08/ChatGPT)|✅|✅|❌|✅|ChatGPT 网页版| -|[KoushikNavuluri/Claude-API](https://github.com/KoushikNavuluri/Claude-API)|✅|❌|❌|✅|Claude 网页版| -|[dsdanielpark/Bard-API](https://github.com/dsdanielpark/Bard-API)|✅|❌|❌|✅|Google Bard 网页版| -|[xtekky/gpt4free](https://github.com/xtekky/gpt4free)|✅|✅|❌|✅|gpt4free 接入多个平台的破解| -|[Soulter/hugging-chat-api](https://github.com/Soulter/hugging-chat-api)|✅|✅|❌|✅|huggingface的对话模型| -|[xw5xr6/revTongYi](https://github.com/xw5xr6/revTongYi)|✅|✅|❌|✅|阿里云通义千问网页版| +|Adapter|Multi Round|Stream|Function Call|Comment| +|---|---|---|---|---| +|[acheong08/ChatGPT](https://github.com/acheong08/ChatGPT)|✅|✅|❌|ChatGPT 网页版| +|[KoushikNavuluri/Claude-API](https://github.com/KoushikNavuluri/Claude-API)|✅|❌|❌|Claude 网页版| +|[dsdanielpark/Bard-API](https://github.com/dsdanielpark/Bard-API)|✅|❌|❌|Google Bard 网页版| +|[xtekky/gpt4free](https://github.com/xtekky/gpt4free)|✅|✅|❌|gpt4free 接入多个平台的破解| +|[Soulter/hugging-chat-api](https://github.com/Soulter/hugging-chat-api)|✅|✅|❌|huggingface的对话模型| +|[xw5xr6/revTongYi](https://github.com/xw5xr6/revTongYi)|✅|✅|❌|阿里云通义千问网页版| +|[Zai-Kun/reverse-engineered-chatgpt](https://github.com/Zai-Kun/reverse-engineered-chatgpt)|✅|✅|❌|ChatGPT 网页版| ## 支持的 API 路径 diff --git a/web/src/components/Channel.vue b/web/src/components/Channel.vue index 501335b..9c0598e 100644 --- a/web/src/components/Channel.vue +++ b/web/src/components/Channel.vue @@ -79,6 +79,7 @@ const adapter_color = { "acheong08/EdgeGPT": "#0388FF", "Soulter/hugging-chat-api": "#FFBB03", "xw5xr6/revTongYi": "#4040C0", + "Zai-Kun/reverse-engineered-chatgpt": "#00CC90", } function deleteChannelConfirmed(channel_id) {