H commited on
Commit
fc6e68a
·
1 Parent(s): 16f8eca

Fix mutiple retrieval component content (#2006)

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,8 +448,6 @@ 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
- 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
 
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
agent/component/generate.py CHANGED
@@ -66,6 +66,8 @@ class Generate(ComponentBase):
66
  return cpnts
67
 
68
  def set_cite(self, retrieval_res, answer):
 
 
69
  answer, idx = retrievaler.insert_citations(answer, [ck["content_ltks"] for _, ck in retrieval_res.iterrows()],
70
  [ck["vector"] for _, ck in retrieval_res.iterrows()],
71
  LLMBundle(self._canvas.get_tenant_id(), LLMType.EMBEDDING,
@@ -117,8 +119,10 @@ class Generate(ComponentBase):
117
  "obj"].component_name.lower() == "answer":
118
  return partial(self.stream_output, chat_mdl, prompt, retrieval_res)
119
 
120
- if "empty_response" in retrieval_res.columns:
121
- return Generate.be_output(input)
 
 
122
 
123
  ans = chat_mdl.chat(prompt, self._canvas.get_history(self._param.message_history_window_size),
124
  self._param.gen_conf())
@@ -130,8 +134,9 @@ 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 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
 
66
  return cpnts
67
 
68
  def set_cite(self, retrieval_res, answer):
69
+ retrieval_res.dropna(subset=["vector", "content_ltks"], inplace=True)
70
+ retrieval_res["empty_response"].fillna("", inplace=True)
71
  answer, idx = retrievaler.insert_citations(answer, [ck["content_ltks"] for _, ck in retrieval_res.iterrows()],
72
  [ck["vector"] for _, ck in retrieval_res.iterrows()],
73
  LLMBundle(self._canvas.get_tenant_id(), LLMType.EMBEDDING,
 
119
  "obj"].component_name.lower() == "answer":
120
  return partial(self.stream_output, chat_mdl, prompt, retrieval_res)
121
 
122
+ if "empty_response" in retrieval_res.columns and not "".join(retrieval_res["content"]):
123
+ res = {"content": "\n- ".join(retrieval_res["empty_response"]) if "\n- ".join(
124
+ retrieval_res["empty_response"]) else "Nothing found in knowledgebase!", "reference": []}
125
+ return Generate.be_output(res)
126
 
127
  ans = chat_mdl.chat(prompt, self._canvas.get_history(self._param.message_history_window_size),
128
  self._param.gen_conf())
 
134
 
135
  def stream_output(self, chat_mdl, prompt, retrieval_res):
136
  res = None
137
+ if "empty_response" in retrieval_res.columns and not "".join(retrieval_res["content"]):
138
+ res = {"content": "\n- ".join(retrieval_res["empty_response"]) if "\n- ".join(
139
+ retrieval_res["empty_response"]) else "Nothing found in knowledgebase!", "reference": []}
140
  yield res
141
  self.set_output(res)
142
  return