Kevin Hu
commited on
Commit
·
a004a85
1
Parent(s):
a11ffc5
Component debugging funcionality. (#4012)
Browse files### What problem does this PR solve?
#3993
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- agent/component/categorize.py +4 -0
- agent/component/generate.py +6 -5
- agent/component/keyword.py +3 -0
- agent/component/relevant.py +2 -0
- agent/component/rewrite.py +1 -0
agent/component/categorize.py
CHANGED
@@ -87,4 +87,8 @@ class Categorize(Generate, ABC):
|
|
87 |
|
88 |
return Categorize.be_output(list(self._param.category_description.items())[-1][1]["to"])
|
89 |
|
|
|
|
|
|
|
|
|
90 |
|
|
|
87 |
|
88 |
return Categorize.be_output(list(self._param.category_description.items())[-1][1]["to"])
|
89 |
|
90 |
+
def debug(self, **kwargs):
|
91 |
+
df = self._run([], **kwargs)
|
92 |
+
cpn_id = df.iloc[0, 0]
|
93 |
+
return Categorize.be_output(self._canvas.get_compnent_name(cpn_id))
|
94 |
|
agent/component/generate.py
CHANGED
@@ -111,9 +111,9 @@ class Generate(ComponentBase):
|
|
111 |
|
112 |
def get_input_elements(self):
|
113 |
if self._param.parameters:
|
114 |
-
return [{"key": "user"}, *self._param.parameters]
|
115 |
|
116 |
-
return [{"key": "user"}]
|
117 |
|
118 |
def _run(self, history, **kwargs):
|
119 |
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
|
@@ -220,14 +220,15 @@ class Generate(ComponentBase):
|
|
220 |
|
221 |
self.set_output(Generate.be_output(res))
|
222 |
|
223 |
-
def debug(self,
|
224 |
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
|
225 |
prompt = self._param.prompt
|
226 |
|
227 |
for para in self._param.debug_inputs:
|
228 |
-
kwargs[para["key"]] = para
|
229 |
|
230 |
for n, v in kwargs.items():
|
231 |
prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt)
|
232 |
|
233 |
-
|
|
|
|
111 |
|
112 |
def get_input_elements(self):
|
113 |
if self._param.parameters:
|
114 |
+
return [{"key": "user", "name": "User"}, *self._param.parameters]
|
115 |
|
116 |
+
return [{"key": "user", "name": "User"}]
|
117 |
|
118 |
def _run(self, history, **kwargs):
|
119 |
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
|
|
|
220 |
|
221 |
self.set_output(Generate.be_output(res))
|
222 |
|
223 |
+
def debug(self, **kwargs):
|
224 |
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
|
225 |
prompt = self._param.prompt
|
226 |
|
227 |
for para in self._param.debug_inputs:
|
228 |
+
kwargs[para["key"]] = para.get("value", "")
|
229 |
|
230 |
for n, v in kwargs.items():
|
231 |
prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt)
|
232 |
|
233 |
+
ans = chat_mdl.chat(prompt, [{"role": "user", "content": kwargs.get("user", "")}], self._param.gen_conf())
|
234 |
+
return pd.DataFrame([ans])
|
agent/component/keyword.py
CHANGED
@@ -60,3 +60,6 @@ class KeywordExtract(Generate, ABC):
|
|
60 |
ans = re.sub(r".*keyword:", "", ans).strip()
|
61 |
logging.debug(f"ans: {ans}")
|
62 |
return KeywordExtract.be_output(ans)
|
|
|
|
|
|
|
|
60 |
ans = re.sub(r".*keyword:", "", ans).strip()
|
61 |
logging.debug(f"ans: {ans}")
|
62 |
return KeywordExtract.be_output(ans)
|
63 |
+
|
64 |
+
def debug(self, **kwargs):
|
65 |
+
return self._run([], **kwargs)
|
agent/component/relevant.py
CHANGED
@@ -78,4 +78,6 @@ class Relevant(Generate, ABC):
|
|
78 |
return Relevant.be_output(self._param.no)
|
79 |
assert False, f"Relevant component got: {ans}"
|
80 |
|
|
|
|
|
81 |
|
|
|
78 |
return Relevant.be_output(self._param.no)
|
79 |
assert False, f"Relevant component got: {ans}"
|
80 |
|
81 |
+
def debug(self, **kwargs):
|
82 |
+
return self._run([], **kwargs)
|
83 |
|
agent/component/rewrite.py
CHANGED
@@ -110,3 +110,4 @@ class RewriteQuestion(Generate, ABC):
|
|
110 |
return RewriteQuestion.be_output(ans)
|
111 |
|
112 |
|
|
|
|
110 |
return RewriteQuestion.be_output(ans)
|
111 |
|
112 |
|
113 |
+
|