上传彩蛋

1、上传chatgpt彩蛋;
2、修复音频合成过长不播放问题。
This commit is contained in:
xszyou 2023-05-19 18:12:02 +08:00
parent 524e4d0e65
commit 023df4deb1
8 changed files with 100 additions and 47 deletions

34
ai_module/nlp_gpt.py Normal file
View File

@ -0,0 +1,34 @@
from revChatGPT.V1 import Chatbot
from core.content_db import Content_Db
from utils import config_util as cfg
def question(cont):
contentdb = Content_Db()
list = contentdb.get_list('all','desc',5)
text = ''
if len(list) > 0:
relist = []
i = len(list)-1
text = '以下是我和机器人的历史对话:'
while i >= 0:
if list[i][0] == 'fay':
text = text + ' 机器人:' + list[i][2]
else:
text = text + ' 我:' + list[i][2]
i -= 1
try:
chatbot = Chatbot(config={
"access_token": cfg.key_gpt_access_token,
"conversation_id": cfg.key_gpt_conversation_id
})
prompt = text + ' 现在想咨询的问题是:'+cont
response = ""
for data in chatbot.ask(
prompt
):
response = data["message"]
return response
except:
return 'gpt当前繁忙请稍后重试'

View File

@ -28,9 +28,10 @@ from utils import config_util as cfg
from core.content_db import Content_Db
from datetime import datetime
from ai_module import nlp_rasa
from ai_module import nlp_gpt
class FeiFei:
def __init__(self):
pygame.mixer.init()
pygame.init()
self.q_msg = '你叫什么名字?'
self.a_msg = 'hi,我叫菲菲英文名是fay'
self.mood = 0.0 # 情绪值
@ -516,7 +517,7 @@ class FeiFei:
audio_length = eyed3.load(file_url).info.time_secs #mp3音频长度
# with wave.open(file_url, 'rb') as wav_file: #wav音频长度
# audio_length = wav_file.getnframes() / float(wav_file.getframerate())
if audio_length <= config_util.config["interact"]["maxInteractTime"] or say_type == "script":
# if audio_length <= config_util.config["interact"]["maxInteractTime"] or say_type == "script":
if config_util.config["interact"]["playSound"]: # 展板播放
self.__play_sound(file_url)
else:#发送音频给ue和socket
@ -590,7 +591,7 @@ class FeiFei:
self.last_interact_time = time.time()
self.speaking = False
def send_for_answer(self,msg):
def send_for_answer(self,msg,sendto):
contentdb = Content_Db()
contentdb.add_content('member','send',msg)
answer = self.__get_answer('send', msg)
@ -603,6 +604,9 @@ class FeiFei:
util.log(1, '自然语言处理...')
tm = time.time()
cfg.load_config()
if sendto == 2:
text = nlp_gpt.question(msg)
else:
if cfg.key_chat_module == 'xfaiui':
text = xf_aiui.question(msg)
elif cfg.key_chat_module == 'yuan':

View File

@ -78,7 +78,7 @@ def api_send():
print(data)
info = json.loads(data)
feiFei = FeiFei()
text = feiFei.send_for_answer(info['msg'])
text = feiFei.send_for_answer(info['msg'],info['sendto'])
return '{"result":"successful","msg":"'+text+'"}'
@__app.route('/api/get-msg', methods=['post'])

View File

@ -82,8 +82,8 @@ new Vue({
methods: {
// 回车和空格键提交右侧信息
handkeyCode(e) {
if(e.keyCode === 13){
this.send()
if(e.keyCode === 13 && e.keyCode === 18){
this.send(1)
}
},
handleTabsEdit(targetName, action) {
@ -452,7 +452,7 @@ new Vue({
type: 'success'
});
},
send() {
send(sendto) {
let _this = this;
let text = _this.send_msg;
if (!text) {
@ -474,7 +474,8 @@ new Vue({
_this.send_msg = ''
let url = "http://127.0.0.1:5000/api/send";
let send_data = {
"msg": text
"msg": text,
"sendto" : sendto
};
let xhr = new XMLHttpRequest()

View File

@ -333,7 +333,10 @@
<div class="input-area">
<textarea v-model="send_msg" name="text" id="textarea" placeholder="发送些内容给Fay..."></textarea>
<div class="button-area">
<button id="send-btn" @click="send()">发 送</button>
<button id="send-btn" @click="send(1)">发 送</button>
<!--删除注释打开彩蛋
<button id="send-btn" @click="send(2)" style="margin-left: 25px;">发送gpt</button>
-->
</div>
</div>
</div>

View File

@ -19,3 +19,4 @@ pytz
gevent~=22.10.1
edge_tts~=6.1.3
eyed3
#revChatGPT 删除注释打开彩蛋

View File

@ -18,8 +18,8 @@ ms_tts_key=
ms_tts_region=
# 讯飞 情绪分析 服务密钥 https://www.xfyun.cn/service/emotion-analysis/
xf_ltp_app_id=
xf_ltp_api_key=
xf_ltp_app_id=604404c8
xf_ltp_api_key=78d2db9a83cda0b355c76ea791bc74da
#NLP四选一:xfaiui、yuan、chatgpt、rasa(需启动chatglm及rasahttps://m.bilibili.com/video/BV1D14y1f7pr)
chat_module=xfaiui
@ -37,3 +37,7 @@ chatgpt_api_key=
#ngrok内网穿透id远程设备可以通过互联网连接Fay非必须http://ngrok.cc
ngrok_cc_id=
#revChatGPT对接非必须https://chat.openai.com登录后访问https://chat.openai.com/api/auth/session获取
gpt_access_token=
gpt_conversation_id=

View File

@ -21,6 +21,8 @@ key_yuan_1_0_account = None
key_yuan_1_0_phone = None
key_chatgpt_api_key = None
key_chat_module = None
key_gpt_access_token = None
key_gpt_conversation_id = None
ASR_mode = None
local_asr_ip = None
@ -43,6 +45,8 @@ def load_config():
global key_yuan_1_0_phone
global key_chatgpt_api_key
global key_chat_module
global key_gpt_access_token
global key_gpt_conversation_id
global ASR_mode
global local_asr_ip
@ -64,6 +68,8 @@ def load_config():
key_yuan_1_0_phone = system_config.get('key', 'yuan_1_0_phone')
key_chatgpt_api_key = system_config.get('key', 'chatgpt_api_key')
key_chat_module = system_config.get('key', 'chat_module')
key_gpt_access_token = system_config.get('key', 'gpt_access_token')
key_gpt_conversation_id = system_config.get('key', 'gpt_conversation_id')
ASR_mode = system_config.get('key', 'ASR_mode')
local_asr_ip = system_config.get('key', 'local_asr_ip')