MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Databricks with the Python SDK

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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

# Create a custom LangChain LLM using the Databricks Meta Llama 3 model
meta_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)
Edit dan Jalankan Kode