diff --git a/agent/component/generate.py b/agent/component/generate.py index b9ed75c38..82963ea8e 100644 --- a/agent/component/generate.py +++ b/agent/component/generate.py @@ -216,6 +216,8 @@ class Generate(ComponentBase): return msg = self._canvas.get_history(self._param.message_history_window_size) + if msg and msg[0]['role'] == 'assistant': + msg.pop(0) if len(msg) < 1: msg.append({"role": "user", "content": "Output: "}) _, msg = message_fit_in([{"role": "system", "content": prompt}, *msg], int(chat_mdl.max_length * 0.97)) diff --git a/agent/component/retrieval.py b/agent/component/retrieval.py index 50c6c7963..6abfb784c 100644 --- a/agent/component/retrieval.py +++ b/agent/component/retrieval.py @@ -53,7 +53,9 @@ class Retrieval(ComponentBase, ABC): def _run(self, history, **kwargs): query = self.get_input() query = str(query["content"][0]) if "content" in query else "" - + lines = query.split('\n') + user_queries = [line.split("USER:", 1)[1] for line in lines if line.startswith("USER:")] + query = user_queries[-1] if user_queries else "" kbs = KnowledgebaseService.get_by_ids(self._param.kb_ids) if not kbs: return Retrieval.be_output("")