langchain
langchain copied to clipboard
Power BI Dataset Agent Issue
System Info
We are using the below Power BI Agent guide to try to connect to Power BI dashboard.
We are able to connect to OpenAI API but facing issues with the below line of code.
powerbi=PowerBIDataset(dataset_id="<dataset_id>", table_names=['table1', 'table2'], credential=DefaultAzureCredential())
Error:
ConfigError: field "credential" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs().
We tried searching to solve the issues we no luck so far. Is there any configuration we are missing? Can you share more details, is there any specific configuration or access required on power BI side?
thanks in advance...
Who can help?
No response
Information
- [X] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [ ] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
Same steps mentioned your official PowerBI Dataset Agent documentation
Expected behavior
We should be able to connect to power BI
Hi,
Received response from @xiangyan99 in forum azure-sdk-for-python that bug in langchain: https://github.com/hwchase17/langchain/blob/master/langchain/utilities/powerbi.py
TokenCredential is only defined in TYPE_CHECKING.
Having the same issue.
in utilities>powerbi.py if we import TokenCredential without checking TYPE_CHECKING flag the issue is getting resolved.
Request the team to look into it @hwchase17
Also having this issue - not sure if there is/should be a separate integ test for the powerbi tool
@satishgunjal I opened a PR for this that should resolve this issue. In addition to the TYPE_CHECKING issue, the notebook code should be using ChatOpenAI
instead of AzureOpenAI
, I.e
fast_llm = ChatOpenAI(temperature=0.5, max_tokens=1000, model_name="gpt-3.5-turbo", verbose=True)
smart_llm = ChatOpenAI(temperature=0, max_tokens=100, model_name="gpt-4", verbose=True)
Hi ! Have you find a way to make the agent work ? we have the same error here
ConfigError: field "credential" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs(). If we use powerbidataset.update.forward.refs() we then have this error : NameError: name 'TokenCredential' is not defined
It seems like the issue was resolved by i still have it on my side. Someone knows how to bypass that ?
It looks like parts of this change were reverted back in an update #5062
if TYPE_CHECKING: from azure.core.credentials import TokenCredential
@hwchase17, is there a way to handle the import in a different way? My initial fix in #4983 used a try-except instead, since azure is not a required dependency.
It looks like the type checking condition breaks the powerbi tool with the error mentioned by @JRlis
Hi! We are still facing this issue. Do we have any updates/fixes/bypasses about it?
Hi, this issue is still happening:
line 22, in <module>
powerbi=PowerBIDataset(
File "pydantic\main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic\main.py", line 1076, in pydantic.main.validate_model
File "pydantic\fields.py", line 860, in pydantic.fields.ModelField.validate
pydantic.errors.ConfigError: field "credential" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs().
Here is the code to solve this issue
!pip install powerbiclient ################################################ #Using powerbiclient to get token instead of DefaultAzureCredential ###############################################
from powerbiclient.authentication import DeviceCodeLoginAuthentication auth = DeviceCodeLoginAuthentication() token = auth.get_access_token()
llm = AzureOpenAI(temperature=0, deployment_name="gpt-35-turbo", model_name="gpt-35-turbo",) toolkit = PowerBIToolkit( powerbi=PowerBIDataset( dataset_id="your_dataset_id", table_names=["HR Employees", "Sales Orders"], token= token, #<--------------Using token instead credential ), llm=llm, output_token_limit = 1024 )
agent_executor = create_pbi_agent( llm=llm, toolkit=toolkit, verbose=True )
agent_executor.run('How many rows are in HR Employees')
Here is the code to solve this issue
!pip install powerbiclient ################################################ #Using powerbiclient to get token instead of DefaultAzureCredential ###############################################
from powerbiclient.authentication import DeviceCodeLoginAuthentication auth = DeviceCodeLoginAuthentication() token = auth.get_access_token()
llm = AzureOpenAI(temperature=0, deployment_name="gpt-35-turbo", model_name="gpt-35-turbo",) toolkit = PowerBIToolkit( powerbi=PowerBIDataset( dataset_id="your_dataset_id", table_names=["HR Employees", "Sales Orders"], token= token, #<--------------Using token instead credential ), llm=llm, output_token_limit = 1024 )
agent_executor = create_pbi_agent( llm=llm, toolkit=toolkit, verbose=True )
agent_executor.run('How many rows are in HR Employees')
Thanks a lot, it works this way!
Here is the code to solve this issue
!pip install powerbiclient ################################################ #Using powerbiclient to get token instead of DefaultAzureCredential ###############################################
from powerbiclient.authentication import DeviceCodeLoginAuthentication auth = DeviceCodeLoginAuthentication() token = auth.get_access_token()
llm = AzureOpenAI(temperature=0, deployment_name="gpt-35-turbo", model_name="gpt-35-turbo",) toolkit = PowerBIToolkit( powerbi=PowerBIDataset( dataset_id="your_dataset_id", table_names=["HR Employees", "Sales Orders"], token= token, #<--------------Using token instead credential ), llm=llm, output_token_limit = 1024 )
agent_executor = create_pbi_agent( llm=llm, toolkit=toolkit, verbose=True )
agent_executor.run('How many rows are in HR Employees')
It works this way indeed. Thanks a lot @lewisdba !
Aqui está o código para resolver este problema
!pip instalar powerbiclient ) ) Embalhação (em, í) Usando powerbiclient para obter token em vez de DefaultAzureCredential ) ) Embalhação (em, í)
de powerbiclient.authentication import DeviceCodeLoginAutenticação auth ? DeviceCodeLoginAutentication() token ? auth.get_access_token() (em inglês)
llm ? AzureOpenAI(temperatura 0, deployment_name?"gpt-35-turbo", model_name?"gpt-35-turbo,") kit de ferramentas ? PowerBIToolkit( powerbi'PowerBIDataset (em inglês) dataset_id"your_dataset_id," (em inglês). table_names["HR Employees", "Ordens de vendas"], token, ?------------------- Uting token em vez de credencial ) - Em que o nome de porta - o que é! llm?llm, em inglês, . output_token_limit ? 1024 ) - Em que é)
agent_executor ? create_pbi_agent( llm?llm, em inglês, . toolkit?toolkit, em inglês, versão de verbose-True ) - )
agent_executor.run('Quantas linhas estão em RH')
Ok, for me it really works. But, i am coding a product for my boss. I need an automatic login.
All classes from azure.identity return the same error:
credential = UsernamePasswordCredential( username='[email protected]', password='mypass', client_id='a181f0*9f' )
PowerBIDataset.update_forward_refs() dataset = PowerBIDataset( dataset_id="26d-9a-4b-*-c132ed*8", table_names=["Sell"], credential=credential)
ERROR: name 'TokenCredential' is not defined
I tried:
credential = UsernamePasswordCredential( username='[email protected]', password='mypass', client_id='a181f0*9f' )
from azure.core.credentials import TokenCredential PowerBIDataset.update_forward_refs() dataset = PowerBIDataset( dataset_id="26d-9a-4b-*-c132ed*8", table_names=["Sell"], credential=credential)
But, it not works...
Here is the code to solve this issue !pip install powerbiclient ################################################ #Using powerbiclient to get token instead of DefaultAzureCredential ############################################### from powerbiclient.authentication import DeviceCodeLoginAuthentication auth = DeviceCodeLoginAuthentication() token = auth.get_access_token() llm = AzureOpenAI(temperature=0, deployment_name="gpt-35-turbo", model_name="gpt-35-turbo",) toolkit = PowerBIToolkit( powerbi=PowerBIDataset( dataset_id="your_dataset_id", table_names=["HR Employees", "Sales Orders"], token= token, #<--------------Using token instead credential ), llm=llm, output_token_limit = 1024 ) agent_executor = create_pbi_agent( llm=llm, toolkit=toolkit, verbose=True ) agent_executor.run('How many rows are in HR Employees')
Thanks a lot, it works this way!
This solution is really helpful :))) Thank you!