Skip to content

Commit

Permalink
Component debugging funcionality. (infiniflow#4012)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

infiniflow#3993
### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
KevinHuSh authored and isthaison committed Dec 13, 2024
1 parent 075bc18 commit 8f54b62
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions agent/component/categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ def _run(self, history, **kwargs):

return Categorize.be_output(list(self._param.category_description.items())[-1][1]["to"])

def debug(self, **kwargs):
df = self._run([], **kwargs)
cpn_id = df.iloc[0, 0]
return Categorize.be_output(self._canvas.get_compnent_name(cpn_id))

11 changes: 6 additions & 5 deletions agent/component/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def set_cite(self, retrieval_res, answer):

def get_input_elements(self):
if self._param.parameters:
return [{"key": "user"}, *self._param.parameters]
return [{"key": "user", "name": "User"}, *self._param.parameters]

return [{"key": "user"}]
return [{"key": "user", "name": "User"}]

def _run(self, history, **kwargs):
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
Expand Down Expand Up @@ -220,14 +220,15 @@ def stream_output(self, chat_mdl, prompt, retrieval_res):

self.set_output(Generate.be_output(res))

def debug(self, history, **kwargs):
def debug(self, **kwargs):
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
prompt = self._param.prompt

for para in self._param.debug_inputs:
kwargs[para["key"]] = para["value"]
kwargs[para["key"]] = para.get("value", "")

for n, v in kwargs.items():
prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt)

return chat_mdl.chat(prompt, [{"role": "user", "content": kwargs.get("user", "")}], self._param.gen_conf())
ans = chat_mdl.chat(prompt, [{"role": "user", "content": kwargs.get("user", "")}], self._param.gen_conf())
return pd.DataFrame([ans])
3 changes: 3 additions & 0 deletions agent/component/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ def _run(self, history, **kwargs):
ans = re.sub(r".*keyword:", "", ans).strip()
logging.debug(f"ans: {ans}")
return KeywordExtract.be_output(ans)

def debug(self, **kwargs):
return self._run([], **kwargs)
2 changes: 2 additions & 0 deletions agent/component/relevant.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ def _run(self, history, **kwargs):
return Relevant.be_output(self._param.no)
assert False, f"Relevant component got: {ans}"

def debug(self, **kwargs):
return self._run([], **kwargs)

1 change: 1 addition & 0 deletions agent/component/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ def _run(self, history, **kwargs):
return RewriteQuestion.be_output(ans)



0 comments on commit 8f54b62

Please sign in to comment.