H commited on
Commit
f89901e
·
1 Parent(s): 99e5e05

fix mutiple retrieval component content (#1997)

Browse files

### What problem does this PR solve?

### Type of change

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

agent/component/base.py CHANGED
@@ -448,6 +448,8 @@ class ComponentBase(ABC):
448
  if self.component_name.lower() == "generate" and self.get_component_name(u) == "retrieval":
449
  o = self._canvas.get_component(u)["obj"].output(allow_partial=False)[1]
450
  if o is not None:
 
 
451
  upstream_outs.append(o)
452
  continue
453
  if u not in self._canvas.get_component(self._id)["upstream"]: continue
 
448
  if self.component_name.lower() == "generate" and self.get_component_name(u) == "retrieval":
449
  o = self._canvas.get_component(u)["obj"].output(allow_partial=False)[1]
450
  if o is not None:
451
+ if not "".join(o["content"]):
452
+ continue
453
  upstream_outs.append(o)
454
  continue
455
  if u not in self._canvas.get_component(self._id)["upstream"]: continue
agent/component/generate.py CHANGED
@@ -130,8 +130,8 @@ class Generate(ComponentBase):
130
 
131
  def stream_output(self, chat_mdl, prompt, retrieval_res):
132
  res = None
133
- if "empty_response" in retrieval_res.columns and "\n- ".join(retrieval_res["content"]):
134
- res = {"content": "\n- ".join(retrieval_res["content"]), "reference": []}
135
  yield res
136
  self.set_output(res)
137
  return
 
130
 
131
  def stream_output(self, chat_mdl, prompt, retrieval_res):
132
  res = None
133
+ if "empty_response" in retrieval_res.columns and not "\n- ".join(retrieval_res["content"]):
134
+ res = {"content": "\n- ".join(retrieval_res["empty_response"]), "reference": []}
135
  yield res
136
  self.set_output(res)
137
  return
agent/component/retrieval.py CHANGED
@@ -75,8 +75,8 @@ class Retrieval(ComponentBase, ABC):
75
  aggs=False, rerank_mdl=rerank_mdl)
76
 
77
  if not kbinfos["chunks"]:
78
- df = Retrieval.be_output(self._param.empty_response)
79
- df["empty_response"] = True
80
  return df
81
 
82
  df = pd.DataFrame(kbinfos["chunks"])
 
75
  aggs=False, rerank_mdl=rerank_mdl)
76
 
77
  if not kbinfos["chunks"]:
78
+ df = Retrieval.be_output("")
79
+ df["empty_response"] = self._param.empty_response
80
  return df
81
 
82
  df = pd.DataFrame(kbinfos["chunks"])