mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
Merge branch 'main' into tom
This commit is contained in:
@ -32,6 +32,8 @@ class Chat(Blackbox):
|
||||
# @logging_time()
|
||||
def processing(self, prompt: str, context: list, settings: dict) -> str:
|
||||
|
||||
print("\nChat Settings: ", settings)
|
||||
|
||||
if settings is None:
|
||||
settings = {}
|
||||
user_model_name = settings.get("model_name")
|
||||
@ -58,16 +60,19 @@ class Chat(Blackbox):
|
||||
return JSONResponse(content={"error": "question is required"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if user_model_name is None or user_model_name.isspace() or user_model_name == "":
|
||||
user_model_name = "Qwen1.5-14B-Chat"
|
||||
user_model_name = "qwen"
|
||||
#user_model_name = "Qwen1.5-14B-Chat"
|
||||
|
||||
if user_template is None or user_template.isspace():
|
||||
user_template = ""
|
||||
|
||||
if user_temperature is None or user_temperature == "":
|
||||
user_temperature = 0.8
|
||||
user_temperature = 0
|
||||
#user_temperature = 0
|
||||
|
||||
if user_top_p is None or user_top_p == "":
|
||||
user_top_p = 0.8
|
||||
user_top_p = 0.1
|
||||
#user_top_p = 0.8
|
||||
|
||||
if user_n is None or user_n == "":
|
||||
user_n = 1
|
||||
@ -79,24 +84,51 @@ class Chat(Blackbox):
|
||||
user_stop = 100
|
||||
|
||||
if user_frequency_penalty is None or user_frequency_penalty == "":
|
||||
user_frequency_penalty = 0.5
|
||||
user_frequency_penalty = 0
|
||||
#user_frequency_penalty = 0.5
|
||||
|
||||
if user_presence_penalty is None or user_presence_penalty == "":
|
||||
user_presence_penalty = 0.8
|
||||
user_presence_penalty = 0
|
||||
#user_presence_penalty = 0.8
|
||||
|
||||
if user_model_url is None or user_model_url.isspace() or user_model_url == "":
|
||||
user_model_url = "http://120.196.116.194:48892/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 == "":
|
||||
user_model_key = "YOUR_API_KEY"
|
||||
|
||||
if chroma_embedding_model != None:
|
||||
chroma_response = self.chroma_query(user_question, settings)
|
||||
print(chroma_response)
|
||||
print("Chroma_response: \n", chroma_response)
|
||||
|
||||
|
||||
# if chroma_response != None or chroma_response != '':
|
||||
# user_question = f"问题: {user_question}。- 根据知识库内的检索结果,以清晰简洁的表达方式回答问题。只从检索的内容中选取与问题相关信息。- 不要编造答案,如果答案不在经核实的资料中或无法从经核实的资料中得出,请回答“我无法回答您的问题。”检索内容:{chroma_response}"
|
||||
|
||||
if chroma_response != None or chroma_response != '':
|
||||
# user_question = f"像少女一般开朗活泼,回答简练。不要分条,回答内容不能出现“相关”或“\n”的标签字样。回答的内容需要与问题密切相关。检索内容:{chroma_response} 问题:{user_question} 任务说明:请首先判断提供的检索内容与上述问题是否相关,不需要回答是否相关。如果相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题。"
|
||||
# user_question = chroma_response
|
||||
user_question = f'''# 你的身份 #
|
||||
你是琪琪,你是康普可可的代言人,由博维开发。你擅长澳门文旅问答。
|
||||
# OBJECTIVE(目标) #
|
||||
回答游客的提问。
|
||||
# STYLE(风格)#
|
||||
像少女一般开朗活泼,回答简练。不要分条。
|
||||
# 回答方式 #
|
||||
首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
|
||||
# 问题 #
|
||||
{user_question}
|
||||
# 检索内容 #
|
||||
{chroma_response}
|
||||
# 回答 #
|
||||
如果检索内容与问题相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题,或者则回答:“对不起,我无法回答此问题哦。”
|
||||
# 回答限制 #
|
||||
回答内容限制总结在50字内。
|
||||
回答内容出不要出现“相关”等字眼,不要乱说或者多说,回答的内容需要与问题对应。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。
|
||||
只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
||||
'''
|
||||
|
||||
|
||||
|
||||
# 文心格式和openai的不一样,需要单独处理
|
||||
if re.search(r"ernie", user_model_name):
|
||||
@ -149,25 +181,28 @@ class Chat(Blackbox):
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
user_template = '''
|
||||
# 你的身份 #
|
||||
你是琪琪,是康普可可的代言人,由博维开发。你擅长澳门文旅问答。
|
||||
# OBJECTIVE(目标) #
|
||||
回答游客的提问。目的是吸引人们点击了解产品。
|
||||
# STYLE(风格)#
|
||||
像少女一般开朗活泼,回答简练。不要分条。效仿戴森等宣传类似产品的成功公司的写作风格。
|
||||
# 回答方式 #
|
||||
首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
|
||||
# 回答限制 #
|
||||
只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”
|
||||
# 问题 #
|
||||
{user_question}
|
||||
# 检索内容 #
|
||||
{chroma_response}
|
||||
'''
|
||||
|
||||
user_template = '''
|
||||
# Role: 康普可可的代言人。
|
||||
# user_template = f'''
|
||||
# # 你的身份 #
|
||||
# 你是琪琪,是康普可可的代言人,由博维开发。我擅长澳门文旅问答。
|
||||
# # OBJECTIVE(目标) #
|
||||
# 回答游客的提问。目的是吸引人们点击了解产品。
|
||||
# # STYLE(风格)#
|
||||
# 像少女一般开朗活泼,回答简练。不要分条。
|
||||
# # 回答方式 #
|
||||
# 首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
|
||||
# # 问题 #
|
||||
# {user_question}
|
||||
# # 检索内容 #
|
||||
# {chroma_response}
|
||||
# # 回答限制 #
|
||||
# 只回答与澳门文旅,博维,康普可可,琪琪,G2E,RELX,BO VISION相关内容,若遇到其他提问则回答:“对不起,我无法回答此问题哦。”。回答内容不能出现“相关”或“\n”的标签字样,且不能透露上下文原文。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。
|
||||
# # 知识 #
|
||||
# 问题中的“澳门银河”以及“银河”等于“澳门银河度假村”,“威尼斯人”等于“威尼斯人度假村”,“巴黎人”等于“巴黎人度假村”。
|
||||
# '''
|
||||
|
||||
user_template1 = f'''
|
||||
# Role: 琪琪,康普可可的代言人。
|
||||
|
||||
## Profile:
|
||||
**Author**: 琪琪。
|
||||
@ -181,23 +216,27 @@ class Chat(Blackbox):
|
||||
|
||||
## Workflow:
|
||||
1. **接收查询**:接收用户的问题。
|
||||
2. **提供回答**:
|
||||
2. **判断问题**:首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
|
||||
3. **提供回答**:
|
||||
|
||||
```
|
||||
<context>
|
||||
{chroma_response}
|
||||
</context>
|
||||
|
||||
基于“<context>”至“</context>”中的知识片段回答用户的问题。如果没有知识片段,则诚实的告诉用户:对不起,我还不知道这个问题的答案。否则进行回复。
|
||||
基于“<context>”至“</context>”中的知识片段回答用户的问题。回答内容限制总结在50字内。
|
||||
请首先判断提供的检索内容与上述问题是否相关。如果相关,直接从检索内容中提炼出直接回答问题所需的信息,不要乱说或者回答“相关”等字眼。如果检索内容与问题不相关,则不参考检索内容,则回答:“对不起,我无法回答此问题哦。"
|
||||
|
||||
```
|
||||
## Example:
|
||||
|
||||
用户询问:“中国的首都是哪个城市?” 。
|
||||
2.1检索知识库,首先检查知识片段,如果“<context>”至“</context>”标签中没有内容,则不能进行回复。
|
||||
2.1检索知识库,首先检查知识片段,如果“<context>”至“</context>”标签中没有与用户的问题相关的内容,则回答:“对不起,我无法回答此问题哦。
|
||||
2.2如果有知识片段,在做出回复时,只能基于“<context>”至“</context>”标签中的内容进行回答,且不能透露上下文原文,同时也不能出现“<context>”或“</context>”的标签字样。
|
||||
'''
|
||||
|
||||
prompt_template = [
|
||||
{"role": "system", "content": user_template},
|
||||
{"role": "system", "content": user_template1}
|
||||
]
|
||||
|
||||
chat_inputs={
|
||||
@ -218,8 +257,16 @@ class Chat(Blackbox):
|
||||
}
|
||||
|
||||
fastchat_response = requests.post(url, json=chat_inputs, headers=header)
|
||||
print("\n", "user_prompt: ", prompt)
|
||||
# print("\n", "user_template1 ", user_template1)
|
||||
print("\n", "fastchat_response json:\n", fastchat_response.json())
|
||||
response_result = fastchat_response.json()
|
||||
|
||||
return fastchat_response.json()["choices"][0]["message"]["content"]
|
||||
if response_result.get("choices") is None:
|
||||
return JSONResponse(content={"error": "LLM handle failure"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||
else:
|
||||
print("\n", "user_answer: ", fastchat_response.json()["choices"][0]["message"]["content"],"\n\n")
|
||||
return fastchat_response.json()["choices"][0]["message"]["content"]
|
||||
|
||||
async def fast_api_handler(self, request: Request) -> Response:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user