Kevin Hu commited on
Commit
6229599
·
1 Parent(s): 391120b

let 'Generate' take user's input as parameter (#3086)

Browse files

### What problem does this PR solve?

#3085

### Type of change

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

Files changed (2) hide show
  1. agent/canvas.py +1 -1
  2. agent/component/generate.py +3 -0
agent/canvas.py CHANGED
@@ -260,7 +260,7 @@ class Canvas(ABC):
260
 
261
  def get_history(self, window_size):
262
  convs = []
263
- for role, obj in self.history[(window_size + 1) * -1:]:
264
  convs.append({"role": role, "content": (obj if role == "user" else
265
  '\n'.join([str(s) for s in pd.DataFrame(obj)['content']]))})
266
  return convs
 
260
 
261
  def get_history(self, window_size):
262
  convs = []
263
+ for role, obj in self.history[window_size * -1:]:
264
  convs.append({"role": role, "content": (obj if role == "user" else
265
  '\n'.join([str(s) for s in pd.DataFrame(obj)['content']]))})
266
  return convs
agent/component/generate.py CHANGED
@@ -105,6 +105,9 @@ class Generate(ComponentBase):
105
  input = (" - "+"\n - ".join([c for c in retrieval_res["content"] if isinstance(c, str)])) if "content" in retrieval_res else ""
106
  for para in self._param.parameters:
107
  cpn = self._canvas.get_component(para["component_id"])["obj"]
 
 
 
108
  _, out = cpn.output(allow_partial=False)
109
  if "content" not in out.columns:
110
  kwargs[para["key"]] = "Nothing"
 
105
  input = (" - "+"\n - ".join([c for c in retrieval_res["content"] if isinstance(c, str)])) if "content" in retrieval_res else ""
106
  for para in self._param.parameters:
107
  cpn = self._canvas.get_component(para["component_id"])["obj"]
108
+ if cpn.component_name.lower() == "answer":
109
+ kwargs[para["key"]] = self._canvas.get_history(1)[0]["content"]
110
+ continue
111
  _, out = cpn.output(allow_partial=False)
112
  if "content" not in out.columns:
113
  kwargs[para["key"]] = "Nothing"