Fix rerank_model bug in chat and markdown bug (#4061)

### What problem does this PR solve?

Fix rerank_model bug in chat and markdown bug
#4000
#3992
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: liuhua <10215101452@stu.ecun.edu.cn>
This commit is contained in:
liuhua 2024-12-17 16:03:37 +08:00 committed by GitHub
parent bcccaccc2b
commit 1d65299791
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 11 deletions

View File

@ -82,7 +82,8 @@ def create(tenant_id):
req["top_k"] = req.get("top_k", 1024) req["top_k"] = req.get("top_k", 1024)
req["rerank_id"] = req.get("rerank_id", "") req["rerank_id"] = req.get("rerank_id", "")
if req.get("rerank_id"): if req.get("rerank_id"):
if not TenantLLMService.query(tenant_id=tenant_id,llm_name=req.get("rerank_id"),model_type="rerank"): value_rerank_model = ["BAAI/bge-reranker-v2-m3","maidalun1020/bce-reranker-base_v1"]
if req["rerank_id"] not in value_rerank_model and not TenantLLMService.query(tenant_id=tenant_id,llm_name=req.get("rerank_id"),model_type="rerank"):
return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist") return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist")
if not req.get("llm_id"): if not req.get("llm_id"):
req["llm_id"] = tenant.llm_id req["llm_id"] = tenant.llm_id
@ -161,7 +162,7 @@ def update(tenant_id,chat_id):
req["do_refer"]=req.pop("show_quotation") req["do_refer"]=req.pop("show_quotation")
if "dataset_ids" in req: if "dataset_ids" in req:
if not ids: if not ids:
return get_error_data_result("`datasets` can't be empty") return get_error_data_result("`dataset_ids` can't be empty")
if ids: if ids:
for kb_id in ids: for kb_id in ids:
kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id)
@ -188,9 +189,6 @@ def update(tenant_id,chat_id):
e, tenant = TenantService.get_by_id(tenant_id) e, tenant = TenantService.get_by_id(tenant_id)
if not e: if not e:
return get_error_data_result(message="Tenant not found!") return get_error_data_result(message="Tenant not found!")
if req.get("rerank_model"):
if not TenantLLMService.query(tenant_id=tenant_id,llm_name=req.get("rerank_model"),model_type="rerank"):
return get_error_data_result(f"`rerank_model` {req.get('rerank_model')} doesn't exist")
# prompt # prompt
prompt = req.get("prompt") prompt = req.get("prompt")
key_mapping = {"parameters": "variables", key_mapping = {"parameters": "variables",
@ -210,6 +208,10 @@ def update(tenant_id,chat_id):
req["prompt_config"] = req.pop("prompt") req["prompt_config"] = req.pop("prompt")
e, res = DialogService.get_by_id(chat_id) e, res = DialogService.get_by_id(chat_id)
res = res.to_json() res = res.to_json()
if req.get("rerank_id"):
value_rerank_model = ["BAAI/bge-reranker-v2-m3","maidalun1020/bce-reranker-base_v1"]
if req["rerank_id"] not in value_rerank_model and not TenantLLMService.query(tenant_id=tenant_id,llm_name=req.get("rerank_id"),model_type="rerank"):
return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist")
if "name" in req: if "name" in req:
if not req.get("name"): if not req.get("name"):
return get_error_data_result(message="`name` is not empty.") return get_error_data_result(message="`name` is not empty.")

View File

@ -2243,7 +2243,7 @@ Success:
"data": { "data": {
"form": {}, "form": {},
"label": "Answer", "label": "Answer",
"name": "对话_0" "name": "dialog_0"
}, },
"dragging": false, "dragging": false,
"height": 44, "height": 44,
@ -2362,7 +2362,7 @@ curl --request POST \
--data-binary ' --data-binary '
{ {
"lang":"English" "lang":"English"
"file":"明天天气如何" "file":"How is the weather tomorrow?"
}' }'
``` ```

View File

@ -1435,7 +1435,7 @@ session = create_session(AGENT_ID,rag_object)
--- ---
## Converse with agent without `begin` component ## Converse with agent
```python ```python
Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]] Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]]

View File

@ -169,11 +169,13 @@ class Markdown(MarkdownParser):
sections = [] sections = []
tbls = [] tbls = []
for sec in remainder.split("\n"): for sec in remainder.split("\n"):
if num_tokens_from_string(sec) > 10 * self.chunk_token_num: if num_tokens_from_string(sec) > 3 * self.chunk_token_num:
sections.append((sec[:int(len(sec) / 2)], "")) sections.append((sec[:int(len(sec) / 2)], ""))
sections.append((sec[int(len(sec) / 2):], "")) sections.append((sec[int(len(sec) / 2):], ""))
else: else:
if sections and sections[-1][0].strip().find("#") == 0: if sec.strip().find("#") == 0:
sections.append((sec, ""))
elif sections and sections[-1][0].strip().find("#") == 0:
sec_, _ = sections.pop(-1) sec_, _ = sections.pop(-1)
sections.append((sec_ + "\n" + sec, "")) sections.append((sec_ + "\n" + sec, ""))
else: else: