mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Support debug components. (#3994)
### What problem does this PR solve? #3993 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -111,9 +111,9 @@ class Generate(ComponentBase):
|
||||
|
||||
def get_input_elements(self):
|
||||
if self._param.parameters:
|
||||
return self._param.parameters
|
||||
return [{"key": "user"}, *self._param.parameters]
|
||||
|
||||
return [{"key": "input"}]
|
||||
return [{"key": "user"}]
|
||||
|
||||
def _run(self, history, **kwargs):
|
||||
chat_mdl = LLMBundle(self._canvas.get_tenant_id(), LLMType.CHAT, self._param.llm_id)
|
||||
@ -218,4 +218,16 @@ class Generate(ComponentBase):
|
||||
res = self.set_cite(retrieval_res, answer)
|
||||
yield res
|
||||
|
||||
self.set_output(res)
|
||||
self.set_output(Generate.be_output(res))
|
||||
|
||||
def debug(self, history, **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"]
|
||||
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user