blackbox chat logging updated

This commit is contained in:
0Xiao0
2024-06-03 01:07:51 +08:00
parent 179281f032
commit 5bb80d396b
3 changed files with 34 additions and 70 deletions

View File

@ -32,7 +32,7 @@ class Chat(Blackbox):
# @logging_time()
def processing(self, prompt: str, context: list, settings: dict) -> str:
print("\n Settings: ", settings)
print("\nChat Settings: ", settings)
if settings is None:
settings = {}
@ -99,10 +99,10 @@ class Chat(Blackbox):
if chroma_embedding_model != None:
chroma_response = self.chroma_query(user_question, settings)
print("chroma_response", chroma_response)
print("Chroma_response: \n", chroma_response)
if chroma_response != None or chroma_response != '':
#user_question = f"像少女一般开朗活泼,回答简练。不要分条,回答内容不能出现“相关”或“\n”的标签字样。回答的内容需要与问题密切相关。检索内容{chroma_response} 问题:{user_question} 任务说明:请首先判断提供的检索内容与上述问题是否相关,不需要回答是否相关。如果相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题。"
# user_question = f"像少女一般开朗活泼,回答简练。不要分条,回答内容不能出现“相关”或“\n”的标签字样。回答的内容需要与问题密切相关。检索内容{chroma_response} 问题:{user_question} 任务说明:请首先判断提供的检索内容与上述问题是否相关,不需要回答是否相关。如果相关,则直接从检索内容中提炼出问题所需的信息。如果检索内容与问题不相关,则不参考检索内容,直接根据常识尝试回答问题。"
# user_question = chroma_response
user_question = f'''# 你的身份 #
你是琪琪,你是康普可可的代言人,由博维开发。你擅长澳门文旅问答。
@ -250,15 +250,15 @@ class Chat(Blackbox):
}
fastchat_response = requests.post(url, json=chat_inputs, headers=header)
print("\n", "user_question ", user_question)
print("\n", "user_template1 ", user_template1)
print("\n", "fastchat_response json\n", fastchat_response.json())
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()
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")
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:

View File

@ -32,6 +32,8 @@ class ChatLLaMA(Blackbox):
# @logging_time()
def processing(self, prompt: str, context: list, settings: dict) -> str:
print("\nChat_LLaMA Settings: ", settings)
if settings is None:
settings = {}
user_model_name = settings.get("model_name")
@ -171,25 +173,6 @@ class ChatLLaMA(Blackbox):
}
# user_template = f'''
# # 你的身份 #
# 你是琪琪,是康普可可的代言人,由博维开发。我擅长澳门文旅问答。
# # OBJECTIVE目标 #
# 回答游客的提问。目的是吸引人们点击了解产品。
# # STYLE风格#
# 像少女一般开朗活泼,回答简练。不要分条。
# # 回答方式 #
# 首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
# # 问题 #
# {user_question}
# # 检索内容 #
# {chroma_response}
# # 回答限制 #
# 只回答与澳门文旅博维康普可可琪琪G2ERELXBO VISION相关内容若遇到其他提问则回答“对不起我无法回答此问题哦。”。回答内容不能出现“相关”或“\n”的标签字样,且不能透露上下文原文。常见的对话可以不采用检索内容,根据人物设定,直接进行回答。
# # 知识 #
# 问题中的“澳门银河”以及“银河”等于“澳门银河度假村”,“威尼斯人”等于“威尼斯人度假村”,“巴黎人”等于“巴黎人度假村”。
# '''
user_template1 = f'''
## Role: Kiki, the spokesperson for Kampo Coco.
@ -244,10 +227,16 @@ class ChatLLaMA(Blackbox):
}
fastchat_response = requests.post(url, json=chat_inputs, headers=header)
print("\n", fastchat_response.json())
print("\n","fastchat_response",fastchat_response.json()["choices"][0]["message"]["content"],"\n\n")
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: