이 노트북은 Power BI Dataset과 상호작용하는 agent를 보여줍니다. agent는 데이터셋에 대한 보다 일반적인 질문에 답변하고 오류를 복구합니다. 이 agent는 현재 활발히 개발 중이므로 모든 답변이 정확하지 않을 수 있습니다. executequery endpoint에 대해 실행되며, 삭제는 허용하지 않습니다.

참고사항

  • azure.identity package를 사용한 인증에 의존하며, pip install azure-identity로 설치할 수 있습니다. 또는 credentials를 제공하지 않고 token을 문자열로 사용하여 powerbi dataset을 생성할 수 있습니다.
  • RLS가 활성화된 데이터셋과 함께 사용하기 위해 가장할 username을 제공할 수도 있습니다.
  • toolkit은 LLM을 사용하여 질문으로부터 query를 생성하고, agent는 전체 실행을 위해 LLM을 사용합니다.
  • 테스트는 주로 gpt-3.5-turbo-instruct model로 수행되었으며, codex model은 성능이 그다지 좋지 않았습니다.

Initialization

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="<dataset_id>",
        table_names=["table1", "table2"],
        credential=DefaultAzureCredential(),
    ),
    llm=smart_llm,
)

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

예제: table 설명하기

agent_executor.run("Describe table1")

예제: table에 대한 간단한 query

이 예제에서 agent는 실제로 table의 row count를 가져오기 위한 올바른 query를 파악합니다.
agent_executor.run("How many records are in table1?")

예제: query 실행하기

agent_executor.run("How many records are there by dimension1 in table2?")
agent_executor.run("What unique values are there for dimensions2 in table2")

예제: 자신만의 few-shot prompt 추가하기

# fictional example
few_shots = """
Question: How many rows are in the table revenue?
DAX: EVALUATE ROW("Number of rows", COUNTROWS(revenue_details))
----
Question: How many rows are in the table revenue where year is not empty?
DAX: EVALUATE ROW("Number of rows", COUNTROWS(FILTER(revenue_details, revenue_details[year] <> "")))
----
Question: What was the average of value in revenue in dollars?
DAX: EVALUATE ROW("Average", AVERAGE(revenue_details[dollar_value]))
----
"""
toolkit = PowerBIToolkit(
    powerbi=PowerBIDataset(
        dataset_id="<dataset_id>",
        table_names=["table1", "table2"],
        credential=DefaultAzureCredential(),
    ),
    llm=smart_llm,
    examples=few_shots,
)
agent_executor = create_pbi_agent(
    llm=fast_llm,
    toolkit=toolkit,
    verbose=True,
)
agent_executor.run("What was the maximum of value in revenue in dollars in 2022?")

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I