langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
93.88k stars 15.13k forks source link

PowerBIDataSet credential not working: field "credential" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs() #27583

Open jerschi opened 3 hours ago

jerschi commented 3 hours ago

Checked other resources

Example Code

from azure.identity import DefaultAzureCredential
from langchain_community.agent_toolkits import PowerBIToolkit, create_pbi_agent
from langchain_community.utilities.powerbi import PowerBIDataset
from langchain_openai import ChatOpenAI

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)

toolkit = PowerBIToolkit(
    powerbi=PowerBIDataset(
        dataset_id="AdvWorksTest",
        table_names=["SalesLT SalesOrderHeader", "SalesLT SalesOrderDetail"],
        credential=DefaultAzureCredential(),
    ),
    llm=smart_llm,
)

agent_executor = create_pbi_agent(
    llm=fast_llm,
    toolkit=toolkit,
    verbose=True,
)

Error Message and Stack Trace (if applicable)

{
    "name": "ConfigError",
    "message": "field \"credential\" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs().",
    "stack": "---------------------------------------------------------------------------
ConfigError                               Traceback (most recent call last)
Cell In[30], line 7
      1 fast_llm = ChatOpenAI(
      2     temperature=0.5, max_tokens=1000, model_name=\"gpt-3.5-turbo\", verbose=True, api_key=OPEN_AI_API_KEY
      3 )
      4 smart_llm = ChatOpenAI(temperature=0, max_tokens=100, model_name=\"gpt-4\", verbose=True, api_key=OPEN_AI_API_KEY)
      6 toolkit = PowerBIToolkit(
----> 7     powerbi=PowerBIDataset(
      8         dataset_id=\"AdvWorksTest\",
      9         table_names=[\"SalesLT SalesOrderHeader\", \"SalesLT SalesOrderDetail\"],
     10         credential=DefaultAzureCredential(),
     11     ),
     12     llm=smart_llm,
     13 )
     15 agent_executor = create_pbi_agent(
     16     llm=fast_llm,
     17     toolkit=toolkit,
     18     verbose=True,
     19 )

File c:\\Users\\jerschi\\projects\\.conda\\Lib\\site-packages\\pydantic\\v1\\main.py:339, in BaseModel.__init__(__pydantic_self__, **data)
    333 \"\"\"
    334 Create a new model by parsing and validating input data from keyword arguments.
    335 
    336 Raises ValidationError if the input data cannot be parsed to form a valid model.
    337 \"\"\"
    338 # Uses something other than `self` the first arg to allow \"self\" as a settable attribute
--> 339 values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    340 if validation_error:
    341     raise validation_error

File c:\\Users\\jerschi\\projects\\.conda\\Lib\\site-packages\\pydantic\\v1\\main.py:1074, in validate_model(model, input_data, cls)
   1071     if check_extra:
   1072         names_used.add(field.name if using_name else field.alias)
-> 1074 v_, errors_ = field.validate(value, values, loc=field.alias, cls=cls_)
   1075 if isinstance(errors_, ErrorWrapper):
   1076     errors.append(errors_)

File c:\\Users\\jerschi\\projects\\.conda\\Lib\\site-packages\\pydantic\\v1\\fields.py:857, in ModelField.validate(self, v, values, loc, cls)
    855 if self.type_.__class__ is ForwardRef:
    856     assert cls is not None
--> 857     raise ConfigError(
    858         f'field \"{self.name}\" not yet prepared so type is still a ForwardRef, '
    859         f'you might need to call {cls.__name__}.update_forward_refs().'
    860     )
    862 errors: Optional['ErrorList']
    863 if self.pre_validators:

ConfigError: field \"credential\" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs()."
}

Description

Hello Team,

I'm trying to use the PowerBIToolkit to connect to my PowerBI report and prompt a llm. Unfortunately, I get the following error message: "ConfigError: field "credential" not yet prepared so type is still a ForwardRef, you might need to call PowerBIDataset.update_forward_refs()."

A quick google search showed me that this was an issue before (https://github.com/langchain-ai/langchain/issues/9823 and https://github.com/langchain-ai/langchain/issues/4325) that has been resolved, but somehow reverted. The other issues are closed, so I opened a new one to get some attention on this.

There is a workaround that works locally, but I need a solution that works on an application level.

From what I found, the error lies in https://github.com/hwchase17/langchain/blob/master/langchain/utilities/powerbi.py (based on some comments and this https://github.com/Azure/azure-sdk-for-python/issues/30288)

Best, jerschi

System Info

System Information

OS: Windows OS Version: 10.0.22631 Python Version: 3.11.9 | packaged by Anaconda, Inc. | (main, Apr 19 2024, 16:40:41) [MSC v.1916 64 bit (AMD64)]

Package Information

langchain_core: 0.3.12 langchain: 0.3.4 langchain_community: 0.3.3 langsmith: 0.1.137 langchain_chroma: 0.1.3 langchain_openai: 0.2.3 langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.10.5 async-timeout: Installed. No version info available. chromadb: 0.5.3 dataclasses-json: 0.6.7 fastapi: 0.112.2 httpx: 0.27.2 jsonpatch: 1.33 numpy: 1.26.4 openai: 1.52.1 orjson: 3.10.7 packaging: 24.1 pydantic: 2.8.2 pydantic-settings: 2.6.0 PyYAML: 6.0.2 requests: 2.32.3 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.32 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

zhaoJoseph commented 2 hours ago

This seems like a straightforward issue, me and a group of students from the University of Toronto are eager to help with LangChain, could my team look into this issue?