이 가이드는 Tableau 시작하기에 대한 간단한 개요를 제공합니다.

개요

Tableau의 VizQL Data Service(VDS)는 개발자에게 Tableau Published Data Sources에 대한 프로그래밍 방식의 접근을 제공하여, AI Agent를 포함한 모든 커스텀 워크로드나 애플리케이션에 대해 비즈니스 의미론을 확장할 수 있도록 합니다. simple_datasource_qa tool은 LangChain 프레임워크에 VDS를 추가합니다. 이 노트북은 엔터프라이즈 semantic model을 기반으로 분석 질문에 답변하는 agent를 구축하는 방법을 보여줍니다. 곧 출시될 더 많은 tool에 대해서는 tableau-langchain 프로젝트를 팔로우하세요!

설정

다음을 실행 중이고 접근 권한이 있는지 확인하세요:
  1. python 버전 3.12.2 이상
  2. 최소 1개 이상의 published data source가 있는 Tableau Cloud 또는 Server 환경
필요한 패키지를 설치 및/또는 import하여 시작하세요
# pip install langchain-openai
# pip install langgraph
# pip install langchain-tableau --upgrade
Requirement already satisfied: regex>=2022.1.18 in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from tiktoken<1,>=0.7->langchain-openai->langchain-tableau) (2024.11.6)
Requirement already satisfied: httpcore==1.* in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph->langchain-tableau) (1.0.7)
Requirement already satisfied: h11<0.15,>=0.13 in /Users/joe.constantino/.pyenv/versions/3.12.2/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.25.2->langgraph-sdk<0.2.0,>=0.1.42->langgraph->langchain-tableau) (0.14.0)
업데이트된 패키지를 사용하려면 커널을 재시작해야 할 수 있습니다

자격 증명

이 문서의 여러 경우에서 보여지는 것처럼 환경 변수를 명시적으로 선언할 수 있습니다. 그러나 이러한 매개변수가 제공되지 않으면 simple_datasource_qa tool은 환경 변수에서 자동으로 읽으려고 시도합니다. 쿼리하려는 Data Source에 대해 Tableau의 VizqlDataApiAccess 권한을 업데이트하여 VDS API가 REST를 통해 해당 Data Source에 접근할 수 있도록 허용했는지 확인하세요. 자세한 정보는 여기를 참조하세요.
# langchain package imports
from langchain_openai import ChatOpenAI

# langchain_tableau and langgraph imports
from langchain_tableau.tools.simple_datasource_qa import initialize_simple_datasource_qa
from langchain.agents import create_agent

인증 변수

이 쿡북의 여러 경우에서 보여지는 것처럼 환경 변수를 명시적으로 선언할 수 있습니다. 그러나 이러한 매개변수가 제공되지 않으면 simple_datasource_qa tool은 환경 변수에서 자동으로 읽으려고 시도합니다. 선택한 Data Source에 대해 Tableau의 VizqlDataApiAccess 권한을 업데이트하여 VDS API가 REST를 통해 해당 Data Source에 접근할 수 있도록 허용했는지 확인하세요. 자세한 정보는 여기를 참조하세요.
import os

from dotenv import load_dotenv

load_dotenv()

tableau_server = "https://stage-dataplane2.tableau.sfdc-shbmgi.svc.sfdcfc.net/"  # replace with your Tableau server name
tableau_site = "vizqldataservicestage02"  # replace with your Tableau site
tableau_jwt_client_id = os.getenv(
    "TABLEAU_JWT_CLIENT_ID"
)  # a JWT client ID (obtained through Tableau's admin UI)
tableau_jwt_secret_id = os.getenv(
    "TABLEAU_JWT_SECRET_ID"
)  # a JWT secret ID (obtained through Tableau's admin UI)
tableau_jwt_secret = os.getenv(
    "TABLEAU_JWT_SECRET"
)  # a JWT secret ID (obtained through Tableau's admin UI)
tableau_api_version = "3.21"  # the current Tableau REST API Version
tableau_user = "[email protected]"  # enter the username querying the target Tableau Data Source

# For this cookbook we are connecting to the Superstore dataset that comes by default with every Tableau server
datasource_luid = (
    "0965e61b-a072-43cf-994c-8c6cf526940d"  # the target data source for this Tool
)
model_provider = "openai"  # the name of the model provider you are using for your Agent
# Add variables to control LLM models for the Agent and Tools
os.environ["OPENAI_API_KEY"]  # set an your model API key as an environment variable
tooling_llm_model = "gpt-4o-mini"

인스턴스화

initialize_simple_datasource_qa는 Tableau Data Source에 대한 분석 질문과 답변에 사용할 수 있는 simple_datasource_qa라는 LangGraph tool을 초기화합니다. 이 initializer function은:
  1. JWT 기반 인증을 위한 Tableau의 connected-app 프레임워크를 사용하여 Tableau에 인증합니다. 모든 필수 변수는 런타임 또는 환경 변수로 정의되어야 합니다.
  2. datasource_luid 변수에 지정된 대상 datasource의 field metadata를 비동기적으로 쿼리합니다.
  3. 대상 datasource의 metadata를 기반으로 자연어 질문을 VDS query-datasource 요청에 필요한 json 형식의 query payload로 변환합니다.
  4. VDS에 POST 요청을 실행합니다.
  5. 결과를 구조화된 응답으로 포맷하고 반환합니다.
# Initialize simple_datasource_qa for querying Tableau Datasources through VDS
analyze_datasource = initialize_simple_datasource_qa(
    domain=tableau_server,
    site=tableau_site,
    jwt_client_id=tableau_jwt_client_id,
    jwt_secret_id=tableau_jwt_secret_id,
    jwt_secret=tableau_jwt_secret,
    tableau_api_version=tableau_api_version,
    tableau_user=tableau_user,
    datasource_luid=datasource_luid,
    tooling_llm_model=tooling_llm_model,
    model_provider=model_provider,
)

# load the List of Tools to be used by the Agent. In this case we will just load our data source Q&A tool.
tools = [analyze_datasource]

호출 - LangGraph 예제

먼저, 선택한 LLM을 초기화합니다. 그런 다음 langgraph agent constructor class를 사용하여 agent를 정의하고 대상 data source와 관련된 쿼리로 호출합니다.
from IPython.display import Markdown, display

model = ChatOpenAI(model="gpt-4o", temperature=0)

tableauAgent = create_agent(model, tools)

# Run the agent
messages = tableauAgent.invoke(
    {
        "messages": [
            (
                "human",
                "what's going on with table sales?",
            )
        ]
    }
)
messages
# display(Markdown(messages['messages'][3].content)) #display a nicely formatted answer for successful generations

체이닝

TODO.

API reference

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