Kevin Hu commited on
Commit
f2439de
·
1 Parent(s): e98cd71

New: a new interpretor based on Andrew Ng theory. (#3532)

Browse files

### What problem does this PR solve?

### Type of change

- [x] New Feature (non-breaking change which adds functionality)

agent/canvas.py CHANGED
@@ -199,7 +199,7 @@ class Canvas(ABC):
199
  if any([cc not in self.path[-1] for cc in cpids]):
200
  if c not in waiting: waiting.append(c)
201
  continue
202
- yield "'{}' is running...".format(self.get_compnent_name(c))
203
  ans = cpn.run(self.history, **kwargs)
204
  self.path[-1].append(c)
205
  ran += 1
@@ -224,28 +224,16 @@ class Canvas(ABC):
224
  for m in prepare2run([switch_out]):
225
  yield {"content": m, "running_status": True}
226
  except Exception as e:
227
- for p in [c for p in self.path for c in p][::-1]:
228
- if p.lower().find("answer") >= 0:
229
- self.get_component(p)["obj"].set_exception(e)
230
- for m in prepare2run([p]):
231
- yield {"content": m, "running_status": True}
232
- break
233
  logging.exception("Canvas.run got exception")
234
- break
235
  continue
236
 
237
  try:
238
  for m in prepare2run(cpn["downstream"]):
239
  yield {"content": m, "running_status": True}
240
  except Exception as e:
241
- for p in [c for p in self.path for c in p][::-1]:
242
- if p.lower().find("answer") >= 0:
243
- self.get_component(p)["obj"].set_exception(e)
244
- for m in prepare2run([p]):
245
- yield {"content": m, "running_status": True}
246
- break
247
  logging.exception("Canvas.run got exception")
248
- break
249
 
250
  if ran >= len(self.path[-1]) and waiting:
251
  without_dependent_checking = waiting
 
199
  if any([cc not in self.path[-1] for cc in cpids]):
200
  if c not in waiting: waiting.append(c)
201
  continue
202
+ yield "*'{}'* is running...🕞".format(self.get_compnent_name(c))
203
  ans = cpn.run(self.history, **kwargs)
204
  self.path[-1].append(c)
205
  ran += 1
 
224
  for m in prepare2run([switch_out]):
225
  yield {"content": m, "running_status": True}
226
  except Exception as e:
227
+ yield {"content": "*Exception*: {}".format(e), "running_status": True}
 
 
 
 
 
228
  logging.exception("Canvas.run got exception")
 
229
  continue
230
 
231
  try:
232
  for m in prepare2run(cpn["downstream"]):
233
  yield {"content": m, "running_status": True}
234
  except Exception as e:
235
+ yield {"content": "*Exception*: {}".format(e), "running_status": True}
 
 
 
 
 
236
  logging.exception("Canvas.run got exception")
 
237
 
238
  if ran >= len(self.path[-1]) and waiting:
239
  without_dependent_checking = waiting
agent/component/base.py CHANGED
@@ -454,7 +454,7 @@ class ComponentBase(ABC):
454
  outs = []
455
  for q in self._param.query:
456
  if q["component_id"]:
457
- if q["component_id"].split("@")[0].lower().find("begin") > 0:
458
  cpn_id, key = q["component_id"].split("@")
459
  for p in self._canvas.get_component(cpn_id)["obj"]._param.query:
460
  if p["key"] == key:
 
454
  outs = []
455
  for q in self._param.query:
456
  if q["component_id"]:
457
+ if q["component_id"].split("@")[0].lower().find("begin") >= 0:
458
  cpn_id, key = q["component_id"].split("@")
459
  for p in self._canvas.get_component(cpn_id)["obj"]._param.query:
460
  if p["key"] == key:
agent/component/generate.py CHANGED
@@ -124,11 +124,16 @@ class Generate(ComponentBase):
124
 
125
  cpn = self._canvas.get_component(component_id)["obj"]
126
  if cpn.component_name.lower() == "answer":
127
- kwargs[para["key"]] = self._canvas.get_history(1)[0]["content"]
 
 
 
 
 
128
  continue
129
  _, out = cpn.output(allow_partial=False)
130
  if "content" not in out.columns:
131
- kwargs[para["key"]] = "Nothing"
132
  else:
133
  if cpn.component_name.lower() == "retrieval":
134
  retrieval_res.append(out)
 
124
 
125
  cpn = self._canvas.get_component(component_id)["obj"]
126
  if cpn.component_name.lower() == "answer":
127
+ hist = self._canvas.get_history(1)
128
+ if hist:
129
+ hist = hist[0]["content"]
130
+ else:
131
+ hist = ""
132
+ kwargs[para["key"]] = hist
133
  continue
134
  _, out = cpn.output(allow_partial=False)
135
  if "content" not in out.columns:
136
+ kwargs[para["key"]] = ""
137
  else:
138
  if cpn.component_name.lower() == "retrieval":
139
  retrieval_res.append(out)
agent/templates/interpreter.json CHANGED
The diff for this file is too large to render. See raw diff
 
api/apps/canvas_app.py CHANGED
@@ -134,6 +134,8 @@ def run():
134
  cvs.dsl = json.loads(str(canvas))
135
  UserCanvasService.update_by_id(req["id"], cvs.to_dict())
136
  except Exception as e:
 
 
137
  traceback.print_exc()
138
  yield "data:" + json.dumps({"code": 500, "message": str(e),
139
  "data": {"answer": "**ERROR**: " + str(e), "reference": []}},
 
134
  cvs.dsl = json.loads(str(canvas))
135
  UserCanvasService.update_by_id(req["id"], cvs.to_dict())
136
  except Exception as e:
137
+ cvs.dsl = json.loads(str(canvas))
138
+ UserCanvasService.update_by_id(req["id"], cvs.to_dict())
139
  traceback.print_exc()
140
  yield "data:" + json.dumps({"code": 500, "message": str(e),
141
  "data": {"answer": "**ERROR**: " + str(e), "reference": []}},
api/apps/tenant_app.py CHANGED
@@ -111,12 +111,6 @@ def tenant_list():
111
  @manager.route("/agree/<tenant_id>", methods=["PUT"])
112
  @login_required
113
  def agree(tenant_id):
114
- if current_user.id != tenant_id:
115
- return get_json_result(
116
- data=False,
117
- message='No authorization.',
118
- code=settings.RetCode.AUTHENTICATION_ERROR)
119
-
120
  try:
121
  UserTenantService.filter_update([UserTenant.tenant_id == tenant_id, UserTenant.user_id == current_user.id], {"role": UserTenantRole.NORMAL})
122
  return get_json_result(data=True)
 
111
  @manager.route("/agree/<tenant_id>", methods=["PUT"])
112
  @login_required
113
  def agree(tenant_id):
 
 
 
 
 
 
114
  try:
115
  UserTenantService.filter_update([UserTenant.tenant_id == tenant_id, UserTenant.user_id == current_user.id], {"role": UserTenantRole.NORMAL})
116
  return get_json_result(data=True)