之前存在106.52上的仓库被重新初始化了,同时增加了测试账号的兼容,测试账号hxbtest001,...hxbtest005
This commit is contained in:
@@ -286,21 +286,26 @@ def upload_file(tenant_id,mesum_id):
|
||||
|
||||
if parsed_json_res.get('success') is True:
|
||||
parsed_json_data = parsed_json_res.get('data')
|
||||
matchedAntiqueArray = parsed_json_data.get('antique').split(';') # 识别出的文物的数组,中间以';'分割,可能有多个
|
||||
if len(matchedAntiqueArray) ==1: # 只有一个匹配项,直接返回
|
||||
matchedAntiqueLabelArray = parsed_json_data.get('antique').split(';') # 识别出的文物的数组,中间以';'分割,可能有多个
|
||||
if len(matchedAntiqueLabelArray) ==1: # 只有一个匹配项
|
||||
logging.info(f"识别完成 得到1个,{parsed_json_data.get('antique')} {labels_with_id} ")
|
||||
for item in labels_with_id:
|
||||
if item['label'] == parsed_json_data.get('antique'):
|
||||
if is_base_same(item['label'],parsed_json_data.get('antique')):
|
||||
parsed_json_data['id'] = item.get('id')
|
||||
antique = {'label': item.get('label')+' '+item.get('category',''),'id':item.get('id')}
|
||||
matchedArray.append(antique)
|
||||
if len(matchedArray) > 1:
|
||||
parsed_json_data['matchedArray'] = matchedArray
|
||||
else: # 有多个匹配项,需要进行多个匹配
|
||||
for label in matchedAntiqueArray[:5]:
|
||||
for label in matchedAntiqueLabelArray[:5]:
|
||||
antique= {'label':label}
|
||||
for item in labels_with_id:
|
||||
if item['label'] == label:
|
||||
antique['id'] = item.get('id')
|
||||
matchedArray.append(antique)
|
||||
if len(matchedArray) > 0:
|
||||
parsed_json_data['matchedArray'] = matchedArray
|
||||
|
||||
if len(matchedArray) > 0:
|
||||
parsed_json_data['matchedArray'] = matchedArray
|
||||
logging.info(f"{parsed_json_data}")
|
||||
return jsonify({'message': 'File uploaded successfully','text': message.content,
|
||||
'data': parsed_json_data}), 200
|
||||
@@ -888,6 +893,9 @@ def list_objects(tenant_id,bucket: str, prefix: str = "", recursive: bool = True
|
||||
except Exception as e:
|
||||
return get_error_data_result(message=f"minio put list objects error {e}")
|
||||
|
||||
@manager.route('/get_v1_uuid', methods=['GET'])
|
||||
def get_v1_uuid():
|
||||
return get_result(data={"uuid":get_uuid()})
|
||||
#------------------------------------------------
|
||||
def audio_fade_in(audio_data, fade_length):
|
||||
# 假设音频数据是16位单声道PCM
|
||||
@@ -915,4 +923,28 @@ def parse_markdown_json(json_string):
|
||||
# 如果解析失败,返回错误信息
|
||||
return {'success': False, 'data': str(e)}
|
||||
else:
|
||||
return {'success': False, 'data': 'not a valid markdown json string'}
|
||||
return {'success': False, 'data': 'not a valid markdown json string'}
|
||||
|
||||
|
||||
def is_base_same(a, b):
|
||||
"""
|
||||
判断两个字符串是否除了尾部数字外完全相同
|
||||
|
||||
参数:
|
||||
a, b: 要比较的两个字符串
|
||||
|
||||
返回:
|
||||
bool: 如果基础部分相同返回True,否则返回False
|
||||
("陶觚", "陶觚1"), # 相同
|
||||
("陶觚1", "陶觚2"), # 相同
|
||||
("陶觚", "陶觚12"), # 相同
|
||||
"""
|
||||
# 创建正则表达式模式:匹配基础部分(忽略尾部数字)
|
||||
pattern = re.compile(r'^(.*?)(?:\d*)$')
|
||||
|
||||
# 提取两个字符串的基础部分
|
||||
base_a = pattern.match(a).group(1)
|
||||
base_b = pattern.match(b).group(1)
|
||||
|
||||
# 比较基础部分是否相同
|
||||
return base_a == base_b
|
||||
@@ -115,7 +115,7 @@ def update(tenant_id, chat_id, session_id):
|
||||
@token_required
|
||||
def completion(tenant_id, chat_id): # chat_id 和 别的文件中的dialog_id 应该是一个意思? cyx 2025-01-25
|
||||
req = request.json
|
||||
logging.info(f"/chats/{chat_id}/completions--0 req={req}") # cyx
|
||||
#logging.info(f"/chats/{chat_id}/completions--0 req={req}") # cyx
|
||||
if not req.get("session_id"): # session_id 和 别的文件中的conversation_id 应该是一个意思? cyx 2025-01-25
|
||||
conv = {
|
||||
"id": get_uuid(),
|
||||
@@ -130,6 +130,17 @@ def completion(tenant_id, chat_id): # chat_id 和 别的文件中的dialog_id
|
||||
session_id = conv.id
|
||||
else:
|
||||
session_id = req.get("session_id")
|
||||
# 2025 0423 cyx 修改,前端传入的session_id ,但数据库库中可能不存在,需要创建
|
||||
conv_exist = ConversationService.query(id=session_id, dialog_id=chat_id)
|
||||
if not conv_exist: # session_id 的对话在数据库中不存在 # 当 conv_exist 为 None、空列表 []、空元组 () 等时进入此分支
|
||||
conv = {
|
||||
"id": session_id,
|
||||
"dialog_id": chat_id,
|
||||
"name": req.get("name", "New session"),
|
||||
"message": [{"role": "assistant", "content": "Hi! I am your assistant,can I help you?"}]
|
||||
}
|
||||
ConversationService.save(**conv)
|
||||
#-------------------------------------
|
||||
if not req.get("question"):
|
||||
return get_error_data_result(message="Please input your question.")
|
||||
|
||||
@@ -148,6 +159,7 @@ def completion(tenant_id, chat_id): # chat_id 和 别的文件中的dialog_id
|
||||
if not conv:
|
||||
return get_error_data_result(message="Session does not exist")
|
||||
conv = conv[0]
|
||||
#logging.info(f"/chats/{chat_id}/completions--4 history_limit={history_limit} conv={conv.message}") # cyx
|
||||
if not DialogService.query(id=chat_id, tenant_id=tenant_id, status=StatusEnum.VALID.value):
|
||||
return get_error_data_result(message="You do not own the chat")
|
||||
msg = []
|
||||
@@ -172,7 +184,6 @@ def completion(tenant_id, chat_id): # chat_id 和 别的文件中的dialog_id
|
||||
current_assistant_count += 1
|
||||
continue
|
||||
msg.append(m)
|
||||
|
||||
message_id = msg[-1].get("id")
|
||||
e, dia = DialogService.get_by_id(conv.dialog_id)
|
||||
logging.info(f"/chats/{chat_id}/completions req={req}--dale --2 history_limit={history_limit} dia {dia}") # cyx
|
||||
|
||||
@@ -48,8 +48,8 @@ class MesumAntiqueService(CommonService):
|
||||
# 统一替换中文分号为英文分号,并去除末尾分号
|
||||
if categories_text:
|
||||
categories_text = categories_text.replace(";", ";").rstrip(";")
|
||||
# 分割并清理空格/空值
|
||||
mesum_antique_categories = [dynasty.strip() for dynasty in categories_text.split(";") if dynasty.strip()]
|
||||
# 分割并清理空格/空值
|
||||
mesum_antique_categories = [dynasty.strip() for dynasty in categories_text.split(";") if dynasty.strip()]
|
||||
|
||||
finally:
|
||||
pass
|
||||
@@ -115,7 +115,8 @@ class MesumAntiqueService(CommonService):
|
||||
for obj in query.dicts():
|
||||
labels_data.append({
|
||||
'id': obj['id'],
|
||||
'label': obj['label']
|
||||
'label': obj['label'],
|
||||
"category": obj['category'],
|
||||
})
|
||||
|
||||
return labels_data
|
||||
|
||||
@@ -625,7 +625,7 @@ def chat(dialog, messages, stream=True, **kwargs):
|
||||
fid = None
|
||||
llm_id = tmp[0]
|
||||
if len(tmp)>1: fid = tmp[1]
|
||||
|
||||
#logging.info(f"dialog_service--0 message={messages}") # cyx
|
||||
llm = LLMService.query(llm_name=llm_id) if not fid else LLMService.query(llm_name=llm_id, fid=fid)
|
||||
if not llm:
|
||||
llm = TenantLLMService.query(tenant_id=dialog.tenant_id, llm_name=llm_id) if not fid else \
|
||||
@@ -716,8 +716,8 @@ def chat(dialog, messages, stream=True, **kwargs):
|
||||
top=dialog.top_k, aggs=False, rerank_mdl=rerank_mdl)
|
||||
knowledges = [ck["content_with_weight"] for ck in kbinfos["chunks"]]
|
||||
logging.debug( "{}->{}".format(" ".join(questions), "\n->".join(knowledges)))
|
||||
# 打印历史记录
|
||||
# logging.info( "dale-----!!!:{}->{}".format(" ".join(questions), "\n->".join(knowledges)))
|
||||
# 打印查询到的知识库信息
|
||||
#logging.info( "知识库中知识--!!!:{}->{}".format(" ".join(questions), "\n->".join(knowledges)))
|
||||
retrieval_tm = timer()
|
||||
|
||||
if not knowledges and prompt_config.get("empty_response"):
|
||||
@@ -736,7 +736,7 @@ def chat(dialog, messages, stream=True, **kwargs):
|
||||
assert len(msg) >= 2, f"message_fit_in has bug: {msg}"
|
||||
prompt = msg[0]["content"]
|
||||
prompt += "\n\n### Query:\n%s" % " ".join(questions)
|
||||
|
||||
#logging.info(f"dialog_service--3 chat msg={msg}") # cyx
|
||||
if "max_tokens" in gen_conf:
|
||||
gen_conf["max_tokens"] = min(
|
||||
gen_conf["max_tokens"],
|
||||
|
||||
Reference in New Issue
Block a user