-
I'm currently building a traditional chatbot private chatbot that allow user to interact with their csv file using chat. However, I was wondering if not only can we give the result of the query, but also the code generated and used to output that result so that the user understands what's under the hood? I knew that if we check the pandasai.log, we can check all the code generation, code execution, and the result. But the question is whether is it possible to use method/function to output the code used for the query? Sometimes it will give the idea for the user whether their prompt/query is accurate/self-explanatory enough for the model to interpret or translate that to python code. Any response or answer would be pretty much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @ramzyizza! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Yes, it is possible to show the generated code used for a query to the user without using the log. In the pandas-ai codebase, the Here's a relevant snippet of how this is implemented: conversation_message = await self.conversation_repository.add_conversation_message(
conversation_id=conversation_id,
query=chat_request.query,
response=response,
code_generated=agent.last_code_executed,
log_id=log.id
)
return ChatResponse(
response=response,
conversation_id=str(conversation_id),
message_id=str(conversation_message.id),
query=str(conversation_message.query)
) The |
Beta Was this translation helpful? Give feedback.
Hey @ramzyizza! 👋 I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer.
Yes, it is possible to show the generated code used for a query to the user without using the log. In the pandas-ai codebase, the
ChatController
class includes a methodchat
that handles chat interactions. After the agent processes the query, the generated code is stored inagent.last_code_executed
. This code can be included in the response to the user.Here's a relevant snippet of how this is implemented: