mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
Merge pull request #13 from BoardWare-Genius/tom
chroma query add top distance
This commit is contained in:
@ -101,6 +101,10 @@ class Chat(Blackbox):
|
||||
chroma_response = self.chroma_query(user_question, settings)
|
||||
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
|
||||
@ -125,6 +129,7 @@ class Chat(Blackbox):
|
||||
'''
|
||||
|
||||
|
||||
|
||||
# 文心格式和openai的不一样,需要单独处理
|
||||
if re.search(r"ernie", user_model_name):
|
||||
# key = "24.22873ef3acf61fb343812681e4df251a.2592000.1719453781.282335-46723715" 没充钱,只有ernie-speed-128k能用
|
||||
@ -213,6 +218,7 @@ class Chat(Blackbox):
|
||||
1. **接收查询**:接收用户的问题。
|
||||
2. **判断问题**:首先自行判断下方问题与检索内容是否相关,若相关则根据检索内容总结概括相关信息进行回答;若检索内容与问题无关,则根据自身知识进行回答。
|
||||
3. **提供回答**:
|
||||
|
||||
```
|
||||
<context>
|
||||
{chroma_response}
|
||||
@ -220,6 +226,7 @@ class Chat(Blackbox):
|
||||
|
||||
基于“<context>”至“</context>”中的知识片段回答用户的问题。回答内容限制总结在50字内。
|
||||
请首先判断提供的检索内容与上述问题是否相关。如果相关,直接从检索内容中提炼出直接回答问题所需的信息,不要乱说或者回答“相关”等字眼。如果检索内容与问题不相关,则不参考检索内容,则回答:“对不起,我无法回答此问题哦。"
|
||||
|
||||
```
|
||||
## Example:
|
||||
|
||||
|
||||
@ -89,9 +89,24 @@ class ChromaQuery(Blackbox):
|
||||
)
|
||||
|
||||
# response = str(results["documents"] + results["metadatas"])
|
||||
response = str(results["documents"])
|
||||
# response = str(results["documents"])
|
||||
|
||||
return response
|
||||
final_result = ''
|
||||
|
||||
if results is not None:
|
||||
results_distances = results["distances"][0]
|
||||
|
||||
#distance越高越不准确
|
||||
top_distance = 0.8
|
||||
|
||||
|
||||
for i in range(len(results_distances)):
|
||||
if results_distances[i] < top_distance:
|
||||
final_result += results["documents"][0][i]
|
||||
|
||||
print("\n final_result: ", final_result)
|
||||
|
||||
return final_result
|
||||
|
||||
|
||||
async def fast_api_handler(self, request: Request) -> Response:
|
||||
|
||||
Reference in New Issue
Block a user