langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Power BI Dataset Agent Issue

Open satishgunjal opened this issue 1 year ago • 5 comments

System Info

We are using the below Power BI Agent guide to try to connect to Power BI dashboard.

Power BI Dataset Agent

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

satishgunjal avatar May 08 '23 07:05 satishgunjal

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.

satishgunjal avatar May 08 '23 18:05 satishgunjal

Having the same issue.

Ioannis-Pikoulis avatar May 09 '23 07:05 Ioannis-Pikoulis

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

avinesh-a avatar May 09 '23 17:05 avinesh-a

Also having this issue - not sure if there is/should be a separate integ test for the powerbi tool

aditya-pethe avatar May 09 '23 19:05 aditya-pethe

@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)

aditya-pethe avatar May 11 '23 20:05 aditya-pethe

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 ?

JRlis avatar Jun 14 '23 11:06 JRlis

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

aditya-pethe avatar Jun 15 '23 20:06 aditya-pethe

Hi! We are still facing this issue. Do we have any updates/fixes/bypasses about it?

grillon6u avatar Jul 11 '23 08:07 grillon6u

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().

alaturqua avatar Aug 24 '23 19:08 alaturqua

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')

lewisdba avatar Sep 27 '23 09:09 lewisdba

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!

ghost avatar Sep 27 '23 13:09 ghost

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 !

Cozokim avatar Sep 27 '23 15:09 Cozokim

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...

BaimaCaio avatar Nov 16 '23 13:11 BaimaCaio

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!

bloopepper avatar Jan 21 '24 13:01 bloopepper