leecjnew commited on
Commit
ab7218e
·
1 Parent(s): 86d1ffb

fix: Reference markers in the context may be carried over into the next answer (#1855)

Browse files

The answer in the context carries reference markers and passes them to
the large model, which may include the markers in the new answer,
leading to abnormal reference points.
```
{'role': 'assistant', 'content': '设置在地下或半地下空间 ##0$$。'}
```

![image](https://github.com/user-attachments/assets/bcfdb3fc-7b54-44cb-ab70-2f9b715d06b8)

### What problem does this PR solve?

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

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

Files changed (1) hide show
  1. api/db/services/dialog_service.py +1 -1
api/db/services/dialog_service.py CHANGED
@@ -168,7 +168,7 @@ def chat(dialog, messages, stream=True, **kwargs):
168
  gen_conf = dialog.llm_setting
169
 
170
  msg = [{"role": "system", "content": prompt_config["system"].format(**kwargs)}]
171
- msg.extend([{"role": m["role"], "content": m["content"]}
172
  for m in messages if m["role"] != "system"])
173
  used_token_count, msg = message_fit_in(msg, int(max_tokens * 0.97))
174
  assert len(msg) >= 2, f"message_fit_in has bug: {msg}"
 
168
  gen_conf = dialog.llm_setting
169
 
170
  msg = [{"role": "system", "content": prompt_config["system"].format(**kwargs)}]
171
+ msg.extend([{"role": m["role"], "content": re.sub(r"##\d+\$\$", "", m["content"])}
172
  for m in messages if m["role"] != "system"])
173
  used_token_count, msg = message_fit_in(msg, int(max_tokens * 0.97))
174
  assert len(msg) >= 2, f"message_fit_in has bug: {msg}"