liuhua
liuhua
commited on
Commit
·
af2dd36
1
Parent(s):
faa9f3e
Fix rerank_model bug in chat and markdown bug (#4061)
Browse files### 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 <[email protected]>
api/apps/sdk/chat.py
CHANGED
@@ -82,7 +82,8 @@ def create(tenant_id):
|
|
82 |
req["top_k"] = req.get("top_k", 1024)
|
83 |
req["rerank_id"] = req.get("rerank_id", "")
|
84 |
if req.get("rerank_id"):
|
85 |
-
|
|
|
86 |
return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist")
|
87 |
if not req.get("llm_id"):
|
88 |
req["llm_id"] = tenant.llm_id
|
@@ -161,7 +162,7 @@ def update(tenant_id,chat_id):
|
|
161 |
req["do_refer"]=req.pop("show_quotation")
|
162 |
if "dataset_ids" in req:
|
163 |
if not ids:
|
164 |
-
return get_error_data_result("`
|
165 |
if ids:
|
166 |
for kb_id in ids:
|
167 |
kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id)
|
@@ -188,9 +189,6 @@ def update(tenant_id,chat_id):
|
|
188 |
e, tenant = TenantService.get_by_id(tenant_id)
|
189 |
if not e:
|
190 |
return get_error_data_result(message="Tenant not found!")
|
191 |
-
if req.get("rerank_model"):
|
192 |
-
if not TenantLLMService.query(tenant_id=tenant_id,llm_name=req.get("rerank_model"),model_type="rerank"):
|
193 |
-
return get_error_data_result(f"`rerank_model` {req.get('rerank_model')} doesn't exist")
|
194 |
# prompt
|
195 |
prompt = req.get("prompt")
|
196 |
key_mapping = {"parameters": "variables",
|
@@ -210,6 +208,10 @@ def update(tenant_id,chat_id):
|
|
210 |
req["prompt_config"] = req.pop("prompt")
|
211 |
e, res = DialogService.get_by_id(chat_id)
|
212 |
res = res.to_json()
|
|
|
|
|
|
|
|
|
213 |
if "name" in req:
|
214 |
if not req.get("name"):
|
215 |
return get_error_data_result(message="`name` is not empty.")
|
|
|
82 |
req["top_k"] = req.get("top_k", 1024)
|
83 |
req["rerank_id"] = req.get("rerank_id", "")
|
84 |
if req.get("rerank_id"):
|
85 |
+
value_rerank_model = ["BAAI/bge-reranker-v2-m3","maidalun1020/bce-reranker-base_v1"]
|
86 |
+
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"):
|
87 |
return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist")
|
88 |
if not req.get("llm_id"):
|
89 |
req["llm_id"] = tenant.llm_id
|
|
|
162 |
req["do_refer"]=req.pop("show_quotation")
|
163 |
if "dataset_ids" in req:
|
164 |
if not ids:
|
165 |
+
return get_error_data_result("`dataset_ids` can't be empty")
|
166 |
if ids:
|
167 |
for kb_id in ids:
|
168 |
kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id)
|
|
|
189 |
e, tenant = TenantService.get_by_id(tenant_id)
|
190 |
if not e:
|
191 |
return get_error_data_result(message="Tenant not found!")
|
|
|
|
|
|
|
192 |
# prompt
|
193 |
prompt = req.get("prompt")
|
194 |
key_mapping = {"parameters": "variables",
|
|
|
208 |
req["prompt_config"] = req.pop("prompt")
|
209 |
e, res = DialogService.get_by_id(chat_id)
|
210 |
res = res.to_json()
|
211 |
+
if req.get("rerank_id"):
|
212 |
+
value_rerank_model = ["BAAI/bge-reranker-v2-m3","maidalun1020/bce-reranker-base_v1"]
|
213 |
+
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"):
|
214 |
+
return get_error_data_result(f"`rerank_model` {req.get('rerank_id')} doesn't exist")
|
215 |
if "name" in req:
|
216 |
if not req.get("name"):
|
217 |
return get_error_data_result(message="`name` is not empty.")
|
docs/references/http_api_reference.md
CHANGED
@@ -1380,7 +1380,7 @@ curl --request POST \
|
|
1380 |
- `"frequency penalty"`: `float`
|
1381 |
Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
|
1382 |
- `"max_token"`: `integer`
|
1383 |
-
The maximum length of the model's output, measured in the number of tokens (words or pieces of words). If disabled, you lift the maximum token limit, allowing the model to determine the number of tokens in its responses. Defaults to `512`.
|
1384 |
- `"prompt"`: (*Body parameter*), `object`
|
1385 |
Instructions for the LLM to follow. If it is not explicitly set, a JSON object with the following values will be generated as the default. A `prompt` JSON object contains the following attributes:
|
1386 |
- `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
|
@@ -2243,7 +2243,7 @@ Success:
|
|
2243 |
"data": {
|
2244 |
"form": {},
|
2245 |
"label": "Answer",
|
2246 |
-
"name": "
|
2247 |
},
|
2248 |
"dragging": false,
|
2249 |
"height": 44,
|
@@ -2362,7 +2362,7 @@ curl --request POST \
|
|
2362 |
--data-binary '
|
2363 |
{
|
2364 |
"lang":"English"
|
2365 |
-
"file":"
|
2366 |
}'
|
2367 |
```
|
2368 |
|
|
|
1380 |
- `"frequency penalty"`: `float`
|
1381 |
Similar to the presence penalty, this reduces the model’s tendency to repeat the same words frequently. Defaults to `0.7`.
|
1382 |
- `"max_token"`: `integer`
|
1383 |
+
The maximum length of the model's output, measured in the number of tokens (words or pieces of words). If disabled, you lift the maximum token limit, allowing the model to determine the number of tokens in its responses. Defaults to `512`.
|
1384 |
- `"prompt"`: (*Body parameter*), `object`
|
1385 |
Instructions for the LLM to follow. If it is not explicitly set, a JSON object with the following values will be generated as the default. A `prompt` JSON object contains the following attributes:
|
1386 |
- `"similarity_threshold"`: `float` RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This argument sets the threshold for similarities between the user query and chunks. If a similarity score falls below this threshold, the corresponding chunk will be excluded from the results. The default value is `0.2`.
|
|
|
2243 |
"data": {
|
2244 |
"form": {},
|
2245 |
"label": "Answer",
|
2246 |
+
"name": "dialog_0"
|
2247 |
},
|
2248 |
"dragging": false,
|
2249 |
"height": 44,
|
|
|
2362 |
--data-binary '
|
2363 |
{
|
2364 |
"lang":"English"
|
2365 |
+
"file":"How is the weather tomorrow?"
|
2366 |
}'
|
2367 |
```
|
2368 |
|
docs/references/python_api_reference.md
CHANGED
@@ -1435,7 +1435,7 @@ session = create_session(AGENT_ID,rag_object)
|
|
1435 |
|
1436 |
---
|
1437 |
|
1438 |
-
## Converse with agent
|
1439 |
|
1440 |
```python
|
1441 |
Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]]
|
|
|
1435 |
|
1436 |
---
|
1437 |
|
1438 |
+
## Converse with agent
|
1439 |
|
1440 |
```python
|
1441 |
Session.ask(question: str, stream: bool = False) -> Optional[Message, iter[Message]]
|
rag/app/naive.py
CHANGED
@@ -169,11 +169,13 @@ class Markdown(MarkdownParser):
|
|
169 |
sections = []
|
170 |
tbls = []
|
171 |
for sec in remainder.split("\n"):
|
172 |
-
if num_tokens_from_string(sec) >
|
173 |
sections.append((sec[:int(len(sec) / 2)], ""))
|
174 |
sections.append((sec[int(len(sec) / 2):], ""))
|
175 |
else:
|
176 |
-
if
|
|
|
|
|
177 |
sec_, _ = sections.pop(-1)
|
178 |
sections.append((sec_ + "\n" + sec, ""))
|
179 |
else:
|
|
|
169 |
sections = []
|
170 |
tbls = []
|
171 |
for sec in remainder.split("\n"):
|
172 |
+
if num_tokens_from_string(sec) > 3 * self.chunk_token_num:
|
173 |
sections.append((sec[:int(len(sec) / 2)], ""))
|
174 |
sections.append((sec[int(len(sec) / 2):], ""))
|
175 |
else:
|
176 |
+
if sec.strip().find("#") == 0:
|
177 |
+
sections.append((sec, ""))
|
178 |
+
elif sections and sections[-1][0].strip().find("#") == 0:
|
179 |
sec_, _ = sections.pop(-1)
|
180 |
sections.append((sec_ + "\n" + sec, ""))
|
181 |
else:
|