How to log out the prompts generate by each component of agent? #6926
-
I want debug each component of agent generate what prompt. It can help us adjust the prompt templetes. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @jamerainbow! I'm Dosu, a friendly bot here to help you solve bugs, answer questions, and assist you in becoming a contributor. I'll be here while you wait for a human maintainer. How can I assist you today? To log the prompts generated by each component of an agent for debugging purposes, you can modify the Here's an example of how you might modify the 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.get("value", "")
for n, v in kwargs.items():
prompt = re.sub(r"\{%s\}" % re.escape(n), str(v).replace("\\", " "), prompt)
# Log the generated prompt for debugging
print(f"Generated Prompt: {prompt}")
u = kwargs.get("user")
ans = chat_mdl.chat(prompt, [{"role": "user", "content": u if u else "Output: "}], self._param.gen_conf())
return pd.DataFrame([ans]) By adding To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Hello @jamerainbow! I'm Dosu, a friendly bot here to help you solve bugs, answer questions, and assist you in becoming a contributor. I'll be here while you wait for a human maintainer. How can I assist you today?
To log the prompts generated by each component of an agent for debugging purposes, you can modify the
debug
method in theGenerate
class. This method constructs the prompt using the provided parameters and then uses thechat
method of theLLMBundle
to generate the response. You can add logging functionality to capture the prompts.Here's an example of how you might modify the
debug
method to log the prompts: