Skip to content

Commit

Permalink
New: a new interpretor based on Andrew Ng theory. (infiniflow#3532)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
KevinHuSh authored Nov 20, 2024
1 parent 58ce093 commit 5309ab2
Show file tree
Hide file tree
Showing 6 changed files with 603 additions and 274 deletions.
18 changes: 3 additions & 15 deletions agent/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def prepare2run(cpns):
if any([cc not in self.path[-1] for cc in cpids]):
if c not in waiting: waiting.append(c)
continue
yield "'{}' is running...".format(self.get_compnent_name(c))
yield "*'{}'* is running...🕞".format(self.get_compnent_name(c))
ans = cpn.run(self.history, **kwargs)
self.path[-1].append(c)
ran += 1
Expand All @@ -224,28 +224,16 @@ def prepare2run(cpns):
for m in prepare2run([switch_out]):
yield {"content": m, "running_status": True}
except Exception as e:
for p in [c for p in self.path for c in p][::-1]:
if p.lower().find("answer") >= 0:
self.get_component(p)["obj"].set_exception(e)
for m in prepare2run([p]):
yield {"content": m, "running_status": True}
break
yield {"content": "*Exception*: {}".format(e), "running_status": True}
logging.exception("Canvas.run got exception")
break
continue

try:
for m in prepare2run(cpn["downstream"]):
yield {"content": m, "running_status": True}
except Exception as e:
for p in [c for p in self.path for c in p][::-1]:
if p.lower().find("answer") >= 0:
self.get_component(p)["obj"].set_exception(e)
for m in prepare2run([p]):
yield {"content": m, "running_status": True}
break
yield {"content": "*Exception*: {}".format(e), "running_status": True}
logging.exception("Canvas.run got exception")
break

if ran >= len(self.path[-1]) and waiting:
without_dependent_checking = waiting
Expand Down
2 changes: 1 addition & 1 deletion agent/component/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def get_input(self):
outs = []
for q in self._param.query:
if q["component_id"]:
if q["component_id"].split("@")[0].lower().find("begin") > 0:
if q["component_id"].split("@")[0].lower().find("begin") >= 0:
cpn_id, key = q["component_id"].split("@")
for p in self._canvas.get_component(cpn_id)["obj"]._param.query:
if p["key"] == key:
Expand Down
9 changes: 7 additions & 2 deletions agent/component/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ def _run(self, history, **kwargs):

cpn = self._canvas.get_component(component_id)["obj"]
if cpn.component_name.lower() == "answer":
kwargs[para["key"]] = self._canvas.get_history(1)[0]["content"]
hist = self._canvas.get_history(1)
if hist:
hist = hist[0]["content"]
else:
hist = ""
kwargs[para["key"]] = hist
continue
_, out = cpn.output(allow_partial=False)
if "content" not in out.columns:
kwargs[para["key"]] = "Nothing"
kwargs[para["key"]] = ""
else:
if cpn.component_name.lower() == "retrieval":
retrieval_res.append(out)
Expand Down
Loading

0 comments on commit 5309ab2

Please sign in to comment.