mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 15:59:01 +08:00
Component debugging funcionality. (#4012)
### What problem does this PR solve? #3993 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
275b5d14f2
commit
7559bbd46d
@ -87,4 +87,8 @@ class Categorize(Generate, ABC):
|
||||
|
||||
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))
|
||||
|
||||
|
@ -111,9 +111,9 @@ class Generate(ComponentBase):
|
||||
|
||||
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)
|
||||
@ -220,14 +220,15 @@ class Generate(ComponentBase):
|
||||
|
||||
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])
|
||||
|
@ -60,3 +60,6 @@ class KeywordExtract(Generate, ABC):
|
||||
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)
|
@ -78,4 +78,6 @@ class Relevant(Generate, ABC):
|
||||
return Relevant.be_output(self._param.no)
|
||||
assert False, f"Relevant component got: {ans}"
|
||||
|
||||
def debug(self, **kwargs):
|
||||
return self._run([], **kwargs)
|
||||
|
||||
|
@ -110,3 +110,4 @@ class RewriteQuestion(Generate, ABC):
|
||||
return RewriteQuestion.be_output(ans)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user