Kevin Hu commited on
Commit
a57190d
·
1 Parent(s): 96bea9f

fix generate bug (#2614)

Browse files

### What problem does this PR solve?



### Type of change

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

agent/component/generate.py CHANGED
@@ -122,13 +122,13 @@ class Generate(ComponentBase):
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())
129
  if self._param.cite and "content_ltks" in retrieval_res.columns and "vector" in retrieval_res.columns:
130
- df = self.set_cite(retrieval_res, ans)
131
- return pd.DataFrame(df)
132
 
133
  return Generate.be_output(ans)
134
 
 
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 pd.DataFrame([res])
126
 
127
  ans = chat_mdl.chat(prompt, self._canvas.get_history(self._param.message_history_window_size),
128
  self._param.gen_conf())
129
  if self._param.cite and "content_ltks" in retrieval_res.columns and "vector" in retrieval_res.columns:
130
+ res = self.set_cite(retrieval_res, ans)
131
+ return pd.DataFrame([res])
132
 
133
  return Generate.be_output(ans)
134
 
agent/component/switch.py CHANGED
@@ -49,34 +49,15 @@ class Switch(ComponentBase, ABC):
49
 
50
  def _run(self, history, **kwargs):
51
  for cond in self._param.conditions:
52
-
53
- if len(cond["items"]) == 1:
54
- out = self._canvas.get_component(cond["items"][0]["cpn_id"])["obj"].output()[1]
55
- cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
56
- if self.process_operator(cpn_input, cond["items"][0]["operator"], cond["items"][0]["value"]):
57
- return Switch.be_output(cond["to"])
58
- continue
59
-
60
- if cond["logical_operator"] == "and":
61
- res = True
62
- for item in cond["items"]:
63
- out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1]
64
- cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
65
- if not self.process_operator(cpn_input, item["operator"], item["value"]):
66
- res = False
67
- break
68
- if res:
69
- return Switch.be_output(cond["to"])
70
- continue
71
-
72
- res = False
73
  for item in cond["items"]:
74
  out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1]
75
  cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
76
- if self.process_operator(cpn_input, item["operator"], item["value"]):
77
- res = True
78
- break
79
- if res:
 
80
  return Switch.be_output(cond["to"])
81
 
82
  return Switch.be_output(self._param.end_cpn_id)
@@ -122,4 +103,4 @@ class Switch(ComponentBase, ABC):
122
  except Exception as e:
123
  return True if input <= value else False
124
 
125
- raise ValueError('Not supported operator' + operator)
 
49
 
50
  def _run(self, history, **kwargs):
51
  for cond in self._param.conditions:
52
+ res = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  for item in cond["items"]:
54
  out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1]
55
  cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
56
+ res.append(self.process_operator(cpn_input, item["operator"], item["value"]))
57
+ if cond["logical_operator"] != "and" and any(res):
58
+ return Switch.be_output(cond["to"])
59
+
60
+ if all(res):
61
  return Switch.be_output(cond["to"])
62
 
63
  return Switch.be_output(self._param.end_cpn_id)
 
103
  except Exception as e:
104
  return True if input <= value else False
105
 
106
+ raise ValueError('Not supported operator' + operator)