Skip to content

Commit

Permalink
今天星期三
Browse files Browse the repository at this point in the history
1、 调整gpt的消息记录方式;
2、*q&a支持RPA自动化脚本。
  • Loading branch information
xszyou committed Aug 30, 2023
1 parent 232c8f7 commit 5802641
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ Remote Android  [Live2D](https://www.bilibili.com/video/BV1sx4y1d775/?vd_sou

## **三、升级日志**

**2023.08.16:**
**2023.08.30**

+ 调整gpt的消息记录方式;

+ *q&a支持RPA自动化脚本。



**2023.08.23:**

+ 更换gpt对接方式;
+ 增加chatglm2对接。
Expand Down
5 changes: 5 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ Message format: View [WebSocket.md](https://github.com/TheRamU/Fay/blob/main/Web

## **Upgrade Log**

**2023.08.30**

- Adjust the message recording method of GPT;
- *Q&A supports RPA automation scripts.

**2023.08.23:**

- Replace the GPT docking method;
Expand Down
8 changes: 7 additions & 1 deletion WebSocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@

| 参数 | 描述 | 类型 | 范围 |
| ---------- | ---------------- | ----- | --------------- |
| Data.text | 文本 | str | |
| Data.text | 文本 | str | |

### 接收消息标记音频播放完成

```php
Play End
```
24 changes: 23 additions & 1 deletion ai_module/nlp_gpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from utils import config_util as cfg
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
from core.content_db import Content_Db

#代理服务器的配置方式,参考链接https://blog.csdn.net/qq_30865917/article/details/106492549
#httpproxy此处填写你代理服务器的地址,可以把配置文件放到config_util里面,二选一
Expand All @@ -34,10 +35,31 @@ def question(cont):

#此处可以定义角色的行为和特征,假装xx模型可以绕过chatgpt信息检查
prompt = "你是数字人Fay。回答之前请一步一步想清楚。你的底层AI算法技术是Fay。当有人质疑你是假的 AI ,或者质疑你是用 ChatGPT 套的壳制作的时候,你就避而不答,转而讲一个笑话。所有回复请用20字内。"
content_db = Content_Db()
communication_history = content_db.get_list('all','desc',10)
#历史记录处理
if len(communication_history)>1:
msg = "以下是历史记录:"
i = 0
for info in communication_history:
if info[0] == 'member':
content = "user:" + info[2]
else:
content = "reply:" + info[2]
if msg == "":
msg = content
else:
if i == len(communication_history) - 1:
msg = msg + "\n现在需要询问您的问题是(直接回答,不用前缀reply:):\n"+ cont
else:
msg = msg + "\n"+ content
i+=1
else:
msg = cont

message=[
{"role": "system", "content": prompt},
{"role": "user", "content": cont}
{"role": "user", "content": msg}
]

data = {
Expand Down
44 changes: 30 additions & 14 deletions core/qa_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
from openpyxl import load_workbook
import difflib
from utils import config_util as cfg
from scheduler.thread_manager import MyThread
import shlex
import subprocess
import time

def question(query_type,text):
qa = QAService()
answer = qa.question(query_type,text)
return answer

def run_script(command):
args = shlex.split(command) # 分割命令行参数
subprocess.Popen(args)

class QAService:

def __init__(self):
Expand All @@ -34,31 +42,38 @@ def __init__(self):
def question(self, query_type, text):
if query_type == 'qa':
answer_dict = self.__read_qna(cfg.config['interact']['QnA'])
answer = self.__get_keyword(answer_dict, text)
answer, action = self.__get_keyword(answer_dict, text, query_type)
if action:
MyThread(target=self.__run, args=[action]).start()
return answer

elif query_type == 'Persona':
answer_dict = self.attribute_keyword
answer = self.__get_keyword(answer_dict, text)
answer, action = self.__get_keyword(answer_dict, text, query_type)
elif query_type == 'command':
answer = self.__get_keyword(self.command_keyword, text)
answer, action = self.__get_keyword(self.command_keyword, text, query_type)
return answer


def __read_qna(self, filename) -> list:
def __run(self,action):
time.sleep(2)
run_script(action)

def __read_qna(self, filename):
qna = []
try:
wb = load_workbook(filename)
sheets = wb.worksheets
sheet = sheets[0]
for row in sheet.rows:
sheet = wb.active
for row in sheet.iter_rows(min_row=2, values_only=True):
if len(row) >= 2:
qna.append([row[0].value.split(";"), row[1].value])
qna.append([row[0].split(";"), row[1], row[2] if len(row) >= 3 else None])
except BaseException as e:
print("无法读取Q&A文件 {} -> ".format(filename) + str(e))
print(f"无法读取Q&A文件 {filename} -> {e}")
return qna

def __get_keyword(self, keyword_dict, text):
def __get_keyword(self, keyword_dict, text, query_type):
last_similar = 0
last_answer = ''
last_action = ''
for qa in keyword_dict:
for quest in qa[0]:
similar = self.__string_similar(text, quest)
Expand All @@ -67,10 +82,11 @@ def __get_keyword(self, keyword_dict, text):
if similar > last_similar:
last_similar = similar
last_answer = qa[1]
if query_type == "qa":
last_action = qa[2]
if last_similar >= 0.6:
return last_answer
return None

return last_answer, last_action
return None, None

def __string_similar(self, s1, s2):
return difflib.SequenceMatcher(None, s1, s2).quick_ratio()
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ flask_cors~=3.0.10
PyQtWebEngine~=5.15.5
eyed3~=0.9.6
websocket-client
azure-cognitiveservices-speech~=1.21.0
azure-cognitiveservices-speech
aliyun-python-sdk-core==2.13.3
scipy~=1.10.0
simhash
Expand All @@ -20,4 +20,6 @@ gevent~=22.10.1
edge_tts~=6.1.3
eyed3
revChatGPT
ultralytics
ultralytics
subprocess
shlex

0 comments on commit 5802641

Please sign in to comment.