mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 11:31:58 +00:00
PowerBI: catch outdated token (#6634)
This adds just a small tweak to catch the error that says the token is expired rather then retrying.
This commit is contained in:
parent
b1de927f1b
commit
48381f1f78
@ -96,6 +96,11 @@ class QueryPowerBITool(BaseTool):
|
|||||||
logger.info("Query: %s", query)
|
logger.info("Query: %s", query)
|
||||||
pbi_result = self.powerbi.run(command=query)
|
pbi_result = self.powerbi.run(command=query)
|
||||||
result, error = self._parse_output(pbi_result)
|
result, error = self._parse_output(pbi_result)
|
||||||
|
if error is not None and "TokenExpired" in error:
|
||||||
|
self.session_cache[
|
||||||
|
tool_input
|
||||||
|
] = "Authentication token expired or invalid, please try reauthenticate."
|
||||||
|
return self.session_cache[tool_input]
|
||||||
|
|
||||||
iterations = kwargs.get("iterations", 0)
|
iterations = kwargs.get("iterations", 0)
|
||||||
if error and iterations < self.max_iterations:
|
if error and iterations < self.max_iterations:
|
||||||
@ -140,6 +145,11 @@ class QueryPowerBITool(BaseTool):
|
|||||||
logger.info("Query: %s", query)
|
logger.info("Query: %s", query)
|
||||||
pbi_result = await self.powerbi.arun(command=query)
|
pbi_result = await self.powerbi.arun(command=query)
|
||||||
result, error = self._parse_output(pbi_result)
|
result, error = self._parse_output(pbi_result)
|
||||||
|
if error is not None and "TokenExpired" in error:
|
||||||
|
self.session_cache[
|
||||||
|
tool_input
|
||||||
|
] = "Authentication token expired or invalid, please try reauthenticate."
|
||||||
|
return self.session_cache[tool_input]
|
||||||
|
|
||||||
iterations = kwargs.get("iterations", 0)
|
iterations = kwargs.get("iterations", 0)
|
||||||
if error and iterations < self.max_iterations:
|
if error and iterations < self.max_iterations:
|
||||||
|
@ -226,7 +226,7 @@ class PowerBIDataset(BaseModel):
|
|||||||
json=self._create_json_content(command),
|
json=self._create_json_content(command),
|
||||||
timeout=10,
|
timeout=10,
|
||||||
) as response:
|
) as response:
|
||||||
response_json = await response.json()
|
response_json = await response.json(content_type=response.content_type)
|
||||||
return response_json
|
return response_json
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(
|
async with session.post(
|
||||||
@ -235,7 +235,7 @@ class PowerBIDataset(BaseModel):
|
|||||||
json=self._create_json_content(command),
|
json=self._create_json_content(command),
|
||||||
timeout=10,
|
timeout=10,
|
||||||
) as response:
|
) as response:
|
||||||
response_json = await response.json()
|
response_json = await response.json(content_type=response.content_type)
|
||||||
return response_json
|
return response_json
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user