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:
Kevin Hu
2024-12-11 19:23:59 +08:00
committed by GitHub
parent f61c276f74
commit 6d19294ddc
8 changed files with 63 additions and 15 deletions

View File

@ -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())