|
|
@ -4,23 +4,20 @@ from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union
|
|
|
|
from typing import Any, Dict, Iterable, List, Optional, Union
|
|
|
|
|
|
|
|
|
|
|
|
import aiohttp
|
|
|
|
import aiohttp
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
from aiohttp import ServerTimeoutError
|
|
|
|
from aiohttp import ServerTimeoutError
|
|
|
|
|
|
|
|
from azure.core.credentials import TokenCredential
|
|
|
|
|
|
|
|
from azure.core.exceptions import ClientAuthenticationError
|
|
|
|
from pydantic import BaseModel, Field, root_validator
|
|
|
|
from pydantic import BaseModel, Field, root_validator
|
|
|
|
from requests.exceptions import Timeout
|
|
|
|
from requests.exceptions import Timeout
|
|
|
|
|
|
|
|
|
|
|
|
from langchain.tools.powerbi.prompt import BAD_REQUEST_RESPONSE, UNAUTHORIZED_RESPONSE
|
|
|
|
from langchain.tools.powerbi.prompt import SCHEMA_ERROR_RESPONSE, UNAUTHORIZED_RESPONSE
|
|
|
|
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
|
|
|
from azure.core.exceptions import ClientAuthenticationError
|
|
|
|
|
|
|
|
from azure.identity import ChainedTokenCredential
|
|
|
|
|
|
|
|
from azure.identity._internal import InteractiveCredential
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL = os.getenv("POWERBI_BASE_URL", "https://api.powerbi.com/v1.0/myorg/datasets/")
|
|
|
|
BASE_URL = os.getenv("POWERBI_BASE_URL", "https://api.powerbi.com/v1.0/myorg/datasets/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -36,7 +33,7 @@ class PowerBIDataset(BaseModel):
|
|
|
|
dataset_id: str
|
|
|
|
dataset_id: str
|
|
|
|
table_names: List[str]
|
|
|
|
table_names: List[str]
|
|
|
|
group_id: Optional[str] = None
|
|
|
|
group_id: Optional[str] = None
|
|
|
|
credential: Optional[Union[ChainedTokenCredential, InteractiveCredential]] = None
|
|
|
|
credential: Optional[TokenCredential] = None
|
|
|
|
token: Optional[str] = None
|
|
|
|
token: Optional[str] = None
|
|
|
|
impersonated_user_name: Optional[str] = None
|
|
|
|
impersonated_user_name: Optional[str] = None
|
|
|
|
sample_rows_in_table_info: int = Field(default=1, gt=0, le=10)
|
|
|
|
sample_rows_in_table_info: int = Field(default=1, gt=0, le=10)
|
|
|
@ -144,7 +141,7 @@ class PowerBIDataset(BaseModel):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
|
|
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
|
|
|
if "bad request" in str(exc).lower():
|
|
|
|
if "bad request" in str(exc).lower():
|
|
|
|
return BAD_REQUEST_RESPONSE
|
|
|
|
return SCHEMA_ERROR_RESPONSE
|
|
|
|
if "unauthorized" in str(exc).lower():
|
|
|
|
if "unauthorized" in str(exc).lower():
|
|
|
|
return UNAUTHORIZED_RESPONSE
|
|
|
|
return UNAUTHORIZED_RESPONSE
|
|
|
|
return str(exc)
|
|
|
|
return str(exc)
|
|
|
@ -167,7 +164,7 @@ class PowerBIDataset(BaseModel):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
|
|
|
except Exception as exc: # pylint: disable=broad-exception-caught
|
|
|
|
if "bad request" in str(exc).lower():
|
|
|
|
if "bad request" in str(exc).lower():
|
|
|
|
return BAD_REQUEST_RESPONSE
|
|
|
|
return SCHEMA_ERROR_RESPONSE
|
|
|
|
if "unauthorized" in str(exc).lower():
|
|
|
|
if "unauthorized" in str(exc).lower():
|
|
|
|
return UNAUTHORIZED_RESPONSE
|
|
|
|
return UNAUTHORIZED_RESPONSE
|
|
|
|
return str(exc)
|
|
|
|
return str(exc)
|
|
|
|