LoslegenKostenlos loslegen

Query NYC Taxi Dataset using SQL Agent

Databricks exposes an open source samples catalog that contains several schemas. In this exercise, we will create a LangChain Databricks SQL agent to connect to the nyctaxi schema and then ask it a question that requires SQL to answer. Creating one of these agents empowers the user to perform data analysis and ask questions on data that require SQL, with no prior knowledge of SQL.

Diese Übung ist Teil des Kurses

Databricks with the Python SDK

Kurs anzeigen

Anleitung zur Übung

  • Create LangChain SQLDatabase object from nyctaxi schema in Databricks samples catalog.
  • Create a custom LangChain LLM using the Databricks Meta Llama 3 model.
  • Create a LangChain Databricks SQL Agent using the custom LLM.
  • Query the Databricks SQL Agent.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Create LangChain SQLDatabase object from `nyctaxi` schema in Databricks `samples` catalog
db = SQLDatabase.from_databricks(
    ____="samples", 
    ____="nyctaxi",  
  	warehouse_id=warehouse_id)

# Create a custom Langchaim LLM using the Databricks Meta llama 3 model
llm = ChatDatabricks(
    ____="databricks-meta-llama-3-3-70b-instruct",
    max_tokens=100)
toolkit = SQLDatabaseToolkit(db=db, llm=meta_llm)

# Create a LangChain Databricks SQL Agent using the custom LLM created above
agent = create_sql_agent(llm=____, toolkit=toolkit, verbose=True, handle_parsing_errors=True)

# Query the Databricks SQL Agent
result = agent.____("what's the duration and distance of the longest trip?")
print(result)
Code bearbeiten und ausführen