Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix generate bug #2614

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/component/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def _run(self, history, **kwargs):
if "empty_response" in retrieval_res.columns and not "".join(retrieval_res["content"]):
res = {"content": "\n- ".join(retrieval_res["empty_response"]) if "\n- ".join(
retrieval_res["empty_response"]) else "Nothing found in knowledgebase!", "reference": []}
return Generate.be_output(res)
return pd.DataFrame([res])

ans = chat_mdl.chat(prompt, self._canvas.get_history(self._param.message_history_window_size),
self._param.gen_conf())
if self._param.cite and "content_ltks" in retrieval_res.columns and "vector" in retrieval_res.columns:
df = self.set_cite(retrieval_res, ans)
return pd.DataFrame(df)
res = self.set_cite(retrieval_res, ans)
return pd.DataFrame([res])

return Generate.be_output(ans)

Expand Down
33 changes: 7 additions & 26 deletions agent/component/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,15 @@ class Switch(ComponentBase, ABC):

def _run(self, history, **kwargs):
for cond in self._param.conditions:

if len(cond["items"]) == 1:
out = self._canvas.get_component(cond["items"][0]["cpn_id"])["obj"].output()[1]
cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
if self.process_operator(cpn_input, cond["items"][0]["operator"], cond["items"][0]["value"]):
return Switch.be_output(cond["to"])
continue

if cond["logical_operator"] == "and":
res = True
for item in cond["items"]:
out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1]
cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
if not self.process_operator(cpn_input, item["operator"], item["value"]):
res = False
break
if res:
return Switch.be_output(cond["to"])
continue

res = False
res = []
for item in cond["items"]:
out = self._canvas.get_component(item["cpn_id"])["obj"].output()[1]
cpn_input = "" if "content" not in out.columns else " ".join(out["content"])
if self.process_operator(cpn_input, item["operator"], item["value"]):
res = True
break
if res:
res.append(self.process_operator(cpn_input, item["operator"], item["value"]))
if cond["logical_operator"] != "and" and any(res):
return Switch.be_output(cond["to"])

if all(res):
return Switch.be_output(cond["to"])

return Switch.be_output(self._param.end_cpn_id)
Expand Down Expand Up @@ -122,4 +103,4 @@ def process_operator(self, input: str, operator: str, value: str) -> bool:
except Exception as e:
return True if input <= value else False

raise ValueError('Not supported operator' + operator)
raise ValueError('Not supported operator' + operator)