mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
fix: chat chroma chat and add opencc convert to asr
This commit is contained in:
@ -16,12 +16,18 @@ import tempfile
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import opencc
|
||||||
|
|
||||||
|
|
||||||
from ..configuration import SenseVoiceConf
|
from ..configuration import SenseVoiceConf
|
||||||
|
|
||||||
from ..log.logging_time import logging_time
|
from ..log.logging_time import logging_time
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
converter = opencc.OpenCC('s2t.json')
|
||||||
|
|
||||||
|
|
||||||
@singleton
|
@singleton
|
||||||
class ASR(Blackbox):
|
class ASR(Blackbox):
|
||||||
mode: str
|
mode: str
|
||||||
@ -98,17 +104,20 @@ class ASR(Blackbox):
|
|||||||
os.remove(temp_audio_path)
|
os.remove(temp_audio_path)
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
return None
|
return None
|
||||||
|
results = converter.convert(results)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
elif user_model_name == 'funasr' or ['funasr']:
|
elif user_model_name == 'funasr' or ['funasr']:
|
||||||
|
|
||||||
|
results = converter.convert(results)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
else:
|
else:
|
||||||
results = self.paraformer([BytesIO(data)])
|
results = self.paraformer([BytesIO(data)])
|
||||||
if len(results) == 0:
|
if len(results) == 0:
|
||||||
return None
|
return None
|
||||||
return results[0]
|
results = converter.convert(results[0])
|
||||||
|
return results
|
||||||
|
|
||||||
def valid(self, data: any) -> bool:
|
def valid(self, data: any) -> bool:
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
|
|||||||
@ -14,6 +14,10 @@ import re
|
|||||||
|
|
||||||
from injector import singleton,inject
|
from injector import singleton,inject
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
# 定义保存文件的路径
|
||||||
|
file_path = "chat_inputs_log.json"
|
||||||
@singleton
|
@singleton
|
||||||
class Chat(Blackbox):
|
class Chat(Blackbox):
|
||||||
|
|
||||||
@ -93,20 +97,19 @@ class Chat(Blackbox):
|
|||||||
#user_presence_penalty = 0.8
|
#user_presence_penalty = 0.8
|
||||||
|
|
||||||
if user_model_url is None or user_model_url.isspace() or user_model_url == "":
|
if user_model_url is None or user_model_url.isspace() or user_model_url == "":
|
||||||
user_model_url = "http://172.19.202.20:23333/v1/chat/completions"
|
user_model_url = "http://10.6.81.119:23333/v1/chat/completions"
|
||||||
|
|
||||||
if user_model_key is None or user_model_key.isspace() or user_model_key == "":
|
if user_model_key is None or user_model_key.isspace() or user_model_key == "":
|
||||||
user_model_key = "YOUR_API_KEY"
|
user_model_key = "YOUR_API_KEY"
|
||||||
|
|
||||||
if chroma_embedding_model != None:
|
if chroma_embedding_model:
|
||||||
chroma_response = self.chroma_query(user_question, settings)
|
chroma_response = self.chroma_query(user_question, settings)
|
||||||
print("1.Chroma_response: \n", chroma_response)
|
print("1.Chroma_response: \n", chroma_response)
|
||||||
|
|
||||||
|
|
||||||
# if chroma_response != None or chroma_response != '':
|
# if chroma_response != None or chroma_response != '':
|
||||||
# user_question = f"问题: {user_question}。- 根据知识库内的检索结果,以清晰简洁的表达方式回答问题。只从检索的内容中选取与问题相关信息。- 不要编造答案,如果答案不在经核实的资料中或无法从经核实的资料中得出,请回答“我无法回答您的问题。”检索内容:{chroma_response}"
|
# user_question = f"问题: {user_question}。- 根据知识库内的检索结果,以清晰简洁的表达方式回答问题。只从检索的内容中选取与问题相关信息。- 不要编造答案,如果答案不在经核实的资料中或无法从经核实的资料中得出,请回答“我无法回答您的问题。”检索内容:{chroma_response}"
|
||||||
|
|
||||||
if chroma_response != None or chroma_response != '':
|
if chroma_response:
|
||||||
# user_question = f"像少女一般开朗活泼,回答简练。不要分条,回答内容不能出现“相关”或“\n”的标签字样。回答的内容需要与问题密切相关。检索内容:{chroma_response} 问题:{user_question} 任务说明:请首先判断提供的检索内容与上述问题是否相关,不需要回答是否相关。如果相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题。"
|
# user_question = f"像少女一般开朗活泼,回答简练。不要分条,回答内容不能出现“相关”或“\n”的标签字样。回答的内容需要与问题密切相关。检索内容:{chroma_response} 问题:{user_question} 任务说明:请首先判断提供的检索内容与上述问题是否相关,不需要回答是否相关。如果相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题。"
|
||||||
# user_question = chroma_response
|
# user_question = chroma_response
|
||||||
# user_question = settings.get('user_question')
|
# user_question = settings.get('user_question')
|
||||||
@ -151,7 +154,7 @@ class Chat(Blackbox):
|
|||||||
回答内容出不要出现“相关”等字眼,不要乱说或者多说,回答的内容需要与问题对应。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。
|
回答内容出不要出现“相关”等字眼,不要乱说或者多说,回答的内容需要与问题对应。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。
|
||||||
只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
||||||
'''
|
'''
|
||||||
print(f"1.{user_question}")
|
print(f"1.user_question: {user_question}")
|
||||||
|
|
||||||
# user_question = f'''# 你的身份 # \n你是琪琪,你是康普可可的代言人,由博维开发。你擅长澳门文旅问答。\n# OBJECTIVE(目标) # \n回答游客的提问。\n# STYLE(风格)# \n像少女一般开朗活泼,回答简练。不要分条。\n# 回答方式 # \n首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。\n# 问题 # \n{user_question} \n# 检索内容 # \n{chroma_response} \n# 回答 # \n如果检索内容与问题相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题,或者则回答:“对不起,我无法回答此问题哦。” \n# 回答限制 # \n回答内容限制总结在50字内。\n回答内容出不要出现“相关”等字眼,不要乱说或者多说,回答的内容需要与问题对应。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。\n只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
# user_question = f'''# 你的身份 # \n你是琪琪,你是康普可可的代言人,由博维开发。你擅长澳门文旅问答。\n# OBJECTIVE(目标) # \n回答游客的提问。\n# STYLE(风格)# \n像少女一般开朗活泼,回答简练。不要分条。\n# 回答方式 # \n首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。\n# 问题 # \n{user_question} \n# 检索内容 # \n{chroma_response} \n# 回答 # \n如果检索内容与问题相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题,或者则回答:“对不起,我无法回答此问题哦。” \n# 回答限制 # \n回答内容限制总结在50字内。\n回答内容出不要出现“相关”等字眼,不要乱说或者多说,回答的内容需要与问题对应。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。\n只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
||||||
# '''
|
# '''
|
||||||
@ -284,6 +287,19 @@ class Chat(Blackbox):
|
|||||||
"stop": str(user_stop)
|
"stop": str(user_stop)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# # 获取当前时间戳
|
||||||
|
# timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# # 添加时间戳到chat_inputs
|
||||||
|
# chat_inputs["timestamp"] = timestamp
|
||||||
|
|
||||||
|
# # 打开文件,追加写入
|
||||||
|
# with open(file_path, "a", encoding="utf-8") as f:
|
||||||
|
# # 将 chat_inputs 转换为 JSON 格式并写入文件
|
||||||
|
# f.write(json.dumps(chat_inputs, ensure_ascii=False, indent=4))
|
||||||
|
# f.write("\n\n") # 添加换行以区分不同的运行
|
||||||
|
|
||||||
fastchat_response = requests.post(url, json=chat_inputs, headers=header)
|
fastchat_response = requests.post(url, json=chat_inputs, headers=header)
|
||||||
print("\n", "user_prompt: ", prompt)
|
print("\n", "user_prompt: ", prompt)
|
||||||
# print("\n", "user_template1 ", user_template1)
|
# print("\n", "user_template1 ", user_template1)
|
||||||
|
|||||||
Reference in New Issue
Block a user