From 76fcd96dae48d13e98f049f302308da115ea4c07 Mon Sep 17 00:00:00 2001 From: Eduard van Valkenburg Date: Thu, 8 Jun 2023 04:19:21 +0200 Subject: [PATCH] Add logging in PBI tool (#5841) Add some logging into the powerbi tool so that you can see the queries being sent to PBI and attempts to correct them. Fixes # (issue) #### Before submitting #### Who can review? Tag maintainers/contributors who might be interested: @vowelparrot --- langchain/tools/powerbi/tool.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/langchain/tools/powerbi/tool.py b/langchain/tools/powerbi/tool.py index d84fe91e..2714e57e 100644 --- a/langchain/tools/powerbi/tool.py +++ b/langchain/tools/powerbi/tool.py @@ -1,4 +1,5 @@ """Tools for interacting with a Power BI dataset.""" +import logging from typing import Any, Dict, Optional, Tuple from pydantic import Field, validator @@ -17,6 +18,8 @@ from langchain.tools.powerbi.prompt import ( ) from langchain.utilities.powerbi import PowerBIDataset, json_to_md +logger = logging.getLogger(__name__) + class QueryPowerBITool(BaseTool): """Tool for querying a Power BI Dataset.""" @@ -73,9 +76,11 @@ class QueryPowerBITool(BaseTool): ) -> str: """Execute the query, return the results or an error message.""" if cache := self._check_cache(tool_input): + logger.debug("Found cached result for %s: %s", tool_input, cache) return cache try: + logger.info("Running PBI Query Tool with input: %s", tool_input) query = self.llm_chain.predict( tool_input=tool_input, tables=self.powerbi.get_table_names(), @@ -88,6 +93,7 @@ class QueryPowerBITool(BaseTool): if query == "I cannot answer this": self.session_cache[tool_input] = query return self.session_cache[tool_input] + logger.info("Query: %s", query) pbi_result = self.powerbi.run(command=query) result, error = self._parse_output(pbi_result) @@ -114,8 +120,10 @@ class QueryPowerBITool(BaseTool): ) -> str: """Execute the query, return the results or an error message.""" if cache := self._check_cache(tool_input): + logger.debug("Found cached result for %s: %s", tool_input, cache) return cache try: + logger.info("Running PBI Query Tool with input: %s", tool_input) query = await self.llm_chain.apredict( tool_input=tool_input, tables=self.powerbi.get_table_names(), @@ -129,6 +137,7 @@ class QueryPowerBITool(BaseTool): if query == "I cannot answer this": self.session_cache[tool_input] = query return self.session_cache[tool_input] + logger.info("Query: %s", query) pbi_result = await self.powerbi.arun(command=query) result, error = self._parse_output(pbi_result)