Skip to content

Commit

Permalink
add many many features for v0.95-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
SnapdragonLee committed Feb 22, 2023
1 parent 54ea18a commit b99bc18
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .config/rev_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"email": "",
"password": "",
"session_token": "",
"paid": false
"paid": true
}
6 changes: 3 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Using ChatGPT-weBot based on ChatGPT(Non-API key call) and official WeChat hook
- [x] Support context-aware question answering
- [x] **Never get banned by using official WeChat execution.**
- [x] Set the keywords to wake up the WeChat robot in private.
- [x] Set the keywords to wake up the WeChat robot in the group. **(have bugs)**
- [x] Set the keywords to wake up the WeChat robot in the group.
- [x] Get help doc in line.
- [x] Can set keywords to reset the previous conversation.
- [x] Support replying message when mentioning your bot in the group. **(have bugs)**
- [ ] Get help doc in line. **(need work)**
- [ ] Can set keywords to reset the previous conversation. **(need work)**
- [ ] Regenerate to get another answer. **(need work)**
- [ ] Rollback conversation. **(need work)**
- [ ] Other
Expand Down
16 changes: 8 additions & 8 deletions Readme_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

## 支持和特点

- [x] 支持对话
- [x] 支持对话
- [x] 支持上下文感知问答
- [x] **使用官方微信软件执行,信息来源方面永不封禁**
- [x] **使用官方微信软件执行,信息来源方面永不封禁**
- [x] 设置关键字在私聊中唤醒微信机器人
- [x] 设置关键字在群中唤醒微信机器人。(有Bug)
- [x] 在群聊中提到您的机器人时,支持回复消息。(有Bug)
- [ ] 在线获取帮助文档。(待完善)
- [ ] 可以设置关键字以重置之前的对话。(待完善
- [ ] 重新生成以获得另一个答案。(待完善)
- [ ] 回滚对话(待完善)
- [x] 设置关键字在群中唤醒微信机器人
- [x] 在线获取帮助文档
- [x] 可以设置关键字以重置之前的对话
- [x] 在群聊中提到您的机器人时,支持回复消息(有Bug
- [ ] 重新生成另一个答案(待完善)
- [ ] 回滚对话(待完善)
- [ ] 其他


Expand Down
88 changes: 56 additions & 32 deletions client/wxclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ def handle_recv_txt_msg(j):
wx_id = j["wxid"]
room_id = ""
content: str = j["content"]
reply = ""

is_room: bool
is_ask: bool = False
is_room: bool

chatbot: Chatbot

Expand All @@ -253,44 +254,66 @@ def handle_recv_txt_msg(j):
is_ask = True
content = re.sub(groupChatKey, "", content)

if autoReply and is_ask and ((not is_room and privateReplyMode) or (is_room and groupReplyMode)):
if chatbot is None:
chatbot = Chatbot(
rev_config,
conversation_id=None,
parent_id=None,
)
if autoReply and ((not is_room and privateReplyMode) or (is_room and groupReplyMode)):
if is_ask:
if chatbot is None:
chatbot = Chatbot(
rev_config,
conversation_id=None,
parent_id=None,
)
if is_room:
global_dict[(wx_id, room_id)] = chatbot
else:
global_dict[(wx_id, "")] = chatbot

print("ask:" + content)
for data in chatbot.ask(
prompt=content,
):
reply += data["message"][len(reply):]

elif content.startswith(helpKey):
if is_room:
global_dict[(wx_id, room_id)] = chatbot
else:
global_dict[(wx_id, "")] = chatbot
reply = str(
b'\xe6\xac\xa2\xe8\xbf\x8e\xe4\xbd\xbf\xe7\x94\xa8 ChatGPT-weBot\xef\xbc\x8c\xe6\x9c\xac\xe9'
b'\xa1\xb9\xe7\x9b\xae\xe5\x9c\xa8 github \xe5\x90\x8c\xe5\x90\x8d\xe5\xbc\x80\xe6\xba\x90\n',
'utf-8') + helpKey + " 查看可用命令帮助\n" + groupChatKey + " 唤醒群内机器人\n" + resetChatKey + \
" 重置上下文\n" + regenerateKey + " 重新生成答案\n" + rollbackKey + " +数字n 回滚到倒数第n个问题"

print("ask:" + content)
reply = ""
for data in chatbot.ask(
prompt=content,
):
reply += data["message"][len(reply):]
else:
reply = str(
b'\xe6\xac\xa2\xe8\xbf\x8e\xe4\xbd\xbf\xe7\x94\xa8 ChatGPT-weBot\xef\xbc\x8c\xe6\x9c\xac\xe9'
b'\xa1\xb9\xe7\x9b\xae\xe5\x9c\xa8 github \xe5\x90\x8c\xe5\x90\x8d\xe5\xbc\x80\xe6\xba\x90\n',
'utf-8') + helpKey + " 查看可用命令帮助\n" + privateChatKey + " 唤醒机器人\n" + resetChatKey + \
" 重置上下文\n" + regenerateKey + " 重新生成答案\n" + rollbackKey + " +数字n 回滚到倒数第n个问题"
time.sleep(1.5)

elif content.startswith(resetChatKey):
if chatbot is not None:
chatbot.clear_conversations()
del (global_dict[(wx_id, room_id)])
reply = "重置完成"
else:
reply = "您还没有开始第一次对话"
time.sleep(1.5)

if is_room:
ws.send(send_txt_msg(text_string=reply, wx_id=room_id))
elif content.startswith(regenerateKey): # todo
pass

elif content.startswith(rollbackKey): # todo
pass
else:
ws.send(send_txt_msg(text_string=reply, wx_id=wx_id))
print("reply:" + reply)

elif content.startswith(resetChatKey): # todo
pass

elif content.startswith(regenerateKey): # todo
pass

elif content.startswith(rollbackKey): # todo
pass

return
else:
return

if is_room:
ws.send(send_txt_msg(text_string=reply.strip(), wx_id=room_id))
else:
ws.send(send_txt_msg(text_string=reply.strip(), wx_id=wx_id))
print("reply:" + reply)


def handle_recv_pic_msg(j):
print(j)
Expand Down Expand Up @@ -366,9 +389,10 @@ def on_error(ws, error):


def on_close(ws):
for key, value in global_dict: # todo: still have bugs
for key, value in global_dict.items(): # todo: still have bugs
print("clear conversation id:" + value.parent_id)
value.clear_conversations()
del value

print(ws)
print("closed")
Expand Down
2 changes: 1 addition & 1 deletion revChat/revChatGPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests
from OpenAIAuth import Authenticator, Error as AuthError

BASE_URL = environ.get("CHATGPT_BASE_URL") or "https://chatgpt.duti.tech/"
BASE_URL = "https://chatgpt.duti.tech/"


class Error(Exception):
Expand Down

0 comments on commit b99bc18

Please sign in to comment.