Skip to content

Commit

Permalink
Merge pull request #96 from RockChinQ/feat/re_gpt
Browse files Browse the repository at this point in the history
Feat: add Zai-Kun/reverse-engineered-chatgpt
  • Loading branch information
RockChinQ authored Apr 2, 2024
2 parents 24caae0 + 05ac488 commit e86e0fc
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 17 deletions.
20 changes: 20 additions & 0 deletions docs/en/Adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
17 changes: 9 additions & 8 deletions docs/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions docs/zh-CN/Adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
17 changes: 9 additions & 8 deletions docs/zh-CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 路径

Expand Down
125 changes: 125 additions & 0 deletions free_one_api/impls/adapter/re_gpt.py
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions free_one_api/impls/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bardapi
hugchat
g4f
revTongYi
colorlog
colorlog
git+https://github.com/Zai-Kun/reverse-engineered-chatgpt
1 change: 1 addition & 0 deletions web/src/components/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e86e0fc

Please sign in to comment.