feat:update scene param

This commit is contained in:
aries_ckt
2023-11-16 22:23:47 +08:00
parent 6253d3b429
commit 3e560099b4
4 changed files with 34 additions and 30 deletions

View File

@@ -75,10 +75,13 @@ def __new_conversation(chat_mode, user_id) -> ConversationVo:
def get_db_list():
dbs = CFG.LOCAL_DB_MANAGE.get_db_list()
params: dict = {}
db_params = []
for item in dbs:
params.update({item["db_name"]: item["db_name"]})
return params
params: dict = {}
params.update({"param": item["db_name"]})
params.update({"type": item["db_type"]})
db_params.append(params)
return db_params
def plugins_select_info():
@@ -110,12 +113,15 @@ def knowledge_list_info():
def knowledge_list():
"""return knowledge space list"""
params: dict = {}
request = KnowledgeSpaceRequest()
spaces = knowledge_service.get_knowledge_space(request)
space_list = []
for space in spaces:
params.update({space.name: space.name})
return params
params: dict = {}
params.update({"param": space.name})
params.update({"type": "space"})
space_list.append(params)
return space_list
def get_model_controller() -> BaseModelController:

View File

@@ -12,11 +12,11 @@ CFG = Config()
PROMPT_SCENE_DEFINE = """"""
_DEFAULT_TEMPLATE_ZH = """根据提供的上下文信息,我们已经提供了一个到某一点的现有总结:{existing_answer}\n 请根据你之前推理的内容进行最终的总结,总结的时候需要有关键见解,并且总结回答的时候最好按照1.2.3.进行总结."""
_DEFAULT_TEMPLATE_ZH = """根据提供的上下文信息,我们已经提供了一个到某一点的现有总结:{existing_answer}\n 请根据你之前推理的内容进行最终的总结,并且总结回答的时候最好按照1.2.3.进行总结."""
_DEFAULT_TEMPLATE_EN = """
We have provided an existing summary up to a certain point: {existing_answer}\nWe have the opportunity to refine the existing summary (only if needed) with some more context below.
\nBased on the previous reasoning, please summarize the final conclusion in accordance with points 1, 2, and 3. and give me a list of bullet points with key insights and the most important facts.
\nBased on the previous reasoning, please summarize the final conclusion in accordance with points 1, 2, and 3.
"""

View File

@@ -95,7 +95,7 @@ class ChatKnowledge(BaseChat):
@trace()
async def generate_input_values(self) -> Dict:
if self.space_context:
if self.space_context and self.space_context.get("prompt"):
self.prompt_template.template_define = self.space_context["prompt"]["scene"]
self.prompt_template.template = self.space_context["prompt"]["template"]
docs = await blocking_func_to_async(
@@ -111,9 +111,6 @@ class ChatKnowledge(BaseChat):
if not docs or len(docs) == 0:
print("no relevant docs to retrieve")
context = "no relevant docs to retrieve"
# raise ValueError(
# "you have no knowledge space, please add your knowledge space"
# )
else:
context = [d.page_content for d in docs]
context = context[: self.max_token]
@@ -155,23 +152,24 @@ class ChatKnowledge(BaseChat):
def merge_by_key(self, data, key):
result = {}
for item in data:
item_key = os.path.basename(item.get(key))
if item_key in result:
if "pages" in result[item_key] and "page" in item:
result[item_key]["pages"].append(str(item["page"]))
elif "page" in item:
result[item_key]["pages"] = [
result[item_key]["pages"],
str(item["page"]),
]
else:
if "page" in item:
result[item_key] = {
"source": item_key,
"pages": [str(item["page"])],
}
if item.get(key):
item_key = os.path.basename(item.get(key))
if item_key in result:
if "pages" in result[item_key] and "page" in item:
result[item_key]["pages"].append(str(item["page"]))
elif "page" in item:
result[item_key]["pages"] = [
result[item_key]["pages"],
str(item["page"]),
]
else:
result[item_key] = {"source": item_key}
if "page" in item:
result[item_key] = {
"source": item_key,
"pages": [str(item["page"])],
}
else:
result[item_key] = {"source": item_key}
return list(result.values())
@property

View File

@@ -17,13 +17,13 @@ _DEFAULT_TEMPLATE_ZH = """ 基于以下已知的信息, 专业、简要的回答
已知内容:
{context}
问题:
{question}
{question},请使用和用户相同的语言进行回答.
"""
_DEFAULT_TEMPLATE_EN = """ Based on the known information below, provide users with professional and concise answers to their questions. If the answer cannot be obtained from the provided content, please say: "The information provided in the knowledge base is not sufficient to answer this question." It is forbidden to make up information randomly. When answering, it is best to summarize according to points 1.2.3.
known information:
{context}
question:
{question}
{question},when answering, use the same language as the "user".
"""
_DEFAULT_TEMPLATE = (