From 9065fb1050723b7ecf2384b710ddc2cc07855051 Mon Sep 17 00:00:00 2001 From: H <43509927+guoyuhao2330@users.noreply.github.com> Date: Mon, 19 Aug 2024 15:01:21 +0800 Subject: [PATCH] fix mutiple retrieval component content (#1997) ### What problem does this PR solve? ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/component/base.py | 2 ++ agent/component/generate.py | 4 ++-- agent/component/retrieval.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/agent/component/base.py b/agent/component/base.py index 103325016..88c85c3fc 100644 --- a/agent/component/base.py +++ b/agent/component/base.py @@ -448,6 +448,8 @@ class ComponentBase(ABC): if self.component_name.lower() == "generate" and self.get_component_name(u) == "retrieval": o = self._canvas.get_component(u)["obj"].output(allow_partial=False)[1] if o is not None: + if not "".join(o["content"]): + continue upstream_outs.append(o) continue if u not in self._canvas.get_component(self._id)["upstream"]: continue diff --git a/agent/component/generate.py b/agent/component/generate.py index c3f50f4de..252526522 100644 --- a/agent/component/generate.py +++ b/agent/component/generate.py @@ -130,8 +130,8 @@ class Generate(ComponentBase): def stream_output(self, chat_mdl, prompt, retrieval_res): res = None - if "empty_response" in retrieval_res.columns and "\n- ".join(retrieval_res["content"]): - res = {"content": "\n- ".join(retrieval_res["content"]), "reference": []} + if "empty_response" in retrieval_res.columns and not "\n- ".join(retrieval_res["content"]): + res = {"content": "\n- ".join(retrieval_res["empty_response"]), "reference": []} yield res self.set_output(res) return diff --git a/agent/component/retrieval.py b/agent/component/retrieval.py index 84893d185..d49ecaa8b 100644 --- a/agent/component/retrieval.py +++ b/agent/component/retrieval.py @@ -75,8 +75,8 @@ class Retrieval(ComponentBase, ABC): aggs=False, rerank_mdl=rerank_mdl) if not kbinfos["chunks"]: - df = Retrieval.be_output(self._param.empty_response) - df["empty_response"] = True + df = Retrieval.be_output("") + df["empty_response"] = self._param.empty_response return df df = pd.DataFrame(kbinfos["chunks"])